blob: 2f378708de4a7f926bc2a5c4ec407c8a33d0abc1 [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;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080067import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080068import android.telephony.CallForwardingInfo;
Sooraj Sasindran4deb8872020-10-30 13:17:53 -070069import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070070import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080071import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070072import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080073import android.telephony.CellIdentityCdma;
74import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070076import android.telephony.CellInfoGsm;
77import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070078import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080079import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070080import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070081import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070082import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080083import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070084import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080085import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070086import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080087import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080088import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070089import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080090import android.telephony.RadioAccessSpecifier;
Daniel Bright59e67312020-11-13 11:49:37 -080091import android.telephony.RadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080093import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080094import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080095import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080096import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070097import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080099import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800100import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800101import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000102import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700103import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700104import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800105import android.telephony.data.ApnSetting;
106import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700107import android.telephony.gba.GbaAuthRequest;
108import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700109import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800110import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700111import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700112import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800113import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700114import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800115import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700116import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700117import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800118import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800119import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800120import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800121import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700122import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800123import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700124import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800126import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800127
Andrew Lee312e8172014-10-23 17:01:36 -0700128import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800129import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800130import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700131import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700132import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700133import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800134import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700135import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700136import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800137import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700139import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800140import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800141import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700142import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700143import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800144import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800146import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700147import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700148import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700149import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700151import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800152import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700153import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700154import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700155import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700156import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700157import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700158import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700159import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700160import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800161import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800162import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800163import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700164import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800165import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700166import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800167import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700168import com.android.internal.telephony.imsphone.ImsPhone;
169import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800170import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700171import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700172import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800173import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700174import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800175import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700176import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800177import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700178import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800179import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000180import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800181import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700182import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700183import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800184import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700185import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700186import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800187import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700188import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700189import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800190import com.android.services.telephony.TelecomAccountRegistry;
191import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800192import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800193
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700194import java.io.FileDescriptor;
195import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800197import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800198import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800199import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800200import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100201import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800202import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700203import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800204import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800205import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800206import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207
208/**
209 * Implementation of the ITelephony interface.
210 */
Santos Cordon117fee72014-05-16 17:56:12 -0700211public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700212 private static final String LOG_TAG = "PhoneInterfaceManager";
213 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
214 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800215 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216
217 // Message codes used with mMainThreadHandler
218 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700219 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
220 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700221 private static final int CMD_OPEN_CHANNEL = 9;
222 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
223 private static final int CMD_CLOSE_CHANNEL = 11;
224 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800225 private static final int CMD_NV_READ_ITEM = 13;
226 private static final int EVENT_NV_READ_ITEM_DONE = 14;
227 private static final int CMD_NV_WRITE_ITEM = 15;
228 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
229 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
230 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700231 private static final int CMD_RESET_MODEM_CONFIG = 19;
232 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800233 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
234 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
235 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
236 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800237 private static final int CMD_SEND_ENVELOPE = 25;
238 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000239 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
240 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700241 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
242 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
243 private static final int CMD_EXCHANGE_SIM_IO = 31;
244 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800245 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
246 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700247 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
248 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700249 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
250 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700251 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
252 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
253 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
254 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700255 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
256 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
257 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
258 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700259 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800260 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
261 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000262 private static final int CMD_SWITCH_SLOTS = 50;
263 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700264 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
265 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
266 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
267 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
268 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
269 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
270 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
271 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700272 private static final int CMD_GET_ALL_CELL_INFO = 60;
273 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
274 private static final int CMD_GET_CELL_LOCATION = 62;
275 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700276 private static final int CMD_MODEM_REBOOT = 64;
277 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700278 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
279 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800280 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
281 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700282 private static final int CMD_GET_MODEM_STATUS = 70;
283 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700284 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
285 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700286 private static final int CMD_ERASE_MODEM_CONFIG = 74;
287 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800288 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
289 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
290 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
291 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800292 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
293 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800294 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800295 private static final int CMD_GET_CALL_FORWARDING = 83;
296 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
297 private static final int CMD_SET_CALL_FORWARDING = 85;
298 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
299 private static final int CMD_GET_CALL_WAITING = 87;
300 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
301 private static final int CMD_SET_CALL_WAITING = 89;
302 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700303 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
304 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
305 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
306 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700307 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
308 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800309 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
310 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800311 private static final int CMD_SET_DATA_THROTTLING = 99;
312 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800313 private static final int CMD_SET_SIM_POWER = 101;
314 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800316 // Parameters of select command.
317 private static final int SELECT_COMMAND = 0xA4;
318 private static final int SELECT_P1 = 0x04;
319 private static final int SELECT_P2 = 0;
320 private static final int SELECT_P3 = 0x10;
321
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700322 /** The singleton instance. */
323 private static PhoneInterfaceManager sInstance;
324
Wink Saville3ab207e2014-11-20 13:07:20 -0800325 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800326 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800327 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700328 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800329 private AppOpsManager mAppOps;
330 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800331 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800332 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700333 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700334
Peter Wangdafb9ac2020-01-15 14:13:38 -0800335 /** User Activity */
336 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800337 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
338
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700339 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
340
Derek Tan97ebb422014-09-05 16:55:38 -0700341 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
342 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800343 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800344 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700345
Michelecea4cf22018-12-21 15:00:11 -0800346 // String to store multi SIM allowed
347 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
348
Derek Tan740e1672017-06-27 14:56:27 -0700349 // The AID of ISD-R.
350 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
351
yinxub1bed742017-04-17 11:45:04 -0700352 private NetworkScanRequestTracker mNetworkScanRequestTracker;
353
David Kelly5e06a7f2018-03-12 14:10:59 +0000354 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
355 private static final int MANUFACTURER_CODE_LENGTH = 8;
356
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800357 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
358
Derek Tan89e89d42014-07-08 17:00:10 -0700359 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700360 * Experiment flag to enable erase modem config on reset network, default value is false
361 */
362 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
363 "reset_network_erase_modem_config_enabled";
364
365 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700366 * A request object to use for transmitting data to an ICC.
367 */
368 private static final class IccAPDUArgument {
369 public int channel, cla, command, p1, p2, p3;
370 public String data;
371
372 public IccAPDUArgument(int channel, int cla, int command,
373 int p1, int p2, int p3, String data) {
374 this.channel = channel;
375 this.cla = cla;
376 this.command = command;
377 this.p1 = p1;
378 this.p2 = p2;
379 this.p3 = p3;
380 this.data = data;
381 }
382 }
383
384 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700385 * A request object to use for transmitting data to an ICC.
386 */
387 private static final class ManualNetworkSelectionArgument {
388 public OperatorInfo operatorInfo;
389 public boolean persistSelection;
390
391 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
392 this.operatorInfo = operatorInfo;
393 this.persistSelection = persistSelection;
394 }
395 }
396
397 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
399 * request after sending. The main thread will notify the request when it is complete.
400 */
401 private static final class MainThreadRequest {
402 /** The argument to use for the request */
403 public Object argument;
404 /** The result of the request that is run on the main thread */
405 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800406 // The subscriber id that this request applies to. Defaults to
407 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
408 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409
Nathan Harold92bed182018-10-12 18:16:49 -0700410 // In cases where subId is unavailable, the caller needs to specify the phone.
411 public Phone phone;
412
vagdeviaf9a5b92018-08-15 16:01:53 -0700413 public WorkSource workSource;
414
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415 public MainThreadRequest(Object argument) {
416 this.argument = argument;
417 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800418
Nathan Harold92bed182018-10-12 18:16:49 -0700419 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
420 this.argument = argument;
421 if (phone != null) {
422 this.phone = phone;
423 }
424 this.workSource = workSource;
425 }
426
vagdeviaf9a5b92018-08-15 16:01:53 -0700427 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800428 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800429 if (subId != null) {
430 this.subId = subId;
431 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700432 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800433 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434 }
435
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800436 private static final class IncomingThirdPartyCallArgs {
437 public final ComponentName component;
438 public final String callId;
439 public final String callerDisplayName;
440
441 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
442 String callerDisplayName) {
443 this.component = component;
444 this.callId = callId;
445 this.callerDisplayName = callerDisplayName;
446 }
447 }
448
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449 /**
450 * A handler that processes messages on the main thread in the phone process. Since many
451 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
452 * inbound binder threads to the main thread in the phone process. The Binder thread
453 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
454 * on, which will be notified when the operation completes and will contain the result of the
455 * request.
456 *
457 * <p>If a MainThreadRequest object is provided in the msg.obj field,
458 * note that request.result must be set to something non-null for the calling thread to
459 * unblock.
460 */
461 private final class MainThreadHandler extends Handler {
462 @Override
463 public void handleMessage(Message msg) {
464 MainThreadRequest request;
465 Message onCompleted;
466 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800467 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700468 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800469 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470
471 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700472 case CMD_HANDLE_USSD_REQUEST: {
473 request = (MainThreadRequest) msg.obj;
474 final Phone phone = getPhoneFromRequest(request);
475 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
476 String ussdRequest = ussdObject.first;
477 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700478
Pengquan Menga1bb6272018-09-06 09:59:22 -0700479 if (!isUssdApiAllowed(request.subId)) {
480 // Carrier does not support use of this API, return failure.
481 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
482 UssdResponse response = new UssdResponse(ussdRequest, null);
483 Bundle returnData = new Bundle();
484 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
485 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700486
Pengquan Menga1bb6272018-09-06 09:59:22 -0700487 request.result = true;
488 notifyRequester(request);
489 return;
490 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700491
Pengquan Menga1bb6272018-09-06 09:59:22 -0700492 try {
493 request.result = phone != null
494 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
495 } catch (CallStateException cse) {
496 request.result = false;
497 }
498 // Wake up the requesting thread
499 notifyRequester(request);
500 break;
pkanwar32d516d2016-10-14 19:37:38 -0700501 }
502
Yorke Lee716f67e2015-06-17 15:39:16 -0700503 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700504 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700505 final Phone phone = getPhoneFromRequest(request);
506 request.result = phone != null ?
507 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
508 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700510 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700511 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700512 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700513
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700514 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700515 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700516 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800517 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700518 if (uiccCard == null) {
519 loge("iccTransmitApduLogicalChannel: No UICC");
520 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700521 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700522 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
524 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700525 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 iccArgument.channel, iccArgument.cla, iccArgument.command,
527 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700528 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700529 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700530 break;
531
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700533 ar = (AsyncResult) msg.obj;
534 request = (MainThreadRequest) ar.userObj;
535 if (ar.exception == null && ar.result != null) {
536 request.result = ar.result;
537 } else {
538 request.result = new IccIoResult(0x6F, 0, (byte[])null);
539 if (ar.result == null) {
540 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800541 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700542 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800543 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700544 } else {
545 loge("iccTransmitApduLogicalChannel: Unknown exception");
546 }
547 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700548 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 break;
550
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700551 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
552 request = (MainThreadRequest) msg.obj;
553 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800554 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 if (uiccCard == null) {
556 loge("iccTransmitApduBasicChannel: No UICC");
557 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 } else {
560 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
561 request);
562 uiccCard.iccTransmitApduBasicChannel(
563 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
564 iccArgument.p3, iccArgument.data, onCompleted);
565 }
566 break;
567
568 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
569 ar = (AsyncResult) msg.obj;
570 request = (MainThreadRequest) ar.userObj;
571 if (ar.exception == null && ar.result != null) {
572 request.result = ar.result;
573 } else {
574 request.result = new IccIoResult(0x6F, 0, (byte[])null);
575 if (ar.result == null) {
576 loge("iccTransmitApduBasicChannel: Empty response");
577 } else if (ar.exception instanceof CommandException) {
578 loge("iccTransmitApduBasicChannel: CommandException: " +
579 ar.exception);
580 } else {
581 loge("iccTransmitApduBasicChannel: Unknown exception");
582 }
583 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 break;
586
587 case CMD_EXCHANGE_SIM_IO:
588 request = (MainThreadRequest) msg.obj;
589 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800590 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 if (uiccCard == null) {
592 loge("iccExchangeSimIO: No UICC");
593 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 } else {
596 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
597 request);
598 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
599 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
600 iccArgument.data, onCompleted);
601 }
602 break;
603
604 case EVENT_EXCHANGE_SIM_IO_DONE:
605 ar = (AsyncResult) msg.obj;
606 request = (MainThreadRequest) ar.userObj;
607 if (ar.exception == null && ar.result != null) {
608 request.result = ar.result;
609 } else {
610 request.result = new IccIoResult(0x6f, 0, (byte[])null);
611 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700612 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 break;
614
Derek Tan4d5e5c12014-02-04 11:54:58 -0800615 case CMD_SEND_ENVELOPE:
616 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800617 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700618 if (uiccCard == null) {
619 loge("sendEnvelopeWithStatus: No UICC");
620 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700621 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700622 } else {
623 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
624 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
625 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800626 break;
627
628 case EVENT_SEND_ENVELOPE_DONE:
629 ar = (AsyncResult) msg.obj;
630 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700631 if (ar.exception == null && ar.result != null) {
632 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800633 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700634 request.result = new IccIoResult(0x6F, 0, (byte[])null);
635 if (ar.result == null) {
636 loge("sendEnvelopeWithStatus: Empty response");
637 } else if (ar.exception instanceof CommandException) {
638 loge("sendEnvelopeWithStatus: CommandException: " +
639 ar.exception);
640 } else {
641 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
642 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800643 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700644 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800645 break;
646
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 case CMD_OPEN_CHANNEL:
648 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800649 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800650 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700651 if (uiccCard == null) {
652 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800653 request.result = new IccOpenLogicalChannelResponse(-1,
654 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700655 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700656 } else {
657 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800658 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
659 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700660 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 break;
662
663 case EVENT_OPEN_CHANNEL_DONE:
664 ar = (AsyncResult) msg.obj;
665 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700666 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 int[] result = (int[]) ar.result;
669 int channelId = result[0];
670 byte[] selectResponse = null;
671 if (result.length > 1) {
672 selectResponse = new byte[result.length - 1];
673 for (int i = 1; i < result.length; ++i) {
674 selectResponse[i - 1] = (byte) result[i];
675 }
676 }
677 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700678 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 if (ar.result == null) {
681 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 if (ar.exception != null) {
684 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
685 }
686
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700687 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700688 if (ar.exception instanceof CommandException) {
689 CommandException.Error error =
690 ((CommandException) (ar.exception)).getCommandError();
691 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700692 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700693 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700694 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700695 }
696 }
697 openChannelResp = new IccOpenLogicalChannelResponse(
698 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700699 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700700 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700701 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 break;
703
704 case CMD_CLOSE_CHANNEL:
705 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800706 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700707 if (uiccCard == null) {
708 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900709 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700710 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700711 } else {
712 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
713 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
714 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 break;
716
717 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800718 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
719 break;
720
721 case CMD_NV_READ_ITEM:
722 request = (MainThreadRequest) msg.obj;
723 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800724 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
725 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800726 break;
727
728 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700729 ar = (AsyncResult) msg.obj;
730 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800731 if (ar.exception == null && ar.result != null) {
732 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700733 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800734 request.result = "";
735 if (ar.result == null) {
736 loge("nvReadItem: Empty response");
737 } else if (ar.exception instanceof CommandException) {
738 loge("nvReadItem: CommandException: " +
739 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800741 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 }
743 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700744 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700745 break;
746
Jake Hambye994d462014-02-03 13:10:13 -0800747 case CMD_NV_WRITE_ITEM:
748 request = (MainThreadRequest) msg.obj;
749 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
750 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800751 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700752 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800753 break;
754
755 case EVENT_NV_WRITE_ITEM_DONE:
756 handleNullReturnEvent(msg, "nvWriteItem");
757 break;
758
759 case CMD_NV_WRITE_CDMA_PRL:
760 request = (MainThreadRequest) msg.obj;
761 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800762 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800763 break;
764
765 case EVENT_NV_WRITE_CDMA_PRL_DONE:
766 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
767 break;
768
chen xu6dac5ab2018-10-26 17:39:23 -0700769 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800770 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700771 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800772 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800773 break;
774
chen xu6dac5ab2018-10-26 17:39:23 -0700775 case EVENT_RESET_MODEM_CONFIG_DONE:
776 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800777 break;
778
Sooraj Sasindran37444802020-08-11 10:40:43 -0700779 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
782 request);
783 Phone phone = getPhoneFromRequest(request);
784 if (phone != null) {
785 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
786 } else {
787 loge("isNRDualConnectivityEnabled: No phone object");
788 request.result = false;
789 notifyRequester(request);
790 }
791 break;
792 }
793
794 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
795 ar = (AsyncResult) msg.obj;
796 request = (MainThreadRequest) ar.userObj;
797 if (ar.exception == null && ar.result != null) {
798 request.result = ar.result;
799 } else {
800 // request.result must be set to something non-null
801 // for the calling thread to unblock
802 if (request.result != null) {
803 request.result = ar.result;
804 } else {
805 request.result = false;
806 }
807 if (ar.result == null) {
808 loge("isNRDualConnectivityEnabled: Empty response");
809 } else if (ar.exception instanceof CommandException) {
810 loge("isNRDualConnectivityEnabled: CommandException: "
811 + ar.exception);
812 } else {
813 loge("isNRDualConnectivityEnabled: Unknown exception");
814 }
815 }
816 notifyRequester(request);
817 break;
818
819 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
820 request = (MainThreadRequest) msg.obj;
821 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
822 Phone phone = getPhoneFromRequest(request);
823 if (phone != null) {
824 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
825 request.workSource);
826 } else {
827 loge("enableNrDualConnectivity: No phone object");
828 request.result =
829 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
830 notifyRequester(request);
831 }
832 break;
833 }
834
835 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
836 ar = (AsyncResult) msg.obj;
837 request = (MainThreadRequest) ar.userObj;
838 if (ar.exception == null) {
839 request.result =
840 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
841 } else {
842 request.result =
843 TelephonyManager
844 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
845 if (ar.exception instanceof CommandException) {
846 CommandException.Error error =
847 ((CommandException) (ar.exception)).getCommandError();
848 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
849 request.result =
850 TelephonyManager
851 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
852 }
853 loge("enableNrDualConnectivity" + ": CommandException: "
854 + ar.exception);
855 } else {
856 loge("enableNrDualConnectivity" + ": Unknown exception");
857 }
858 }
859 notifyRequester(request);
860 break;
861 }
862
Jake Hamby7c27be32014-03-03 13:25:59 -0800863 case CMD_GET_PREFERRED_NETWORK_TYPE:
864 request = (MainThreadRequest) msg.obj;
865 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700866 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800867 break;
868
869 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
870 ar = (AsyncResult) msg.obj;
871 request = (MainThreadRequest) ar.userObj;
872 if (ar.exception == null && ar.result != null) {
873 request.result = ar.result; // Integer
874 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530875 // request.result must be set to something non-null
876 // for the calling thread to unblock
877 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800878 if (ar.result == null) {
879 loge("getPreferredNetworkType: Empty response");
880 } else if (ar.exception instanceof CommandException) {
881 loge("getPreferredNetworkType: CommandException: " +
882 ar.exception);
883 } else {
884 loge("getPreferredNetworkType: Unknown exception");
885 }
886 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700887 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800888 break;
889
890 case CMD_SET_PREFERRED_NETWORK_TYPE:
891 request = (MainThreadRequest) msg.obj;
892 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
893 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700894 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800895 break;
896
897 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
898 handleNullReturnEvent(msg, "setPreferredNetworkType");
899 break;
900
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000901 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
902 request = (MainThreadRequest)msg.obj;
903 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800904 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000905 break;
906
907 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
908 ar = (AsyncResult)msg.obj;
909 request = (MainThreadRequest)ar.userObj;
910 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700911 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000912 break;
913
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800914 case CMD_SET_VOICEMAIL_NUMBER:
915 request = (MainThreadRequest) msg.obj;
916 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
917 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800918 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
919 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800920 break;
921
922 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
923 handleNullReturnEvent(msg, "setVoicemailNumber");
924 break;
925
Stuart Scott54788802015-03-30 13:18:01 -0700926 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
927 request = (MainThreadRequest) msg.obj;
928 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
929 request);
930 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
931 break;
932
933 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
934 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
935 break;
936
Shishir Agrawal302c8692015-06-19 13:49:39 -0700937 case CMD_PERFORM_NETWORK_SCAN:
938 request = (MainThreadRequest) msg.obj;
939 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
940 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
941 break;
942
Hall Liu27d24262020-09-18 19:04:59 -0700943 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800944 request = (MainThreadRequest) msg.obj;
945 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700946 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
947 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
948 request.argument;
949 int callForwardingReason = args.first;
950 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800951 break;
Hall Liu27d24262020-09-18 19:04:59 -0700952 }
953 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800954 ar = (AsyncResult) msg.obj;
955 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700956 TelephonyManager.CallForwardingInfoCallback callback =
957 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
958 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800959 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700960 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800961 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
962 for (CallForwardInfo callForwardInfo : callForwardInfos) {
963 // Service Class is a bit mask per 3gpp 27.007. Search for
964 // any service for voice call.
965 if ((callForwardInfo.serviceClass
966 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700967 callForwardingInfo = new CallForwardingInfo(true,
968 callForwardInfo.reason,
969 callForwardInfo.number,
970 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800971 break;
972 }
973 }
974 // Didn't find a call forward info for voice call.
975 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700976 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
977 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -0800978 }
Hall Liu27d24262020-09-18 19:04:59 -0700979 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -0800980 } else {
981 if (ar.result == null) {
982 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
983 }
984 if (ar.exception != null) {
985 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
986 }
Hall Liu940c4ca2020-09-29 17:10:18 -0700987 int errorCode = TelephonyManager
988 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -0800989 if (ar.exception instanceof CommandException) {
990 CommandException.Error error =
991 ((CommandException) (ar.exception)).getCommandError();
992 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700993 errorCode = TelephonyManager
994 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -0800995 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700996 errorCode = TelephonyManager
997 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -0800998 }
999 }
Hall Liu27d24262020-09-18 19:04:59 -07001000 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001001 }
Shuo Qian4a594052020-01-23 11:59:30 -08001002 break;
Hall Liu27d24262020-09-18 19:04:59 -07001003 }
Shuo Qian4a594052020-01-23 11:59:30 -08001004
Hall Liu27d24262020-09-18 19:04:59 -07001005 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001006 request = (MainThreadRequest) msg.obj;
1007 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001008 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001009 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001010 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1011 request.argument).first;
1012 request.phone.setCallForwardingOption(
1013 callForwardingInfoToSet.isEnabled()
1014 ? CommandsInterface.CF_ACTION_ENABLE
1015 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001016 callForwardingInfoToSet.getReason(),
1017 callForwardingInfoToSet.getNumber(),
1018 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1019 break;
Hall Liu27d24262020-09-18 19:04:59 -07001020 }
Shuo Qian4a594052020-01-23 11:59:30 -08001021
Hall Liu27d24262020-09-18 19:04:59 -07001022 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001023 ar = (AsyncResult) msg.obj;
1024 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001025 Consumer<Integer> callback =
1026 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1027 request.argument).second;
1028 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001029 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001030 int errorCode = TelephonyManager.CallForwardingInfoCallback
1031 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001032 if (ar.exception instanceof CommandException) {
1033 CommandException.Error error =
1034 ((CommandException) (ar.exception)).getCommandError();
1035 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001036 errorCode = TelephonyManager.CallForwardingInfoCallback
1037 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001038 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001039 errorCode = TelephonyManager.CallForwardingInfoCallback
1040 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001041 }
1042 }
1043 callback.accept(errorCode);
1044 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001045 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001046 }
Shuo Qian4a594052020-01-23 11:59:30 -08001047 break;
Hall Liu27d24262020-09-18 19:04:59 -07001048 }
Shuo Qian4a594052020-01-23 11:59:30 -08001049
Hall Liu27d24262020-09-18 19:04:59 -07001050 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001051 request = (MainThreadRequest) msg.obj;
1052 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1053 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1054 break;
Hall Liu27d24262020-09-18 19:04:59 -07001055 }
Shuo Qian4a594052020-01-23 11:59:30 -08001056
Hall Liu27d24262020-09-18 19:04:59 -07001057 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001058 ar = (AsyncResult) msg.obj;
1059 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001060 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001061 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1062 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001063 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001064 // Service Class is a bit mask per 3gpp 27.007.
1065 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001066 if (callForwardResults.length > 1
1067 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001068 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001069 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001070 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1071 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001072 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001073 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001074 }
1075 } else {
1076 if (ar.result == null) {
1077 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1078 }
1079 if (ar.exception != null) {
1080 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1081 }
1082 if (ar.exception instanceof CommandException) {
1083 CommandException.Error error =
1084 ((CommandException) (ar.exception)).getCommandError();
1085 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1086 callForwardingStatus =
1087 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1088 }
1089 }
1090 }
Hall Liu27d24262020-09-18 19:04:59 -07001091 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001092 break;
Hall Liu27d24262020-09-18 19:04:59 -07001093 }
Shuo Qian4a594052020-01-23 11:59:30 -08001094
Hall Liu27d24262020-09-18 19:04:59 -07001095 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001096 request = (MainThreadRequest) msg.obj;
1097 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001098 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1099 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001100 break;
Hall Liu27d24262020-09-18 19:04:59 -07001101 }
Shuo Qian4a594052020-01-23 11:59:30 -08001102
Hall Liu27d24262020-09-18 19:04:59 -07001103 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001104 ar = (AsyncResult) msg.obj;
1105 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001106 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1107 Consumer<Integer> callback =
1108 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1109 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001110 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001111 if (ar.exception instanceof CommandException) {
1112 CommandException.Error error =
1113 ((CommandException) (ar.exception)).getCommandError();
1114 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1115 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1116 } else {
1117 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1118 }
1119 } else {
1120 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1121 }
1122 } else {
1123 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1124 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001125 }
Shuo Qian4a594052020-01-23 11:59:30 -08001126 break;
Hall Liu27d24262020-09-18 19:04:59 -07001127 }
Shuo Qian4a594052020-01-23 11:59:30 -08001128
Shishir Agrawal302c8692015-06-19 13:49:39 -07001129 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1130 ar = (AsyncResult) msg.obj;
1131 request = (MainThreadRequest) ar.userObj;
1132 CellNetworkScanResult cellScanResult;
1133 if (ar.exception == null && ar.result != null) {
1134 cellScanResult = new CellNetworkScanResult(
1135 CellNetworkScanResult.STATUS_SUCCESS,
1136 (List<OperatorInfo>) ar.result);
1137 } else {
1138 if (ar.result == null) {
1139 loge("getCellNetworkScanResults: Empty response");
1140 }
1141 if (ar.exception != null) {
1142 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1143 }
1144 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1145 if (ar.exception instanceof CommandException) {
1146 CommandException.Error error =
1147 ((CommandException) (ar.exception)).getCommandError();
1148 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1149 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1150 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1151 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1152 }
1153 }
1154 cellScanResult = new CellNetworkScanResult(errorCode, null);
1155 }
1156 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001157 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001158 break;
1159
1160 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1161 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001162 ManualNetworkSelectionArgument selArg =
1163 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001164 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1165 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001166 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1167 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001168 break;
1169
1170 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001171 ar = (AsyncResult) msg.obj;
1172 request = (MainThreadRequest) ar.userObj;
1173 if (ar.exception == null) {
1174 request.result = true;
1175 } else {
1176 request.result = false;
1177 loge("setNetworkSelectionModeManual " + ar.exception);
1178 }
1179 notifyRequester(request);
1180 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001181 break;
1182
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001183 case CMD_GET_MODEM_ACTIVITY_INFO:
1184 request = (MainThreadRequest) msg.obj;
1185 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001186 if (defaultPhone != null) {
1187 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001188 } else {
1189 ResultReceiver result = (ResultReceiver) request.argument;
1190 Bundle bundle = new Bundle();
1191 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001192 new ModemActivityInfo(0, 0, 0,
1193 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001194 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001195 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001196 break;
1197
Hall Liud0f208c2020-10-14 16:54:44 -07001198 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001199 ar = (AsyncResult) msg.obj;
1200 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001201 ResultReceiver result = (ResultReceiver) request.argument;
1202
Hall Liud0f208c2020-10-14 16:54:44 -07001203 ModemActivityInfo ret = null;
1204 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001205 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001206 // Update the last modem activity info and the result of the request.
1207 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1208 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001209 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001210 int[] txTimeMs = info.getTransmitTimeMillis();
1211 int[] lastModemTxTimeMs = mLastModemActivityInfo
1212 .getTransmitTimeMillis();
1213 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1214 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1215 }
Hall Liu49656c02020-10-09 19:00:11 -07001216 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001217 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1218 + mLastModemActivityInfo.getSleepTimeMillis());
1219 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1220 + mLastModemActivityInfo.getIdleTimeMillis());
1221 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1222 mLastModemActivityInfo.setReceiveTimeMillis(
1223 info.getReceiveTimeMillis()
1224 + mLastModemActivityInfo.getReceiveTimeMillis());
1225 }
Hall Liu49656c02020-10-09 19:00:11 -07001226 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001227 mLastModemActivityInfo.getSleepTimeMillis(),
1228 mLastModemActivityInfo.getIdleTimeMillis(),
1229 mLastModemActivityInfo.getTransmitTimeMillis(),
1230 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001231 } else {
1232 if (ar.result == null) {
1233 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001234 error = TelephonyManager.ModemActivityInfoException
1235 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001236 } else if (ar.exception instanceof CommandException) {
1237 loge("queryModemActivityInfo: CommandException: " +
1238 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001239 error = TelephonyManager.ModemActivityInfoException
1240 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001241 } else {
1242 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001243 error = TelephonyManager.ModemActivityInfoException
1244 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001245 }
1246 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001247 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001248 if (ret != null) {
1249 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1250 } else {
1251 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1252 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001253 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001254 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001255 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001256 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001257
Meng Wang1a7c35a2016-05-05 20:56:15 -07001258 case CMD_SET_ALLOWED_CARRIERS:
1259 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001260 CarrierRestrictionRules argument =
1261 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001262 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001263 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001264 break;
1265
1266 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1267 ar = (AsyncResult) msg.obj;
1268 request = (MainThreadRequest) ar.userObj;
1269 if (ar.exception == null && ar.result != null) {
1270 request.result = ar.result;
1271 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001272 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1273 if (ar.exception instanceof CommandException) {
1274 loge("setAllowedCarriers: CommandException: " + ar.exception);
1275 CommandException.Error error =
1276 ((CommandException) (ar.exception)).getCommandError();
1277 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1278 request.result =
1279 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1280 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001281 } else {
1282 loge("setAllowedCarriers: Unknown exception");
1283 }
1284 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001285 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001286 break;
1287
1288 case CMD_GET_ALLOWED_CARRIERS:
1289 request = (MainThreadRequest) msg.obj;
1290 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001291 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001292 break;
1293
1294 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1295 ar = (AsyncResult) msg.obj;
1296 request = (MainThreadRequest) ar.userObj;
1297 if (ar.exception == null && ar.result != null) {
1298 request.result = ar.result;
1299 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001300 request.result = new IllegalStateException(
1301 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001302 if (ar.result == null) {
1303 loge("getAllowedCarriers: Empty response");
1304 } else if (ar.exception instanceof CommandException) {
1305 loge("getAllowedCarriers: CommandException: " +
1306 ar.exception);
1307 } else {
1308 loge("getAllowedCarriers: Unknown exception");
1309 }
1310 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001311 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001312 break;
1313
Nathan Haroldb3014052017-01-25 15:57:32 -08001314 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1315 ar = (AsyncResult) msg.obj;
1316 request = (MainThreadRequest) ar.userObj;
1317 if (ar.exception == null && ar.result != null) {
1318 request.result = ar.result;
1319 } else {
1320 request.result = new IllegalArgumentException(
1321 "Failed to retrieve Forbidden Plmns");
1322 if (ar.result == null) {
1323 loge("getForbiddenPlmns: Empty response");
1324 } else {
1325 loge("getForbiddenPlmns: Unknown exception");
1326 }
1327 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001328 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001329 break;
1330
1331 case CMD_GET_FORBIDDEN_PLMNS:
1332 request = (MainThreadRequest) msg.obj;
1333 uiccCard = getUiccCardFromRequest(request);
1334 if (uiccCard == null) {
1335 loge("getForbiddenPlmns() UiccCard is null");
1336 request.result = new IllegalArgumentException(
1337 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001338 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001339 break;
1340 }
1341 Integer appType = (Integer) request.argument;
1342 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1343 if (uiccApp == null) {
1344 loge("getForbiddenPlmns() no app with specified type -- "
1345 + appType);
1346 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001347 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001348 break;
1349 } else {
1350 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1351 + " specified type -- " + appType);
1352 }
1353 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1354 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1355 onCompleted);
1356 break;
1357
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001358 case CMD_SWITCH_SLOTS:
1359 request = (MainThreadRequest) msg.obj;
1360 int[] physicalSlots = (int[]) request.argument;
1361 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1362 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1363 break;
1364
1365 case EVENT_SWITCH_SLOTS_DONE:
1366 ar = (AsyncResult) msg.obj;
1367 request = (MainThreadRequest) ar.userObj;
1368 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001369 notifyRequester(request);
1370 break;
1371 case CMD_GET_NETWORK_SELECTION_MODE:
1372 request = (MainThreadRequest) msg.obj;
1373 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1374 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1375 break;
1376
1377 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1378 ar = (AsyncResult) msg.obj;
1379 request = (MainThreadRequest) ar.userObj;
1380 if (ar.exception != null) {
1381 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1382 } else {
1383 int mode = ((int[]) ar.result)[0];
1384 if (mode == 0) {
1385 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1386 } else {
1387 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1388 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001389 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001390 notifyRequester(request);
1391 break;
1392 case CMD_GET_CDMA_ROAMING_MODE:
1393 request = (MainThreadRequest) msg.obj;
1394 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1395 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1396 break;
1397 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1398 ar = (AsyncResult) msg.obj;
1399 request = (MainThreadRequest) ar.userObj;
1400 if (ar.exception != null) {
1401 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1402 } else {
1403 request.result = ((int[]) ar.result)[0];
1404 }
1405 notifyRequester(request);
1406 break;
1407 case CMD_SET_CDMA_ROAMING_MODE:
1408 request = (MainThreadRequest) msg.obj;
1409 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1410 int mode = (int) request.argument;
1411 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1412 break;
1413 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1414 ar = (AsyncResult) msg.obj;
1415 request = (MainThreadRequest) ar.userObj;
1416 request.result = ar.exception == null;
1417 notifyRequester(request);
1418 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001419 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1420 request = (MainThreadRequest) msg.obj;
1421 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1422 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1423 break;
1424 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1425 ar = (AsyncResult) msg.obj;
1426 request = (MainThreadRequest) ar.userObj;
1427 if (ar.exception != null) {
1428 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1429 } else {
1430 request.result = ((int[]) ar.result)[0];
1431 }
1432 notifyRequester(request);
1433 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001434 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1435 request = (MainThreadRequest) msg.obj;
1436 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1437 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001438 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1439 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001440 break;
1441 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1442 ar = (AsyncResult) msg.obj;
1443 request = (MainThreadRequest) ar.userObj;
1444 request.result = ar.exception == null;
1445 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001446 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001447 case CMD_GET_ALL_CELL_INFO:
1448 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001449 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001450 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001451 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001452 case EVENT_GET_ALL_CELL_INFO_DONE:
1453 ar = (AsyncResult) msg.obj;
1454 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001455 // If a timeout occurs, the response will be null
1456 request.result = (ar.exception == null && ar.result != null)
1457 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001458 synchronized (request) {
1459 request.notifyAll();
1460 }
1461 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001462 case CMD_REQUEST_CELL_INFO_UPDATE:
1463 request = (MainThreadRequest) msg.obj;
1464 request.phone.requestCellInfoUpdate(request.workSource,
1465 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1466 break;
1467 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1468 ar = (AsyncResult) msg.obj;
1469 request = (MainThreadRequest) ar.userObj;
1470 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1471 try {
1472 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001473 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001474 cb.onError(
1475 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1476 ar.exception.getClass().getName(),
1477 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001478 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001479 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001480 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001481 } else {
1482 // use the result as returned
1483 cb.onCellInfo((List<CellInfo>) ar.result);
1484 }
1485 } catch (RemoteException re) {
1486 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1487 }
1488 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001489 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001490 request = (MainThreadRequest) msg.obj;
1491 WorkSource ws = (WorkSource) request.argument;
1492 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001493 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001494 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001495 }
1496 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001497 ar = (AsyncResult) msg.obj;
1498 request = (MainThreadRequest) ar.userObj;
1499 if (ar.exception == null) {
1500 request.result = ar.result;
1501 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001502 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001503 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001504 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001505 }
1506
1507 synchronized (request) {
1508 request.notifyAll();
1509 }
1510 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001511 }
chen xu6dac5ab2018-10-26 17:39:23 -07001512 case CMD_MODEM_REBOOT:
1513 request = (MainThreadRequest) msg.obj;
1514 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001515 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001516 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001517 case EVENT_CMD_MODEM_REBOOT_DONE:
1518 handleNullReturnEvent(msg, "rebootModem");
1519 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001520 case CMD_REQUEST_ENABLE_MODEM:
1521 request = (MainThreadRequest) msg.obj;
1522 boolean enable = (boolean) request.argument;
1523 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001524 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001525 PhoneConfigurationManager.getInstance()
1526 .enablePhone(request.phone, enable, onCompleted);
1527 break;
1528 case EVENT_ENABLE_MODEM_DONE:
1529 ar = (AsyncResult) msg.obj;
1530 request = (MainThreadRequest) ar.userObj;
1531 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001532 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001533 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001534 if ((boolean) request.result) {
1535 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1536 updateModemStateMetrics();
1537 } else {
1538 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1539 + ar.exception);
1540 }
1541 notifyRequester(request);
1542 break;
1543 case CMD_GET_MODEM_STATUS:
1544 request = (MainThreadRequest) msg.obj;
1545 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1546 PhoneConfigurationManager.getInstance()
1547 .getPhoneStatusFromModem(request.phone, onCompleted);
1548 break;
1549 case EVENT_GET_MODEM_STATUS_DONE:
1550 ar = (AsyncResult) msg.obj;
1551 request = (MainThreadRequest) ar.userObj;
1552 int id = request.phone.getPhoneId();
1553 if (ar.exception == null && ar.result != null) {
1554 request.result = ar.result;
1555 //update the cache as modem status has changed
1556 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1557 (boolean) request.result);
1558 } else {
1559 // Return true if modem status cannot be retrieved. For most cases,
1560 // modem status is on. And for older version modems, GET_MODEM_STATUS
1561 // and disable modem are not supported. Modem is always on.
1562 // TODO: this should be fixed in R to support a third
1563 // status UNKNOWN b/131631629
1564 request.result = true;
1565 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1566 + ar.exception);
1567 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001568 notifyRequester(request);
1569 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001570 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1571 request = (MainThreadRequest) msg.obj;
1572 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1573 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1574 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1575 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1576 break;
1577 }
1578 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1579 ar = (AsyncResult) msg.obj;
1580 request = (MainThreadRequest) ar.userObj;
1581 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1582 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1583 args.second.accept(ar.exception == null);
1584 notifyRequester(request);
1585 break;
1586 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001587 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1588 request = (MainThreadRequest) msg.obj;
1589 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1590 Phone phone = getPhoneFromRequest(request);
1591 if (phone != null) {
1592 phone.getSystemSelectionChannels(onCompleted);
1593 } else {
1594 loge("getSystemSelectionChannels: No phone object");
1595 request.result = new ArrayList<RadioAccessSpecifier>();
1596 notifyRequester(request);
1597 }
1598 break;
1599 }
1600 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1601 ar = (AsyncResult) msg.obj;
1602 request = (MainThreadRequest) ar.userObj;
1603 if (ar.exception == null && ar.result != null) {
1604 request.result = ar.result;
1605 } else {
1606 request.result = new IllegalArgumentException(
1607 "Failed to retrieve system selection channels");
1608 if (ar.result == null) {
1609 loge("getSystemSelectionChannels: Empty response");
1610 } else {
1611 loge("getSystemSelectionChannels: Unknown exception");
1612 }
1613 }
1614 notifyRequester(request);
1615 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001616 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1617 ar = (AsyncResult) msg.obj;
1618 request = (MainThreadRequest) ar.userObj;
1619 if (ar.exception == null && ar.result != null) {
1620 request.result = ar.result;
1621 } else {
1622 request.result = -1;
1623 loge("Failed to set Forbidden Plmns");
1624 if (ar.result == null) {
1625 loge("setForbidenPlmns: Empty response");
1626 } else if (ar.exception != null) {
1627 loge("setForbiddenPlmns: Exception: " + ar.exception);
1628 request.result = -1;
1629 } else {
1630 loge("setForbiddenPlmns: Unknown exception");
1631 }
1632 }
1633 notifyRequester(request);
1634 break;
1635 case CMD_SET_FORBIDDEN_PLMNS:
1636 request = (MainThreadRequest) msg.obj;
1637 uiccCard = getUiccCardFromRequest(request);
1638 if (uiccCard == null) {
1639 loge("setForbiddenPlmns: UiccCard is null");
1640 request.result = -1;
1641 notifyRequester(request);
1642 break;
1643 }
1644 Pair<Integer, List<String>> setFplmnsArgs =
1645 (Pair<Integer, List<String>>) request.argument;
1646 appType = setFplmnsArgs.first;
1647 List<String> fplmns = setFplmnsArgs.second;
1648 uiccApp = uiccCard.getApplicationByType(appType);
1649 if (uiccApp == null) {
1650 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1651 request.result = -1;
1652 loge("Failed to get UICC App");
1653 notifyRequester(request);
1654 } else {
1655 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1656 ((SIMRecords) uiccApp.getIccRecords())
1657 .setForbiddenPlmns(onCompleted, fplmns);
1658 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001659 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001660 case CMD_ERASE_MODEM_CONFIG:
1661 request = (MainThreadRequest) msg.obj;
1662 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1663 defaultPhone.eraseModemConfig(onCompleted);
1664 break;
1665 case EVENT_ERASE_MODEM_CONFIG_DONE:
1666 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001667 break;
zoey chene02881a2019-12-30 16:11:23 +08001668
1669 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1670 request = (MainThreadRequest) msg.obj;
1671 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1672 Pair<String, String> changed = (Pair<String, String>) request.argument;
1673 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1674 changed.first, changed.second, onCompleted);
1675 break;
1676 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1677 ar = (AsyncResult) msg.obj;
1678 request = (MainThreadRequest) ar.userObj;
1679 if (ar.exception == null) {
1680 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1681 } else {
1682 request.result = msg.arg1;
1683 }
1684 notifyRequester(request);
1685 break;
1686
1687 case CMD_SET_ICC_LOCK_ENABLED:
1688 request = (MainThreadRequest) msg.obj;
1689 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1690 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1691 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1692 enabled.first, enabled.second, onCompleted);
1693 break;
1694 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1695 ar = (AsyncResult) msg.obj;
1696 request = (MainThreadRequest) ar.userObj;
1697 if (ar.exception == null) {
1698 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1699 } else {
1700 request.result = msg.arg1;
1701 }
1702 notifyRequester(request);
1703 break;
1704
Peter Wangdafb9ac2020-01-15 14:13:38 -08001705 case MSG_NOTIFY_USER_ACTIVITY:
1706 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001707 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001708 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1709 getDefaultPhone().getContext().sendBroadcastAsUser(
1710 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1711 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001712
1713 case CMD_SET_DATA_THROTTLING: {
1714 request = (MainThreadRequest) msg.obj;
1715 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1716 DataThrottlingRequest dataThrottlingRequest =
1717 (DataThrottlingRequest) request.argument;
1718 Phone phone = getPhoneFromRequest(request);
1719 if (phone != null) {
1720 phone.setDataThrottling(onCompleted,
1721 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1722 dataThrottlingRequest.getCompletionDurationMillis());
1723 } else {
1724 loge("setDataThrottling: No phone object");
1725 request.result =
1726 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1727 notifyRequester(request);
1728 }
1729
1730 break;
1731 }
1732 case EVENT_SET_DATA_THROTTLING_DONE:
1733 ar = (AsyncResult) msg.obj;
1734 request = (MainThreadRequest) ar.userObj;
1735
1736 if (ar.exception == null) {
1737 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1738 } else if (ar.exception instanceof CommandException) {
1739 loge("setDataThrottling: CommandException: " + ar.exception);
1740 CommandException.Error error =
1741 ((CommandException) (ar.exception)).getCommandError();
1742
1743 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1744 request.result = TelephonyManager
1745 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1746 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1747 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1748 } else {
1749 request.result =
1750 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1751 }
1752 } else {
1753 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1754 }
1755 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1756 notifyRequester(request);
1757 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001758
1759 case CMD_SET_SIM_POWER: {
1760 request = (MainThreadRequest) msg.obj;
1761 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1762 request = (MainThreadRequest) msg.obj;
1763 int stateToSet =
1764 ((Pair<Integer, IIntegerConsumer>)
1765 request.argument).first;
1766 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1767 break;
1768 }
1769 case EVENT_SET_SIM_POWER_DONE: {
1770 ar = (AsyncResult) msg.obj;
1771 request = (MainThreadRequest) ar.userObj;
1772 IIntegerConsumer callback =
1773 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1774 if (ar.exception != null) {
1775 loge("setSimPower exception: " + ar.exception);
1776 int errorCode = TelephonyManager.CallForwardingInfoCallback
1777 .RESULT_ERROR_UNKNOWN;
1778 if (ar.exception instanceof CommandException) {
1779 CommandException.Error error =
1780 ((CommandException) (ar.exception)).getCommandError();
1781 if (error == CommandException.Error.SIM_ERR) {
1782 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1783 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1784 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1785 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1786 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1787 } else {
1788 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1789 }
1790 }
1791 try {
1792 callback.accept(errorCode);
1793 } catch (RemoteException e) {
1794 // Ignore if the remote process is no longer available to call back.
1795 Log.w(LOG_TAG, "setSimPower: callback not available.");
1796 }
1797 } else {
1798 try {
1799 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1800 } catch (RemoteException e) {
1801 // Ignore if the remote process is no longer available to call back.
1802 Log.w(LOG_TAG, "setSimPower: callback not available.");
1803 }
1804 }
1805 break;
1806 }
1807
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 default:
1809 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1810 break;
1811 }
1812 }
Jake Hambye994d462014-02-03 13:10:13 -08001813
Pengquan Menga1bb6272018-09-06 09:59:22 -07001814 private void notifyRequester(MainThreadRequest request) {
1815 synchronized (request) {
1816 request.notifyAll();
1817 }
1818 }
1819
Jake Hambye994d462014-02-03 13:10:13 -08001820 private void handleNullReturnEvent(Message msg, String command) {
1821 AsyncResult ar = (AsyncResult) msg.obj;
1822 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1823 if (ar.exception == null) {
1824 request.result = true;
1825 } else {
1826 request.result = false;
1827 if (ar.exception instanceof CommandException) {
1828 loge(command + ": CommandException: " + ar.exception);
1829 } else {
1830 loge(command + ": Unknown exception");
1831 }
1832 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001833 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001834 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001835 }
1836
1837 /**
1838 * Posts the specified command to be executed on the main thread,
1839 * waits for the request to complete, and returns the result.
1840 * @see #sendRequestAsync
1841 */
1842 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001843 return sendRequest(
1844 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001845 }
1846
1847 /**
1848 * Posts the specified command to be executed on the main thread,
1849 * waits for the request to complete, and returns the result.
1850 * @see #sendRequestAsync
1851 */
1852 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1853 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001854 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001855 }
1856
1857 /**
1858 * Posts the specified command to be executed on the main thread,
1859 * waits for the request to complete, and returns the result.
1860 * @see #sendRequestAsync
1861 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001862 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001863 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001864 }
1865
1866 /**
1867 * Posts the specified command to be executed on the main thread,
1868 * waits for the request to complete, and returns the result.
1869 * @see #sendRequestAsync
1870 */
Nathan Harold92bed182018-10-12 18:16:49 -07001871 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1872 return sendRequest(command, argument, subId, null, workSource);
1873 }
1874
1875 /**
1876 * Posts the specified command to be executed on the main thread,
1877 * waits for the request to complete, and returns the result.
1878 * @see #sendRequestAsync
1879 */
1880 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1881 return sendRequest(
1882 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1883 }
1884
1885 /**
1886 * Posts the specified command to be executed on the main thread,
1887 * waits for the request to complete, and returns the result.
1888 * @see #sendRequestAsync
1889 */
1890 private Object sendRequest(
1891 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1893 throw new RuntimeException("This method will deadlock if called from the main thread.");
1894 }
1895
Nathan Harold92bed182018-10-12 18:16:49 -07001896 MainThreadRequest request = null;
1897 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1898 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1899 } else if (phone != null) {
1900 request = new MainThreadRequest(argument, phone, workSource);
1901 } else {
1902 request = new MainThreadRequest(argument, subId, workSource);
1903 }
1904
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 Message msg = mMainThreadHandler.obtainMessage(command, request);
1906 msg.sendToTarget();
1907
1908 // Wait for the request to complete
1909 synchronized (request) {
1910 while (request.result == null) {
1911 try {
1912 request.wait();
1913 } catch (InterruptedException e) {
1914 // Do nothing, go back and wait until the request is complete
1915 }
1916 }
1917 }
1918 return request.result;
1919 }
1920
1921 /**
1922 * Asynchronous ("fire and forget") version of sendRequest():
1923 * Posts the specified command to be executed on the main thread, and
1924 * returns immediately.
1925 * @see #sendRequest
1926 */
1927 private void sendRequestAsync(int command) {
1928 mMainThreadHandler.sendEmptyMessage(command);
1929 }
1930
1931 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001932 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001933 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001934 */
1935 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001936 sendRequestAsync(command, argument, null, null);
1937 }
1938
1939 /**
1940 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1941 * @see {@link #sendRequest(int,Object)}
1942 */
1943 private void sendRequestAsync(
1944 int command, Object argument, Phone phone, WorkSource workSource) {
1945 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001946 Message msg = mMainThreadHandler.obtainMessage(command, request);
1947 msg.sendToTarget();
1948 }
1949
1950 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001951 * Initialize the singleton PhoneInterfaceManager instance.
1952 * This is only done once, at startup, from PhoneApp.onCreate().
1953 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001954 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 synchronized (PhoneInterfaceManager.class) {
1956 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001957 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001958 } else {
1959 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1960 }
1961 return sInstance;
1962 }
1963 }
1964
1965 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001966 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001967 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001969 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001970 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001971 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1972 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001973 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001974 mTelephonySharedPreferences =
1975 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001976 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001977 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001978 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001979
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001980 publish();
1981 }
1982
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001983 private Phone getDefaultPhone() {
1984 Phone thePhone = getPhone(getDefaultSubscription());
1985 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1986 }
1987
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001988 private void publish() {
1989 if (DBG) log("publish: " + this);
1990
Peter Wangc035ce42020-01-08 21:00:22 -08001991 TelephonyFrameworkInitializer
1992 .getTelephonyServiceManager()
1993 .getTelephonyServiceRegisterer()
1994 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995 }
1996
Stuart Scott584921c2015-01-15 17:10:34 -08001997 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001998 if (request.phone != null) {
1999 return request.phone;
2000 } else {
2001 return getPhoneFromSubId(request.subId);
2002 }
2003 }
2004
2005 private Phone getPhoneFromSubId(int subId) {
2006 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2007 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002008 }
2009
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002010 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2011 Phone phone = getPhoneFromRequest(request);
2012 return phone == null ? null :
2013 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2014 }
2015
Wink Saville36469e72014-06-11 15:17:00 -07002016 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002017 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002018 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002019 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002020
Naina Nallurid63128d2019-09-17 14:10:30 -07002021 private void sendEraseModemConfig(Phone phone) {
2022 if (phone != null) {
2023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2024 mApp, phone.getSubId(), "eraseModemConfig");
2025 final long identity = Binder.clearCallingIdentity();
2026 try {
2027 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2028 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2029 } finally {
2030 Binder.restoreCallingIdentity(identity);
2031 }
2032 }
2033 }
2034
Peter Wang44b186e2020-01-13 23:33:09 -08002035 private boolean isImsAvailableOnDevice() {
2036 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2037 if (pm == null) {
2038 // For some reason package manger is not available.. This will fail internally anyway,
2039 // so do not throw error and allow.
2040 return true;
2041 }
2042 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2043 }
2044
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002046 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002047 }
2048
Wink Savilleb564aae2014-10-23 10:18:09 -07002049 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002050 if (DBG) log("dial: " + number);
2051 // No permission check needed here: This is just a wrapper around the
2052 // ACTION_DIAL intent, which is available to any app since it puts up
2053 // the UI before it does anything.
2054
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002055 final long identity = Binder.clearCallingIdentity();
2056 try {
2057 String url = createTelUrl(number);
2058 if (url == null) {
2059 return;
2060 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002061
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002062 // PENDING: should we just silently fail if phone is offhook or ringing?
2063 PhoneConstants.State state = mCM.getState(subId);
2064 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2065 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2066 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2067 mApp.startActivity(intent);
2068 }
2069 } finally {
2070 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002071 }
2072 }
2073
2074 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002075 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002076 }
2077
Wink Savilleb564aae2014-10-23 10:18:09 -07002078 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 if (DBG) log("call: " + number);
2080
2081 // This is just a wrapper around the ACTION_CALL intent, but we still
2082 // need to do a permission check since we're calling startActivity()
2083 // from the context of the phone app.
2084 enforceCallPermission();
2085
Jordan Liu1617b712019-07-10 15:06:26 -07002086 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 != AppOpsManager.MODE_ALLOWED) {
2088 return;
2089 }
2090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002091 final long identity = Binder.clearCallingIdentity();
2092 try {
2093 String url = createTelUrl(number);
2094 if (url == null) {
2095 return;
2096 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002098 boolean isValid = false;
2099 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2100 if (slist != null) {
2101 for (SubscriptionInfo subInfoRecord : slist) {
2102 if (subInfoRecord.getSubscriptionId() == subId) {
2103 isValid = true;
2104 break;
2105 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002106 }
Wink Saville08874612014-08-31 19:19:58 -07002107 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002108 if (!isValid) {
2109 return;
2110 }
Wink Saville08874612014-08-31 19:19:58 -07002111
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002112 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2113 intent.putExtra(SUBSCRIPTION_KEY, subId);
2114 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2115 mApp.startActivity(intent);
2116 } finally {
2117 Binder.restoreCallingIdentity(identity);
2118 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 }
2120
Wink Savilleb564aae2014-10-23 10:18:09 -07002121 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002122 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002123 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2124 }
2125
Wink Savilleb564aae2014-10-23 10:18:09 -07002126 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002127 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002128 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2129 }
2130
Wink Savilleb564aae2014-10-23 10:18:09 -07002131 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002133
2134 final long identity = Binder.clearCallingIdentity();
2135 try {
2136 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2137 checkSimPin.start();
2138 return checkSimPin.unlockSim(null, pin);
2139 } finally {
2140 Binder.restoreCallingIdentity(identity);
2141 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002142 }
2143
Wink Savilleb564aae2014-10-23 10:18:09 -07002144 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002145 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002146
2147 final long identity = Binder.clearCallingIdentity();
2148 try {
2149 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2150 checkSimPuk.start();
2151 return checkSimPuk.unlockSim(puk, pin);
2152 } finally {
2153 Binder.restoreCallingIdentity(identity);
2154 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155 }
2156
2157 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002158 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 * a synchronous one.
2160 */
2161 private static class UnlockSim extends Thread {
2162
2163 private final IccCard mSimCard;
2164
2165 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002166 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2167 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168
2169 // For replies from SimCard interface
2170 private Handler mHandler;
2171
2172 // For async handler to identify request type
2173 private static final int SUPPLY_PIN_COMPLETE = 100;
2174
2175 public UnlockSim(IccCard simCard) {
2176 mSimCard = simCard;
2177 }
2178
2179 @Override
2180 public void run() {
2181 Looper.prepare();
2182 synchronized (UnlockSim.this) {
2183 mHandler = new Handler() {
2184 @Override
2185 public void handleMessage(Message msg) {
2186 AsyncResult ar = (AsyncResult) msg.obj;
2187 switch (msg.what) {
2188 case SUPPLY_PIN_COMPLETE:
2189 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2190 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002191 mRetryCount = msg.arg1;
2192 if (ar.exception != null) {
2193 if (ar.exception instanceof CommandException &&
2194 ((CommandException)(ar.exception)).getCommandError()
2195 == CommandException.Error.PASSWORD_INCORRECT) {
2196 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002197 } //When UiccCardApp dispose,handle message and return exception
2198 else if (ar.exception instanceof CommandException &&
2199 ((CommandException) (ar.exception)).getCommandError()
2200 == CommandException.Error.ABORTED) {
2201 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002202 } else {
2203 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2204 }
2205 } else {
2206 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2207 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002208 mDone = true;
2209 UnlockSim.this.notifyAll();
2210 }
2211 break;
2212 }
2213 }
2214 };
2215 UnlockSim.this.notifyAll();
2216 }
2217 Looper.loop();
2218 }
2219
2220 /*
2221 * Use PIN or PUK to unlock SIM card
2222 *
2223 * If PUK is null, unlock SIM card with PIN
2224 *
2225 * If PUK is not null, unlock SIM card with PUK and set PIN code
2226 */
Wink Saville9de0f752013-10-22 19:04:03 -07002227 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228
2229 while (mHandler == null) {
2230 try {
2231 wait();
2232 } catch (InterruptedException e) {
2233 Thread.currentThread().interrupt();
2234 }
2235 }
2236 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2237
2238 if (puk == null) {
2239 mSimCard.supplyPin(pin, callback);
2240 } else {
2241 mSimCard.supplyPuk(puk, pin, callback);
2242 }
2243
2244 while (!mDone) {
2245 try {
2246 Log.d(LOG_TAG, "wait for done");
2247 wait();
2248 } catch (InterruptedException e) {
2249 // Restore the interrupted status
2250 Thread.currentThread().interrupt();
2251 }
2252 }
2253 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002254 int[] resultArray = new int[2];
2255 resultArray[0] = mResult;
2256 resultArray[1] = mRetryCount;
2257 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 }
2259 }
2260
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002261 /**
2262 * This method has been removed due to privacy and stability concerns.
2263 */
2264 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002266 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2267 return;
Wink Saville36469e72014-06-11 15:17:00 -07002268 }
2269
Nathan Harold1f889d82020-06-04 17:05:26 -07002270 @Override
2271 public void updateServiceLocationWithPackageName(String callingPackage) {
2272 mApp.getSystemService(AppOpsManager.class)
2273 .checkPackage(Binder.getCallingUid(), callingPackage);
2274
2275 final int targetSdk = getTargetSdk(callingPackage);
2276 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2277 // Callers targeting S have no business invoking this method.
2278 return;
2279 }
2280
2281 LocationAccessPolicy.LocationPermissionResult locationResult =
2282 LocationAccessPolicy.checkLocationPermission(mApp,
2283 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2284 .setCallingPackage(callingPackage)
2285 .setCallingFeatureId(null)
2286 .setCallingPid(Binder.getCallingPid())
2287 .setCallingUid(Binder.getCallingUid())
2288 .setMethod("updateServiceLocation")
2289 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2290 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2291 .build());
2292 // Apps that lack location permission have no business calling this method;
2293 // however, because no permission was declared in the public API, denials must
2294 // all be "soft".
2295 switch (locationResult) {
2296 case DENIED_HARD: /* fall through */
2297 case DENIED_SOFT:
2298 return;
2299 }
2300
2301 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002302 final long identity = Binder.clearCallingIdentity();
2303 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002304 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002305 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002306 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002307 }
2308 } finally {
2309 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002310 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 }
2312
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002313 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002314 @Override
2315 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002316 return isRadioOnWithFeature(callingPackage, null);
2317 }
2318
2319
2320 @Override
2321 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2322 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2323 callingFeatureId);
2324 }
2325
2326 @Deprecated
2327 @Override
2328 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2329 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002330 }
2331
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002332 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002333 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2334 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002335 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002336 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002337 return false;
2338 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002339
2340 final long identity = Binder.clearCallingIdentity();
2341 try {
2342 return isRadioOnForSubscriber(subId);
2343 } finally {
2344 Binder.restoreCallingIdentity(identity);
2345 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002346 }
2347
2348 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002349 final long identity = Binder.clearCallingIdentity();
2350 try {
2351 final Phone phone = getPhone(subId);
2352 if (phone != null) {
2353 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2354 } else {
2355 return false;
2356 }
2357 } finally {
2358 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 }
2361
2362 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002363 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 }
Wink Saville36469e72014-06-11 15:17:00 -07002365
Wink Savilleb564aae2014-10-23 10:18:09 -07002366 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002367 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002368
2369 final long identity = Binder.clearCallingIdentity();
2370 try {
2371 final Phone phone = getPhone(subId);
2372 if (phone != null) {
2373 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2374 }
2375 } finally {
2376 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002377 }
Wink Saville36469e72014-06-11 15:17:00 -07002378 }
2379
2380 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002381 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002382 }
2383
Wink Savilleb564aae2014-10-23 10:18:09 -07002384 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002385 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002386
2387 final long identity = Binder.clearCallingIdentity();
2388 try {
2389 final Phone phone = getPhone(subId);
2390 if (phone == null) {
2391 return false;
2392 }
2393 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2394 toggleRadioOnOffForSubscriber(subId);
2395 }
2396 return true;
2397 } finally {
2398 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002400 }
Wink Saville36469e72014-06-11 15:17:00 -07002401
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002402 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002403 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002404 /*
2405 * If any of the Radios are available, it will need to be
2406 * shutdown. So return true if any Radio is available.
2407 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002408 final long identity = Binder.clearCallingIdentity();
2409 try {
2410 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2411 Phone phone = PhoneFactory.getPhone(i);
2412 if (phone != null && phone.isRadioAvailable()) return true;
2413 }
2414 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2415 return false;
2416 } finally {
2417 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002418 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002419 }
2420
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002421 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002422 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002423 enforceModifyPermission();
2424
2425 final long identity = Binder.clearCallingIdentity();
2426 try {
2427 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2428 logv("Shutting down Phone " + i);
2429 shutdownRadioUsingPhoneId(i);
2430 }
2431 } finally {
2432 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002433 }
2434 }
2435
2436 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002437 Phone phone = PhoneFactory.getPhone(phoneId);
2438 if (phone != null && phone.isRadioAvailable()) {
2439 phone.shutdownRadio();
2440 }
2441 }
2442
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002444 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002445
2446 final long identity = Binder.clearCallingIdentity();
2447 try {
2448 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2449 if (defaultPhone != null) {
2450 defaultPhone.setRadioPower(turnOn);
2451 return true;
2452 } else {
2453 loge("There's no default phone.");
2454 return false;
2455 }
2456 } finally {
2457 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002458 }
Wink Saville36469e72014-06-11 15:17:00 -07002459 }
2460
Wink Savilleb564aae2014-10-23 10:18:09 -07002461 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002463
2464 final long identity = Binder.clearCallingIdentity();
2465 try {
2466 final Phone phone = getPhone(subId);
2467 if (phone != null) {
2468 phone.setRadioPower(turnOn);
2469 return true;
2470 } else {
2471 return false;
2472 }
2473 } finally {
2474 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002475 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 }
2477
Wink Saville36469e72014-06-11 15:17:00 -07002478 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002479 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 public boolean enableDataConnectivity() {
2481 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002482
2483 final long identity = Binder.clearCallingIdentity();
2484 try {
2485 int subId = mSubscriptionController.getDefaultDataSubId();
2486 final Phone phone = getPhone(subId);
2487 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002488 phone.getDataEnabledSettings().setDataEnabled(
2489 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002490 return true;
2491 } else {
2492 return false;
2493 }
2494 } finally {
2495 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 }
2498
Wink Saville36469e72014-06-11 15:17:00 -07002499 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002500 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 public boolean disableDataConnectivity() {
2502 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503
2504 final long identity = Binder.clearCallingIdentity();
2505 try {
2506 int subId = mSubscriptionController.getDefaultDataSubId();
2507 final Phone phone = getPhone(subId);
2508 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002509 phone.getDataEnabledSettings().setDataEnabled(
2510 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002511 return true;
2512 } else {
2513 return false;
2514 }
2515 } finally {
2516 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002517 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518 }
2519
Sanket Padawe356d7632015-06-22 14:03:32 -07002520 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002521 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002522 final long identity = Binder.clearCallingIdentity();
2523 try {
2524 final Phone phone = getPhone(subId);
2525 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002526 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002527 } else {
2528 return false;
2529 }
2530 } finally {
2531 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002533 }
2534
2535 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002536 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002537 }
2538
pkanwarae03a6b2016-11-06 20:37:09 -08002539 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002540 enforceCallPermission();
2541
2542 final long identity = Binder.clearCallingIdentity();
2543 try {
2544 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2545 return;
2546 }
2547 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2548 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2549 } finally {
2550 Binder.restoreCallingIdentity(identity);
2551 }
pkanwar32d516d2016-10-14 19:37:38 -07002552 };
2553
Wink Savilleb564aae2014-10-23 10:18:09 -07002554 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002556
2557 final long identity = Binder.clearCallingIdentity();
2558 try {
2559 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2560 return false;
2561 }
2562 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2563 } finally {
2564 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 }
2567
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002569 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002570 }
2571
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002572 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002573 final long identity = Binder.clearCallingIdentity();
2574 try {
2575 Phone phone = PhoneFactory.getPhone(slotIndex);
2576 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2577 PhoneConstantConversions.convertCallState(phone.getState());
2578 } finally {
2579 Binder.restoreCallingIdentity(identity);
2580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 }
2582
Sanket Padawe356d7632015-06-22 14:03:32 -07002583 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002584 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002585 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2586 }
2587
2588 @Override
2589 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002590 final long identity = Binder.clearCallingIdentity();
2591 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002592 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002593 if (phone != null) {
2594 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2595 } else {
2596 return PhoneConstantConversions.convertDataState(
2597 PhoneConstants.DataState.DISCONNECTED);
2598 }
2599 } finally {
2600 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002601 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602 }
2603
Sanket Padawe356d7632015-06-22 14:03:32 -07002604 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002605 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002606 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2607 }
2608
2609 @Override
2610 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002611 final long identity = Binder.clearCallingIdentity();
2612 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002613 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614 if (phone != null) {
2615 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2616 } else {
2617 return TelephonyManager.DATA_ACTIVITY_NONE;
2618 }
2619 } finally {
2620 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002622 }
2623
2624 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002625 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002626 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002627 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002628
2629 LocationAccessPolicy.LocationPermissionResult locationResult =
2630 LocationAccessPolicy.checkLocationPermission(mApp,
2631 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2632 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002633 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002634 .setCallingPid(Binder.getCallingPid())
2635 .setCallingUid(Binder.getCallingUid())
2636 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002637 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002638 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2639 .build());
2640 switch (locationResult) {
2641 case DENIED_HARD:
2642 throw new SecurityException("Not allowed to access cell location");
2643 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002644 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2645 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002646 }
2647
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002648 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002649 final long identity = Binder.clearCallingIdentity();
2650 try {
2651 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002652 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002653 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654 } finally {
2655 Binder.restoreCallingIdentity(identity);
2656 }
Svetoslav64fad262015-04-14 14:35:21 -07002657 }
2658
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002659 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002660 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002661 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2662 // registered cell info, so return a NULL country instead.
2663 final long identity = Binder.clearCallingIdentity();
2664 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002665 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2666 // Get default phone in this case.
2667 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2668 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002669 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002670 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002671 if (phone == null) return "";
2672 ServiceStateTracker sst = phone.getServiceStateTracker();
2673 if (sst == null) return "";
2674 LocaleTracker lt = sst.getLocaleTracker();
2675 if (lt == null) return "";
2676 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2677 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2678 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002679 } finally {
2680 Binder.restoreCallingIdentity(identity);
2681 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002682 }
2683
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002684 /**
2685 * This method was removed due to potential issues caused by performing partial
2686 * updates of service state, and lack of a credible use case.
2687 *
2688 * This has the ability to break the telephony implementation by disabling notification of
2689 * changes in device connectivity. DO NOT USE THIS!
2690 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002691 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 public void enableLocationUpdates() {
2693 mApp.enforceCallingOrSelfPermission(
2694 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 }
2696
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002697 /**
2698 * This method was removed due to potential issues caused by performing partial
2699 * updates of service state, and lack of a credible use case.
2700 *
2701 * This has the ability to break the telephony implementation by disabling notification of
2702 * changes in device connectivity. DO NOT USE THIS!
2703 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002704 @Override
2705 public void disableLocationUpdates() {
2706 mApp.enforceCallingOrSelfPermission(
2707 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 }
2709
Nathan Harold31d7ff32018-10-15 20:20:30 -07002710 /**
2711 * Returns the target SDK version number for a given package name.
2712 *
Nathan Haroldec184742019-07-10 17:04:16 -07002713 * This call MUST be invoked before clearing the calling UID.
2714 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002715 * @return target SDK if the package is found or INT_MAX.
2716 */
2717 private int getTargetSdk(String packageName) {
2718 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002719 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002720 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002721 if (ai != null) return ai.targetSdkVersion;
2722 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002723 loge("Failed to get package info for pkg="
2724 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002725 }
2726 return Integer.MAX_VALUE;
2727 }
2728
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729 @Override
2730 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002731 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2732 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002733 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002734 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2735 throw new SecurityException(
2736 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2737 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002738
Jordan Liu1617b712019-07-10 15:06:26 -07002739 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002740 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2741 return null;
2742 }
Svetoslav64fad262015-04-14 14:35:21 -07002743
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002744 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002746 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002747 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002748
Nathan Haroldf180aac2018-06-01 18:43:55 -07002749 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2750 for (CellInfo ci : info) {
2751 if (ci instanceof CellInfoGsm) {
2752 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2753 } else if (ci instanceof CellInfoWcdma) {
2754 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2755 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002756 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002757 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002758 }
2759
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002760 private List<CellInfo> getCachedCellInfo() {
2761 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2762 for (Phone phone : PhoneFactory.getPhones()) {
2763 List<CellInfo> info = phone.getAllCellInfo();
2764 if (info != null) cellInfos.addAll(info);
2765 }
2766 return cellInfos;
2767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002768
2769 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002770 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002771 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002772 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002773
2774 LocationAccessPolicy.LocationPermissionResult locationResult =
2775 LocationAccessPolicy.checkLocationPermission(mApp,
2776 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2777 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002778 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002779 .setCallingPid(Binder.getCallingPid())
2780 .setCallingUid(Binder.getCallingUid())
2781 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002782 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002783 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2784 .build());
2785 switch (locationResult) {
2786 case DENIED_HARD:
2787 throw new SecurityException("Not allowed to access cell info");
2788 case DENIED_SOFT:
2789 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002790 }
2791
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002792 final int targetSdk = getTargetSdk(callingPackage);
2793 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2794 return getCachedCellInfo();
2795 }
2796
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002797 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002798 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2802 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002803 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002804 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805 if (info != null) cellInfos.addAll(info);
2806 }
2807 return cellInfos;
2808 } finally {
2809 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002810 }
2811 }
2812
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002813 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002814 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2815 String callingFeatureId) {
2816 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2817 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002818 }
2819
2820 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002821 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2822 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002823 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002824 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002825 }
2826
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002827 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2828 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002829 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002830 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002831
2832 LocationAccessPolicy.LocationPermissionResult locationResult =
2833 LocationAccessPolicy.checkLocationPermission(mApp,
2834 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2835 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002836 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002837 .setCallingPid(Binder.getCallingPid())
2838 .setCallingUid(Binder.getCallingUid())
2839 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002840 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2841 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002842 .build());
2843 switch (locationResult) {
2844 case DENIED_HARD:
Hall Liud60acc92020-05-21 17:09:35 -07002845 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2846 // Safetynet logging for b/154934934
2847 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2848 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002849 throw new SecurityException("Not allowed to access cell info");
2850 case DENIED_SOFT:
Hall Liud60acc92020-05-21 17:09:35 -07002851 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2852 // Safetynet logging for b/154934934
2853 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2854 }
Nathan Harold5320c422019-05-09 10:26:08 -07002855 try {
2856 cb.onCellInfo(new ArrayList<CellInfo>());
2857 } catch (RemoteException re) {
2858 // Drop without consequences
2859 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002860 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002861 }
2862
Nathan Harolda939a962019-05-09 10:13:47 -07002863
2864 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002865 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2866
2867 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2868 }
2869
2870 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002871 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002872 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002873 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002874
2875 final long identity = Binder.clearCallingIdentity();
2876 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002877 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878 } finally {
2879 Binder.restoreCallingIdentity(identity);
2880 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002881 }
2882
Shishir Agrawala9f32182016-04-12 12:00:16 -07002883 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002884 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002885 Phone phone = PhoneFactory.getPhone(slotIndex);
2886 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002887 return null;
2888 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002889 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002890 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002891 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002892 return null;
2893 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002894
2895 final long identity = Binder.clearCallingIdentity();
2896 try {
2897 return phone.getImei();
2898 } finally {
2899 Binder.restoreCallingIdentity(identity);
2900 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002901 }
2902
2903 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002904 public String getTypeAllocationCodeForSlot(int slotIndex) {
2905 Phone phone = PhoneFactory.getPhone(slotIndex);
2906 String tac = null;
2907 if (phone != null) {
2908 String imei = phone.getImei();
2909 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2910 }
2911 return tac;
2912 }
2913
2914 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002915 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002916 Phone phone = PhoneFactory.getPhone(slotIndex);
2917 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002918 return null;
2919 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002920
Jeff Davidson913390f2018-02-23 17:11:49 -08002921 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002922 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002923 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002924 return null;
2925 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002926
2927 final long identity = Binder.clearCallingIdentity();
2928 try {
2929 return phone.getMeid();
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
2932 }
Jack Yu2af8d712017-03-15 17:14:14 -07002933 }
2934
2935 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002936 public String getManufacturerCodeForSlot(int slotIndex) {
2937 Phone phone = PhoneFactory.getPhone(slotIndex);
2938 String manufacturerCode = null;
2939 if (phone != null) {
2940 String meid = phone.getMeid();
2941 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2942 }
2943 return manufacturerCode;
2944 }
2945
2946 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002947 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2948 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002949 Phone phone = PhoneFactory.getPhone(slotIndex);
2950 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002951 return null;
2952 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002953 int subId = phone.getSubId();
2954 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002955 mApp, subId, callingPackage, callingFeatureId,
2956 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002957 return null;
2958 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002959
2960 final long identity = Binder.clearCallingIdentity();
2961 try {
2962 return phone.getDeviceSvn();
2963 } finally {
2964 Binder.restoreCallingIdentity(identity);
2965 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002966 }
2967
fionaxu43304da2017-11-27 22:51:16 -08002968 @Override
2969 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002970 final long identity = Binder.clearCallingIdentity();
2971 try {
2972 final Phone phone = getPhone(subId);
2973 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2974 } finally {
2975 Binder.restoreCallingIdentity(identity);
2976 }
fionaxu43304da2017-11-27 22:51:16 -08002977 }
2978
2979 @Override
2980 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 final Phone phone = getPhone(subId);
2984 return phone == null ? null : phone.getCarrierName();
2985 } finally {
2986 Binder.restoreCallingIdentity(identity);
2987 }
fionaxu43304da2017-11-27 22:51:16 -08002988 }
2989
calvinpanffe225e2018-11-01 19:43:06 +08002990 @Override
chen xu0026ca62019-03-06 15:28:50 -08002991 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002992 final long identity = Binder.clearCallingIdentity();
2993 try {
2994 final Phone phone = getPhone(subId);
2995 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002996 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002997 } finally {
2998 Binder.restoreCallingIdentity(identity);
2999 }
3000 }
3001
3002 @Override
chen xu0026ca62019-03-06 15:28:50 -08003003 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003004 final long identity = Binder.clearCallingIdentity();
3005 try {
3006 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003007 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
3011 }
3012
chen xu651eec72018-11-11 19:03:44 -08003013 @Override
chen xu864e11c2018-12-06 22:10:03 -08003014 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3015 if (!isSubscriptionMccMnc) {
3016 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3017 }
chen xu651eec72018-11-11 19:03:44 -08003018 final Phone phone = PhoneFactory.getPhone(slotIndex);
3019 if (phone == null) {
3020 return TelephonyManager.UNKNOWN_CARRIER_ID;
3021 }
3022 final long identity = Binder.clearCallingIdentity();
3023 try {
3024 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3025 } finally {
3026 Binder.restoreCallingIdentity(identity);
3027 }
3028 }
3029
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003030 //
3031 // Internal helper methods.
3032 //
3033
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003034 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003035 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3036 *
3037 * @throws SecurityException if the caller does not have the required permission
3038 */
3039 private void enforceModifyPermission() {
3040 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3041 }
3042
Shuo Qiancd19c462020-01-16 20:51:11 -08003043 /**
3044 * Make sure the caller is system.
3045 *
3046 * @throws SecurityException if the caller is not system.
3047 */
3048 private void enforceSystemCaller() {
3049 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3050 throw new SecurityException("Caller must be system");
3051 }
3052 }
3053
Shuo Qian3b6ee772019-11-13 17:43:31 -08003054 private void enforceActiveEmergencySessionPermission() {
3055 mApp.enforceCallingOrSelfPermission(
3056 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3057 }
3058
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003059 /**
3060 * Make sure the caller has the CALL_PHONE permission.
3061 *
3062 * @throws SecurityException if the caller does not have the required permission
3063 */
3064 private void enforceCallPermission() {
3065 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3066 }
3067
paulhu5a773602019-08-23 19:17:33 +08003068 private void enforceSettingsPermission() {
3069 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003070 }
3071
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003072 private String createTelUrl(String number) {
3073 if (TextUtils.isEmpty(number)) {
3074 return null;
3075 }
3076
Jake Hambye994d462014-02-03 13:10:13 -08003077 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003078 }
3079
Ihab Awadf9e92732013-12-05 18:02:52 -08003080 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003081 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3082 }
3083
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003084 private static void logv(String msg) {
3085 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3086 }
3087
Ihab Awadf9e92732013-12-05 18:02:52 -08003088 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003089 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3090 }
3091
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003092 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003093 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003094 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003095 }
3096
Sanket Padawe356d7632015-06-22 14:03:32 -07003097 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003098 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003099 final long identity = Binder.clearCallingIdentity();
3100 try {
3101 final Phone phone = PhoneFactory.getPhone(slotIndex);
3102 if (phone == null) {
3103 return PhoneConstants.PHONE_TYPE_NONE;
3104 } else {
3105 return phone.getPhoneType();
3106 }
3107 } finally {
3108 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003109 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003110 }
3111
3112 /**
3113 * Returns the CDMA ERI icon index to display
3114 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003115 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003116 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3117 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3118 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003119 }
3120
Sanket Padawe356d7632015-06-22 14:03:32 -07003121 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003122 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3123 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003124 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003125 mApp, subId, callingPackage, callingFeatureId,
3126 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003127 return -1;
3128 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003129
3130 final long identity = Binder.clearCallingIdentity();
3131 try {
3132 final Phone phone = getPhone(subId);
3133 if (phone != null) {
3134 return phone.getCdmaEriIconIndex();
3135 } else {
3136 return -1;
3137 }
3138 } finally {
3139 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003140 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003141 }
3142
3143 /**
3144 * Returns the CDMA ERI icon mode,
3145 * 0 - ON
3146 * 1 - FLASHING
3147 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003148 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003149 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3150 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3151 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003152 }
3153
Sanket Padawe356d7632015-06-22 14:03:32 -07003154 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003155 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3156 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003157 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003158 mApp, subId, callingPackage, callingFeatureId,
3159 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003160 return -1;
3161 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003162
3163 final long identity = Binder.clearCallingIdentity();
3164 try {
3165 final Phone phone = getPhone(subId);
3166 if (phone != null) {
3167 return phone.getCdmaEriIconMode();
3168 } else {
3169 return -1;
3170 }
3171 } finally {
3172 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003173 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003174 }
3175
3176 /**
3177 * Returns the CDMA ERI text,
3178 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003179 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003180 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3181 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3182 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003183 }
3184
Sanket Padawe356d7632015-06-22 14:03:32 -07003185 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003186 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3187 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003188 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003189 mApp, subId, callingPackage, callingFeatureId,
3190 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003191 return null;
3192 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003193
3194 final long identity = Binder.clearCallingIdentity();
3195 try {
3196 final Phone phone = getPhone(subId);
3197 if (phone != null) {
3198 return phone.getCdmaEriText();
3199 } else {
3200 return null;
3201 }
3202 } finally {
3203 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003204 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003205 }
3206
3207 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003208 * Returns the CDMA MDN.
3209 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003210 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003211 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3213 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214
3215 final long identity = Binder.clearCallingIdentity();
3216 try {
3217 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003218 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003219 return phone.getLine1Number();
3220 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003221 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003222 return null;
3223 }
3224 } finally {
3225 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003226 }
3227 }
3228
3229 /**
3230 * Returns the CDMA MIN.
3231 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003232 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003233 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3235 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003236
3237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 final Phone phone = getPhone(subId);
3240 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3241 return phone.getCdmaMin();
3242 } else {
3243 return null;
3244 }
3245 } finally {
3246 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003247 }
3248 }
3249
Hall Liud892bec2018-11-30 14:51:45 -08003250 @Override
3251 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3252 INumberVerificationCallback callback, String callingPackage) {
3253 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3254 != PERMISSION_GRANTED) {
3255 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3256 }
3257 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3258
3259 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3260 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3261 throw new SecurityException("Calling package must be configured in the device config");
3262 }
3263
3264 if (range == null) {
3265 throw new NullPointerException("Range must be non-null");
3266 }
3267
3268 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003269 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003270
3271 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3272 }
3273
Junda Liuca05d5d2014-08-14 22:36:34 -07003274 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003275 * Returns true if CDMA provisioning needs to run.
3276 */
3277 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003278 final long identity = Binder.clearCallingIdentity();
3279 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003280 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003281 } finally {
3282 Binder.restoreCallingIdentity(identity);
3283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003284 }
3285
3286 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003287 * Sets the voice mail number of a given subId.
3288 */
3289 @Override
3290 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003291 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3292 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003293
3294 final long identity = Binder.clearCallingIdentity();
3295 try {
3296 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3297 new Pair<String, String>(alphaTag, number), new Integer(subId));
3298 return success;
3299 } finally {
3300 Binder.restoreCallingIdentity(identity);
3301 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003302 }
3303
Ta-wei Yen87c49842016-05-13 21:19:52 -07003304 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003305 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3306 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003307 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3308 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003309 if (!TextUtils.equals(callingPackage, systemDialer)) {
3310 throw new SecurityException("caller must be system dialer");
3311 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003312
3313 final long identity = Binder.clearCallingIdentity();
3314 try {
3315 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3316 if (phoneAccountHandle == null) {
3317 return null;
3318 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003319 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003320 } finally {
3321 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003322 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003323 }
3324
3325 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003326 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3327 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003328 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003330 mApp, subId, callingPackage, callingFeatureId,
3331 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003332 return null;
3333 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003334
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003335 final long identity = Binder.clearCallingIdentity();
3336 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003337 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003338 } finally {
3339 Binder.restoreCallingIdentity(identity);
3340 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003341 }
3342
3343 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003344 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3345 VisualVoicemailSmsFilterSettings settings) {
3346 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347
3348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003351 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003352 } finally {
3353 Binder.restoreCallingIdentity(identity);
3354 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003355 }
3356
3357 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003358 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3359 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003360
3361 final long identity = Binder.clearCallingIdentity();
3362 try {
3363 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003364 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003365 } finally {
3366 Binder.restoreCallingIdentity(identity);
3367 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003368 }
3369
3370 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003371 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3372 String callingPackage, int subId) {
3373 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003374
3375 final long identity = Binder.clearCallingIdentity();
3376 try {
3377 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003378 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003379 } finally {
3380 Binder.restoreCallingIdentity(identity);
3381 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003382 }
3383
3384 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003385 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003386 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003387
3388 final long identity = Binder.clearCallingIdentity();
3389 try {
3390 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003391 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003392 } finally {
3393 Binder.restoreCallingIdentity(identity);
3394 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003395 }
3396
3397 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003398 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3399 String callingAttributionTag, int subId, String number, int port, String text,
3400 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003401 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003402 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003403 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003404 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003405 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3406 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003407 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003408
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003409 /**
fionaxu0152e512016-11-14 13:36:14 -08003410 * Sets the voice activation state of a given subId.
3411 */
3412 @Override
3413 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003414 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3415 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003416
3417 final long identity = Binder.clearCallingIdentity();
3418 try {
3419 final Phone phone = getPhone(subId);
3420 if (phone != null) {
3421 phone.setVoiceActivationState(activationState);
3422 } else {
3423 loge("setVoiceActivationState fails with invalid subId: " + subId);
3424 }
3425 } finally {
3426 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003427 }
3428 }
3429
3430 /**
3431 * Sets the data activation state of a given subId.
3432 */
3433 @Override
3434 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3436 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003437
3438 final long identity = Binder.clearCallingIdentity();
3439 try {
3440 final Phone phone = getPhone(subId);
3441 if (phone != null) {
3442 phone.setDataActivationState(activationState);
3443 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003444 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003445 }
3446 } finally {
3447 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003448 }
3449 }
3450
3451 /**
3452 * Returns the voice activation state of a given subId.
3453 */
3454 @Override
3455 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003456 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003457
fionaxu0152e512016-11-14 13:36:14 -08003458 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003459 final long identity = Binder.clearCallingIdentity();
3460 try {
3461 if (phone != null) {
3462 return phone.getVoiceActivationState();
3463 } else {
3464 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3465 }
3466 } finally {
3467 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003468 }
3469 }
3470
3471 /**
3472 * Returns the data activation state of a given subId.
3473 */
3474 @Override
3475 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003476 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003477
fionaxu0152e512016-11-14 13:36:14 -08003478 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003479 final long identity = Binder.clearCallingIdentity();
3480 try {
3481 if (phone != null) {
3482 return phone.getDataActivationState();
3483 } else {
3484 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3485 }
3486 } finally {
3487 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003488 }
3489 }
3490
3491 /**
Wink Saville36469e72014-06-11 15:17:00 -07003492 * Returns the unread count of voicemails for a subId
3493 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003494 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003495 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3496 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003497 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003498 mApp, subId, callingPackage, callingFeatureId,
3499 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003500 return 0;
3501 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003502 final long identity = Binder.clearCallingIdentity();
3503 try {
3504 final Phone phone = getPhone(subId);
3505 if (phone != null) {
3506 return phone.getVoiceMessageCount();
3507 } else {
3508 return 0;
3509 }
3510 } finally {
3511 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003512 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003513 }
3514
3515 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003516 * returns true, if the device is in a state where both voice and data
3517 * are supported simultaneously. This can change based on location or network condition.
3518 */
3519 @Override
3520 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003521 final long identity = Binder.clearCallingIdentity();
3522 try {
3523 final Phone phone = getPhone(subId);
3524 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3525 } finally {
3526 Binder.restoreCallingIdentity(identity);
3527 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003528 }
3529
3530 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003531 * Send the dialer code if called from the current default dialer or the caller has
3532 * carrier privilege.
3533 * @param inputCode The dialer code to send
3534 */
3535 @Override
3536 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003537 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003538 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003539 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3540 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003541 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003542 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003543 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003544 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003545
3546 final long identity = Binder.clearCallingIdentity();
3547 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003548 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003549 } finally {
3550 Binder.restoreCallingIdentity(identity);
3551 }
fionaxu235cc5e2017-03-06 22:25:57 -08003552 }
3553
Pengquan Menga1bb6272018-09-06 09:59:22 -07003554 @Override
3555 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003556 TelephonyPermissions
3557 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3558 mApp, subId, "getNetworkSelectionMode");
3559 final long identity = Binder.clearCallingIdentity();
3560 try {
3561 if (!isActiveSubscription(subId)) {
3562 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3563 }
3564 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3565 } finally {
3566 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003567 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003568 }
3569
Brad Ebinger35c841c2018-10-01 10:40:55 -07003570 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003571 public boolean isInEmergencySmsMode() {
3572 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 for (Phone phone : PhoneFactory.getPhones()) {
3576 if (phone.isInEmergencySmsMode()) {
3577 return true;
3578 }
3579 }
3580 } finally {
3581 Binder.restoreCallingIdentity(identity);
3582 }
3583 return false;
3584 }
3585
shilu366312e2019-12-17 09:28:10 -08003586 /**
3587 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3588 * @param subId The subscription to use to check the configuration.
3589 * @param c The callback that will be used to send the result.
3590 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003591 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003592 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3593 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003594 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3595 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003596
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003597 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3598 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3599 "IMS not available on device.");
3600 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003601 final long token = Binder.clearCallingIdentity();
3602 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003603 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003604 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003605 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003606 } catch (ImsException e) {
3607 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003608 } finally {
3609 Binder.restoreCallingIdentity(token);
3610 }
3611 }
3612
shilu366312e2019-12-17 09:28:10 -08003613 /**
3614 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3615 * @param subId The subscription to use to check the configuration.
3616 * @param c The callback that will be used to send the result.
3617 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003618 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003619 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003620 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3621 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003622 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3623 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3624 }
Meng Wangafbc5852019-09-19 17:37:13 -07003625 final long token = Binder.clearCallingIdentity();
3626 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003627 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003628 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3629 .removeRegistrationCallbackForSubscription(c, subId);
3630 } catch (ImsException e) {
3631 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3632 + "is inactive, ignoring unregister.");
3633 // If the subscription is no longer active, just return, since the callback
3634 // will already have been removed internally.
3635 } finally {
3636 Binder.restoreCallingIdentity(token);
3637 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003638 }
3639
Brad Ebingera34a6c22019-10-22 17:36:18 -07003640 /**
3641 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3642 */
3643 @Override
3644 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3645 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3646 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3647 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3648 "IMS not available on device.");
3649 }
3650 final long token = Binder.clearCallingIdentity();
3651 try {
3652 Phone phone = getPhone(subId);
3653 if (phone == null) {
3654 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3655 + subId + "'");
3656 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3657 }
3658 phone.getImsRegistrationState(regState -> {
3659 try {
3660 consumer.accept((regState == null)
3661 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3662 } catch (RemoteException e) {
3663 // Ignore if the remote process is no longer available to call back.
3664 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3665 }
3666 });
3667 } finally {
3668 Binder.restoreCallingIdentity(token);
3669 }
3670 }
3671
3672 /**
3673 * Get the transport type for the IMS service registration state.
3674 */
3675 @Override
3676 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003677 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3678 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003679 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3680 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3681 "IMS not available on device.");
3682 }
3683 final long token = Binder.clearCallingIdentity();
3684 try {
3685 Phone phone = getPhone(subId);
3686 if (phone == null) {
3687 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3688 + subId + "'");
3689 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3690 }
3691 phone.getImsRegistrationTech(regTech -> {
3692 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3693 int regTechConverted = (regTech == null)
3694 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3695 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3696 regTechConverted);
3697 try {
3698 consumer.accept(regTechConverted);
3699 } catch (RemoteException e) {
3700 // Ignore if the remote process is no longer available to call back.
3701 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3702 }
3703 });
3704 } finally {
3705 Binder.restoreCallingIdentity(token);
3706 }
3707 }
3708
shilu366312e2019-12-17 09:28:10 -08003709 /**
3710 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3711 * @param subId The subscription to use to check the configuration.
3712 * @param c The callback that will be used to send the result.
3713 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003714 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003715 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3716 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003717 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3718 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003719 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3720 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3721 "IMS not available on device.");
3722 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003723 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3724 final long token = Binder.clearCallingIdentity();
3725 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003726 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003727 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003728 } catch (ImsException e) {
3729 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003730 } finally {
3731 Binder.restoreCallingIdentity(token);
3732 }
3733 }
3734
shilu366312e2019-12-17 09:28:10 -08003735 /**
3736 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3737 * @param subId The subscription to use to check the configuration.
3738 * @param c The callback that will be used to send the result.
3739 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003740 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003741 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003742 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3743 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003744 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3745 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3746 }
Meng Wangafbc5852019-09-19 17:37:13 -07003747
3748 final long token = Binder.clearCallingIdentity();
3749 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003750 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003751 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003752 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003753 } catch (ImsException e) {
3754 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3755 + "is inactive, ignoring unregister.");
3756 // If the subscription is no longer active, just return, since the callback
3757 // will already have been removed internally.
3758 } finally {
3759 Binder.restoreCallingIdentity(token);
3760 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003761 }
3762
3763 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003764 public boolean isCapable(int subId, int capability, int regTech) {
3765 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003766 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3767 final long token = Binder.clearCallingIdentity();
3768 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003769 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003770 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003771 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003772 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3773 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003774 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003775 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3776 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003777 } finally {
3778 Binder.restoreCallingIdentity(token);
3779 }
3780 }
3781
3782 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003783 public boolean isAvailable(int subId, int capability, int regTech) {
3784 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003785 final long token = Binder.clearCallingIdentity();
3786 try {
3787 Phone phone = getPhone(subId);
3788 if (phone == null) return false;
3789 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003790 } catch (com.android.ims.ImsException e) {
3791 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3792 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003793 } finally {
3794 Binder.restoreCallingIdentity(token);
3795 }
3796 }
3797
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003798 /**
3799 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3800 * subscription.
3801 * @param subId The subscription to use to check the configuration.
3802 * @param callback The callback that will be used to send the result.
3803 * @param capability The MmTelFeature capability that will be used to send the result.
3804 * @param transportType The transport type of the MmTelFeature capability.
3805 */
3806 @Override
3807 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3808 int transportType) {
3809 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3810 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3811 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3812 "IMS not available on device.");
3813 }
3814 final long token = Binder.clearCallingIdentity();
3815 try {
3816 int slotId = getSlotIndex(subId);
3817 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3818 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3819 + subId + "'");
3820 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3821 }
3822 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3823 transportType, aBoolean -> {
3824 try {
3825 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3826 } catch (RemoteException e) {
3827 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3828 + "running. Ignore");
3829 }
3830 });
3831 } finally {
3832 Binder.restoreCallingIdentity(token);
3833 }
3834 }
3835
shilu366312e2019-12-17 09:28:10 -08003836 /**
3837 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3838 * @param subId The subscription to use to check the configuration.
3839 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003840 @Override
3841 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003842 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3843 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003844
Brad Ebinger35c841c2018-10-01 10:40:55 -07003845 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3846 final long token = Binder.clearCallingIdentity();
3847 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003848 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003849 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003850 } catch (ImsException e) {
3851 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003852 } finally {
3853 Binder.restoreCallingIdentity(token);
3854 }
3855 }
3856
3857 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003858 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003859 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003860 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003861 final long identity = Binder.clearCallingIdentity();
3862 try {
3863 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003864 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003865 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003866 } catch (ImsException e) {
3867 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003868 } finally {
3869 Binder.restoreCallingIdentity(identity);
3870 }
3871 }
3872
shilu366312e2019-12-17 09:28:10 -08003873 /**
3874 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3875 * @param subId The subscription to use to check the configuration.
3876 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003877 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003878 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003879 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3880 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003881 final long identity = Binder.clearCallingIdentity();
3882 try {
3883 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003884 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3885 } catch (ImsException e) {
3886 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003887 } finally {
3888 Binder.restoreCallingIdentity(identity);
3889 }
3890 }
3891
3892 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003893 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003895 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003896 final long identity = Binder.clearCallingIdentity();
3897 try {
3898 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003899 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003900 } catch (ImsException e) {
3901 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003902 } finally {
3903 Binder.restoreCallingIdentity(identity);
3904 }
3905 }
3906
shilu366312e2019-12-17 09:28:10 -08003907 /**
3908 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3909 * @param subId The subscription to use to check the configuration.
3910 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003911 @Override
3912 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003913 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3914 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003915 final long identity = Binder.clearCallingIdentity();
3916 try {
3917 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003918 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003919 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003920 } catch (ImsException e) {
3921 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003922 } finally {
3923 Binder.restoreCallingIdentity(identity);
3924 }
3925 }
3926
3927 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003928 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003930 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003931 final long identity = Binder.clearCallingIdentity();
3932 try {
3933 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003934 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003935 } catch (ImsException e) {
3936 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003937 } finally {
3938 Binder.restoreCallingIdentity(identity);
3939 }
3940 }
3941
shilu366312e2019-12-17 09:28:10 -08003942 /**
3943 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3944 * @param subId The subscription to use to check the configuration.
3945 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003946 @Override
3947 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003948 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3949 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003950 final long identity = Binder.clearCallingIdentity();
3951 try {
3952 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003953 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003954 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003955 } catch (ImsException e) {
3956 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003957 } finally {
3958 Binder.restoreCallingIdentity(identity);
3959 }
3960 }
3961
3962 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003963 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003964 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003965 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003966 final long identity = Binder.clearCallingIdentity();
3967 try {
3968 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003969 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003970 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003971 } catch (ImsException e) {
3972 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003973 } finally {
3974 Binder.restoreCallingIdentity(identity);
3975 }
3976 }
3977
3978 @Override
3979 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3981 "setVoWiFiNonPersistent");
3982 final long identity = Binder.clearCallingIdentity();
3983 try {
3984 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003985 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003986 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003987 } catch (ImsException e) {
3988 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003989 } finally {
3990 Binder.restoreCallingIdentity(identity);
3991 }
3992 }
3993
shilu366312e2019-12-17 09:28:10 -08003994 /**
3995 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3996 * @param subId The subscription to use to check the configuration.
3997 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003998 @Override
3999 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004000 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4001 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004002 final long identity = Binder.clearCallingIdentity();
4003 try {
4004 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004005 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004006 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004007 } catch (ImsException e) {
4008 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004009 } finally {
4010 Binder.restoreCallingIdentity(identity);
4011 }
4012 }
4013
4014 @Override
4015 public void setVoWiFiModeSetting(int subId, int mode) {
4016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4017 "setVoWiFiModeSetting");
4018 final long identity = Binder.clearCallingIdentity();
4019 try {
4020 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004021 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004022 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004023 } catch (ImsException e) {
4024 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004025 } finally {
4026 Binder.restoreCallingIdentity(identity);
4027 }
4028 }
4029
4030 @Override
4031 public int getVoWiFiRoamingModeSetting(int subId) {
4032 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4033 final long identity = Binder.clearCallingIdentity();
4034 try {
4035 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004036 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004037 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004038 } catch (ImsException e) {
4039 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004040 } finally {
4041 Binder.restoreCallingIdentity(identity);
4042 }
4043 }
4044
4045 @Override
4046 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4047 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4048 "setVoWiFiRoamingModeSetting");
4049 final long identity = Binder.clearCallingIdentity();
4050 try {
4051 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004052 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004053 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004054 } catch (ImsException e) {
4055 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004056 } finally {
4057 Binder.restoreCallingIdentity(identity);
4058 }
4059 }
4060
4061 @Override
4062 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4063 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4064 "setRttCapabilityEnabled");
4065 final long identity = Binder.clearCallingIdentity();
4066 try {
4067 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004068 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4069 } catch (ImsException e) {
4070 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004071 } finally {
4072 Binder.restoreCallingIdentity(identity);
4073 }
4074 }
4075
shilu366312e2019-12-17 09:28:10 -08004076 /**
4077 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4078 * @param subId The subscription to use to check the configuration.
4079 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004080 @Override
4081 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004082 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4083 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004084 final long identity = Binder.clearCallingIdentity();
4085 try {
4086 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004087 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004088 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004089 } catch (ImsException e) {
4090 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004091 } finally {
4092 Binder.restoreCallingIdentity(identity);
4093 }
4094 }
4095
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004096 @Override
4097 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4098 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4099 final long identity = Binder.clearCallingIdentity();
4100 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004101 if (!isImsAvailableOnDevice()) {
4102 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4103 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004104 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004105 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004106 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004107 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004108 } catch (ImsException e) {
4109 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004110 } finally {
4111 Binder.restoreCallingIdentity(identity);
4112 }
4113 }
4114
4115 @Override
4116 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4117 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4118 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004119 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4120 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4121 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004122 try {
4123 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004124 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004125 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004126 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004127 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4128 + "is inactive, ignoring unregister.");
4129 // If the subscription is no longer active, just return, since the callback will already
4130 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004131 } finally {
4132 Binder.restoreCallingIdentity(identity);
4133 }
4134 }
4135
allenwtsu99c623b2020-01-03 18:24:23 +08004136
4137 private void checkModifyPhoneStatePermission(int subId, String message) {
4138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4139 message);
4140 }
4141
4142 private boolean isImsProvisioningRequired(int subId, int capability,
4143 boolean isMmtelCapability) {
4144 Phone phone = getPhone(subId);
4145 if (phone == null) {
4146 loge("phone instance null for subid " + subId);
4147 return false;
4148 }
4149 if (isMmtelCapability) {
4150 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4151 return false;
4152 }
4153 } else {
4154 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4155 return false;
4156 }
4157 }
4158 return true;
4159 }
4160
4161 @Override
4162 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4163 boolean isProvisioned) {
4164 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4165
4166 final long identity = Binder.clearCallingIdentity();
4167 try {
4168 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4169 if (!isImsProvisioningRequired(subId, capability, false)) {
4170 return;
4171 }
4172
4173 // this capability requires provisioning, route to the correct API.
4174 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4175 switch (capability) {
4176 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4177 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4178 ims.setEabProvisioned(isProvisioned);
4179 break;
4180 default: {
4181 throw new IllegalArgumentException("Tried to set provisioning for "
4182 + "rcs capability '" + capability + "', which does not require "
4183 + "provisioning.");
4184 }
4185 }
4186 } finally {
4187 Binder.restoreCallingIdentity(identity);
4188 }
4189
4190 }
4191
4192
4193 @Override
4194 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4195 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4196 final long identity = Binder.clearCallingIdentity();
4197 try {
4198 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4199 if (!isImsProvisioningRequired(subId, capability, false)) {
4200 return true;
4201 }
4202
4203 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4204 switch (capability) {
4205 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4206 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4207 return ims.isEabProvisionedOnDevice();
4208
4209 default: {
4210 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4211 + "capability '" + capability + "', which does not require "
4212 + "provisioning.");
4213 }
4214 }
4215
4216 } finally {
4217 Binder.restoreCallingIdentity(identity);
4218 }
4219 }
4220
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004221 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004222 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4223 boolean isProvisioned) {
4224 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4225 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4226 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4227 }
allenwtsu99c623b2020-01-03 18:24:23 +08004228 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004229 final long identity = Binder.clearCallingIdentity();
4230 try {
4231 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004232 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004233 return;
4234 }
4235
4236 // this capability requires provisioning, route to the correct API.
4237 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4238 switch (capability) {
4239 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4240 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4241 ims.setVolteProvisioned(isProvisioned);
4242 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4243 ims.setWfcProvisioned(isProvisioned);
4244 }
4245 break;
4246 }
4247 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4248 // There is currently no difference in VT provisioning type.
4249 ims.setVtProvisioned(isProvisioned);
4250 break;
4251 }
4252 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4253 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4254 // change the capability of the feature instead if needed.
4255 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4256 == isProvisioned) {
4257 // No change in provisioning.
4258 return;
4259 }
4260 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4261 try {
4262 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004263 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004264 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4265 + ", Exception" + e.getMessage());
4266 }
4267 break;
4268 }
4269 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004270 throw new IllegalArgumentException("Tried to set provisioning for "
4271 + "MmTel capability '" + capability + "', which does not require "
4272 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004273 }
4274 }
4275
4276 } finally {
4277 Binder.restoreCallingIdentity(identity);
4278 }
4279 }
4280
4281 @Override
4282 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4283 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4284 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4285 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4286 }
4287 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4288 final long identity = Binder.clearCallingIdentity();
4289 try {
4290 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004291 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004292 return true;
4293 }
4294
4295 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4296 switch (capability) {
4297 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4298 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4299 return ims.isVolteProvisionedOnDevice();
4300 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4301 return ims.isWfcProvisionedOnDevice();
4302 }
4303 // This should never happen, since we are checking tech above to make sure it
4304 // is either LTE or IWLAN.
4305 throw new IllegalArgumentException("Invalid radio technology for voice "
4306 + "capability.");
4307 }
4308 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4309 // There is currently no difference in VT provisioning type.
4310 return ims.isVtProvisionedOnDevice();
4311 }
4312 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4313 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4314 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4315 }
4316 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004317 throw new IllegalArgumentException(
4318 "Tried to get provisioning for MmTel capability '" + capability
4319 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004320 }
4321 }
4322
4323 } finally {
4324 Binder.restoreCallingIdentity(identity);
4325 }
4326 }
4327
4328 @Override
4329 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4330 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4331 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4332 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4333 }
4334 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4335 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4336 return (provisionedBits & capability) > 0;
4337 }
4338
4339 @Override
4340 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4341 boolean isProvisioned) {
4342 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4343 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4344 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4345 }
4346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4347 "setProvisioningStatusForCapability");
4348 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4349 // If the current provisioning status for capability already matches isProvisioned,
4350 // do nothing.
4351 if (((provisionedBits & capability) > 0) == isProvisioned) {
4352 return;
4353 }
4354 if (isProvisioned) {
4355 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4356 } else {
4357 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4358 }
4359 }
4360
4361 /**
4362 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4363 * technology. The bitfield should mirror the bitfield defined by
4364 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4365 */
4366 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4367 String key = getMmTelProvisioningKey(subId, tech);
4368 // Default is no capabilities are provisioned.
4369 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4370 }
4371
4372 /**
4373 * Sets the MmTel capability provisioning bitfield (defined by
4374 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4375 * technology specified.
4376 *
4377 * Note: This is a synchronous command and should not be called on UI thread.
4378 */
4379 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4380 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4381 String key = getMmTelProvisioningKey(subId, tech);
4382 editor.putInt(key, newField);
4383 editor.commit();
4384 }
4385
4386 private static String getMmTelProvisioningKey(int subId, int tech) {
4387 // resulting key is provision_ims_mmtel_{subId}_{tech}
4388 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4389 }
4390
4391 /**
4392 * Query CarrierConfig to see if the specified capability requires provisioning for the
4393 * carrier associated with the subscription id.
4394 */
4395 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4396 int capability) {
4397 CarrierConfigManager configManager = new CarrierConfigManager(context);
4398 PersistableBundle c = configManager.getConfigForSubId(subId);
4399 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004400 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004401 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4402 false);
4403 boolean requireVoiceVtProvisioning = c.getBoolean(
4404 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4405
4406 // First check to make sure that the capability requires provisioning.
4407 switch (capability) {
4408 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4409 // intentional fallthrough
4410 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4411 if (requireVoiceVtProvisioning) {
4412 // Voice and Video requires provisioning
4413 return true;
4414 }
4415 break;
4416 }
4417 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4418 if (requireUtProvisioning) {
4419 // UT requires provisioning
4420 return true;
4421 }
4422 break;
4423 }
4424 }
4425 return false;
4426 }
4427
allenwtsu99c623b2020-01-03 18:24:23 +08004428 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4429 int capability) {
4430 CarrierConfigManager configManager = new CarrierConfigManager(context);
4431 PersistableBundle c = configManager.getConfigForSubId(subId);
4432
4433 boolean requireRcsProvisioning = c.getBoolean(
4434 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4435
4436 // First check to make sure that the capability requires provisioning.
4437 switch (capability) {
4438 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4439 // intentional fallthrough
4440 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4441 if (requireRcsProvisioning) {
4442 // OPTION or PRESENCE requires provisioning
4443 return true;
4444 }
4445 break;
4446 }
4447 }
4448 return false;
4449 }
4450
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004451 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004452 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004453 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4454 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4455 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004456 enforceReadPrivilegedPermission("getImsProvisioningInt");
4457 final long identity = Binder.clearCallingIdentity();
4458 try {
4459 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004460 int slotId = getSlotIndex(subId);
4461 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4462 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4463 + subId + "' for key:" + key);
4464 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4465 }
4466 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004467 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004468 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4469 + subId + "' for key:" + key);
4470 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004471 } finally {
4472 Binder.restoreCallingIdentity(identity);
4473 }
4474 }
4475
4476 @Override
4477 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004478 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4479 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4480 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004481 enforceReadPrivilegedPermission("getImsProvisioningString");
4482 final long identity = Binder.clearCallingIdentity();
4483 try {
4484 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004485 int slotId = getSlotIndex(subId);
4486 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4487 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4488 + subId + "' for key:" + key);
4489 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4490 }
4491 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004492 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004493 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4494 + subId + "' for key:" + key);
4495 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004496 } finally {
4497 Binder.restoreCallingIdentity(identity);
4498 }
4499 }
4500
4501 @Override
4502 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004503 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4504 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4505 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004506 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4507 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004508 final long identity = Binder.clearCallingIdentity();
4509 try {
4510 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004511 int slotId = getSlotIndex(subId);
4512 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4513 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4514 + subId + "' for key:" + key);
4515 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4516 }
4517 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004518 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004519 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4520 + "' for key:" + key);
4521 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004522 } finally {
4523 Binder.restoreCallingIdentity(identity);
4524 }
4525 }
4526
4527 @Override
4528 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004529 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4530 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4531 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004532 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4533 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004534 final long identity = Binder.clearCallingIdentity();
4535 try {
4536 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004537 int slotId = getSlotIndex(subId);
4538 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4539 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4540 + subId + "' for key:" + key);
4541 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4542 }
4543 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004544 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004545 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4546 + "' for key:" + key);
4547 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004548 } finally {
4549 Binder.restoreCallingIdentity(identity);
4550 }
4551 }
4552
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004553 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004554 int slotId = SubscriptionManager.getSlotIndex(subId);
4555 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004556 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4557 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004558 }
4559 return slotId;
4560 }
4561
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004562 private int getSlotIndex(int subId) {
4563 int slotId = SubscriptionManager.getSlotIndex(subId);
4564 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4565 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4566 }
4567 return slotId;
4568 }
4569
Wink Saville36469e72014-06-11 15:17:00 -07004570 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004571 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004572 */
4573 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004574 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4575 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004576 final int targetSdk = getTargetSdk(callingPackage);
4577 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004578 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004579 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004580 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004581 mApp, subId, callingPackage, callingFeatureId,
4582 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004583 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4584 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004585
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004586 final long identity = Binder.clearCallingIdentity();
4587 try {
4588 final Phone phone = getPhone(subId);
4589 if (phone != null) {
4590 return phone.getServiceState().getDataNetworkType();
4591 } else {
4592 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4593 }
4594 } finally {
4595 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004596 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004597 }
4598
4599 /**
4600 * Returns the data network type
4601 */
4602 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004603 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4604 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4605 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004606 }
4607
4608 /**
4609 * Returns the data network type for a subId
4610 */
4611 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004612 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4613 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004614 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004615 mApp, subId, callingPackage, callingFeatureId,
4616 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004617 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4618 }
4619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004620 final long identity = Binder.clearCallingIdentity();
4621 try {
4622 final Phone phone = getPhone(subId);
4623 if (phone != null) {
4624 return phone.getServiceState().getDataNetworkType();
4625 } else {
4626 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4627 }
4628 } finally {
4629 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004631 }
4632
4633 /**
Wink Saville36469e72014-06-11 15:17:00 -07004634 * Returns the Voice network type for a subId
4635 */
4636 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004637 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4638 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004639 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004640 mApp, subId, callingPackage, callingFeatureId,
4641 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004642 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4643 }
4644
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004645 final long identity = Binder.clearCallingIdentity();
4646 try {
4647 final Phone phone = getPhone(subId);
4648 if (phone != null) {
4649 return phone.getServiceState().getVoiceNetworkType();
4650 } else {
4651 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4652 }
4653 } finally {
4654 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004655 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004656 }
4657
4658 /**
4659 * @return true if a ICC card is present
4660 */
4661 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004662 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004663 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4664 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004665 }
4666
4667 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004668 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004669 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004670 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004671 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004672 final long identity = Binder.clearCallingIdentity();
4673 try {
4674 final Phone phone = PhoneFactory.getPhone(slotIndex);
4675 if (phone != null) {
4676 return phone.getIccCard().hasIccCard();
4677 } else {
4678 return false;
4679 }
4680 } finally {
4681 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004682 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004683 }
4684
4685 /**
4686 * Return if the current radio is LTE on CDMA. This
4687 * is a tri-state return value as for a period of time
4688 * the mode may be unknown.
4689 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004690 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004691 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004692 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004693 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004694 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004695 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4696 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4697 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004698 }
4699
Sanket Padawe356d7632015-06-22 14:03:32 -07004700 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004701 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4702 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004703 try {
4704 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4705 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004706 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4707 }
4708
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004709 final long identity = Binder.clearCallingIdentity();
4710 try {
4711 final Phone phone = getPhone(subId);
4712 if (phone == null) {
4713 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4714 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004715 return TelephonyProperties.lte_on_cdma_device()
4716 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004717 }
4718 } finally {
4719 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004720 }
Wink Saville36469e72014-06-11 15:17:00 -07004721 }
4722
Wink Saville36469e72014-06-11 15:17:00 -07004723 /**
4724 * {@hide}
4725 * Returns Default subId, 0 in the case of single standby.
4726 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004727 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004728 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004729 }
4730
Shishir Agrawala9f32182016-04-12 12:00:16 -07004731 private int getSlotForDefaultSubscription() {
4732 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4733 }
4734
Wink Savilleb564aae2014-10-23 10:18:09 -07004735 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004736 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004737 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004738
Pengquan Menge92a50d2018-09-21 15:54:48 -07004739 private boolean isActiveSubscription(int subId) {
4740 return mSubscriptionController.isActiveSubId(subId);
4741 }
4742
Ihab Awadf2177b72013-11-25 13:33:23 -08004743 /**
4744 * @see android.telephony.TelephonyManager.WifiCallingChoices
4745 */
4746 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004747 final long identity = Binder.clearCallingIdentity();
4748 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004749 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004750 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4751 getWhenToMakeWifiCallsDefaultPreference());
4752 } finally {
4753 Binder.restoreCallingIdentity(identity);
4754 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004755 }
4756
4757 /**
4758 * @see android.telephony.TelephonyManager.WifiCallingChoices
4759 */
4760 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004761 final long identity = Binder.clearCallingIdentity();
4762 try {
4763 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004764 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004765 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4766 } finally {
4767 Binder.restoreCallingIdentity(identity);
4768 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004769 }
4770
Sailesh Nepald1e68152013-12-12 19:08:02 -08004771 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004772 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004773 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004774 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004775
Jordan Liu4c733742019-02-28 12:03:40 -08004776 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4777 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4778 if (phoneId == -1) {
4779 throw new IllegalArgumentException("Given slot index: " + slotIndex
4780 + " does not correspond to an active phone");
4781 }
4782 return PhoneFactory.getPhone(phoneId);
4783 }
4784
Shishir Agrawal566b7612013-10-28 14:41:00 -07004785 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004786 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4787 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4789 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004790 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004791 if (DBG) {
4792 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4793 }
4794 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4795 p2);
4796 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004797
Jordan Liu4c733742019-02-28 12:03:40 -08004798
4799 @Override
4800 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4801 int slotIndex, String callingPackage, String aid, int p2) {
4802 enforceModifyPermission();
4803 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4804 if (DBG) {
4805 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4806 }
4807 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4808 callingPackage, aid, p2);
4809 }
4810
4811 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4812 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004813 final long identity = Binder.clearCallingIdentity();
4814 try {
4815 if (TextUtils.equals(ISDR_AID, aid)) {
4816 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004817 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4818 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004819 if (bestComponent == null
4820 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4821 loge("The calling package is not allowed to access ISD-R.");
4822 throw new SecurityException(
4823 "The calling package is not allowed to access ISD-R.");
4824 }
Derek Tan740e1672017-06-27 14:56:27 -07004825 }
Derek Tan740e1672017-06-27 14:56:27 -07004826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004827 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004828 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4829 null /* workSource */);
4830 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004831 return response;
4832 } finally {
4833 Binder.restoreCallingIdentity(identity);
4834 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004835 }
4836
4837 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004838 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4840 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004841 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4842 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4843 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004844
Jordan Liu4c733742019-02-28 12:03:40 -08004845 @Override
4846 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4847 enforceModifyPermission();
4848 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4849 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4850 channel);
4851 }
4852
4853 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004854 final long identity = Binder.clearCallingIdentity();
4855 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004856 if (channel < 0) {
4857 return false;
4858 }
Jordan Liu4c733742019-02-28 12:03:40 -08004859 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4860 null /* workSource */);
4861 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004862 return success;
4863 } finally {
4864 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004865 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004866 }
4867
4868 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004869 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004870 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4872 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004873 if (DBG) {
4874 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4875 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4876 + p3 + " data=" + data);
4877 }
4878 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4879 command, p1, p2, p3, data);
4880 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004881
Jordan Liu4c733742019-02-28 12:03:40 -08004882 @Override
4883 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4884 int command, int p1, int p2, int p3, String data) {
4885 enforceModifyPermission();
4886 if (DBG) {
4887 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4888 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4889 + p3 + " data=" + data);
4890 }
4891 return iccTransmitApduLogicalChannelWithPermission(
4892 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4893 data);
4894 }
4895
4896 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4897 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004898 final long identity = Binder.clearCallingIdentity();
4899 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004900 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004901 return "";
4902 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004903
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004904 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004905 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4906 null /* workSource */);
4907 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004908
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004909 // Append the returned status code to the end of the response payload.
4910 String s = Integer.toHexString(
4911 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4912 if (response.payload != null) {
4913 s = IccUtils.bytesToHexString(response.payload) + s;
4914 }
4915 return s;
4916 } finally {
4917 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004918 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004919 }
Jake Hambye994d462014-02-03 13:10:13 -08004920
Evan Charltonc66da362014-05-16 14:06:40 -07004921 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004922 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4923 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004924 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4925 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004926 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004927 if (DBG) {
4928 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4929 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4930 }
4931 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4932 cla, command, p1, p2, p3, data);
4933 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004934
Jordan Liu4c733742019-02-28 12:03:40 -08004935 @Override
4936 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4937 int command, int p1, int p2, int p3, String data) {
4938 enforceModifyPermission();
4939 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4940 if (DBG) {
4941 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4942 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4943 + " data=" + data);
4944 }
4945
4946 return iccTransmitApduBasicChannelWithPermission(
4947 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4948 p2, p3, data);
4949 }
4950
4951 // open APDU basic channel assuming the caller has sufficient permissions
4952 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4953 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004954 final long identity = Binder.clearCallingIdentity();
4955 try {
4956 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4957 && TextUtils.equals(ISDR_AID, data)) {
4958 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004959 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4960 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004961 if (bestComponent == null
4962 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4963 loge("The calling package is not allowed to select ISD-R.");
4964 throw new SecurityException(
4965 "The calling package is not allowed to select ISD-R.");
4966 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004967 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004969 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004970 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4971 null /* workSource */);
4972 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004973
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974 // Append the returned status code to the end of the response payload.
4975 String s = Integer.toHexString(
4976 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4977 if (response.payload != null) {
4978 s = IccUtils.bytesToHexString(response.payload) + s;
4979 }
4980 return s;
4981 } finally {
4982 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004983 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004984 }
4985
4986 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004987 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004988 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004989 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4990 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004991
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004992 final long identity = Binder.clearCallingIdentity();
4993 try {
4994 if (DBG) {
4995 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4996 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4997 }
4998
4999 IccIoResult response =
5000 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5001 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5002 subId);
5003
5004 if (DBG) {
5005 log("Exchange SIM_IO [R]" + response);
5006 }
5007
5008 byte[] result = null;
5009 int length = 2;
5010 if (response.payload != null) {
5011 length = 2 + response.payload.length;
5012 result = new byte[length];
5013 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5014 } else {
5015 result = new byte[length];
5016 }
5017
5018 result[length - 1] = (byte) response.sw2;
5019 result[length - 2] = (byte) response.sw1;
5020 return result;
5021 } finally {
5022 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005023 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005024 }
5025
Nathan Haroldb3014052017-01-25 15:57:32 -08005026 /**
5027 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5028 * on a particular subscription
5029 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005030 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5031 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005032 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005033 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005034 return null;
5035 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005036
5037 final long identity = Binder.clearCallingIdentity();
5038 try {
5039 if (appType != TelephonyManager.APPTYPE_USIM
5040 && appType != TelephonyManager.APPTYPE_SIM) {
5041 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5042 return null;
5043 }
5044 Object response = sendRequest(
5045 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5046 if (response instanceof String[]) {
5047 return (String[]) response;
5048 }
yincheng zhao2737e882019-09-06 17:06:54 -07005049 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005050 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005051 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052 } finally {
5053 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005054 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005055 }
5056
yincheng zhao2737e882019-09-06 17:06:54 -07005057 /**
5058 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5059 * subscription.
5060 *
5061 * @param subId the id of the subscription.
5062 * @param appType the uicc app type, must be USIM or SIM.
5063 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5064 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005065 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005066 * @return number of fplmns that is successfully written to the SIM.
5067 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005068 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5069 String callingFeatureId) {
5070 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5071 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005072 if (DBG) logv("no permissions for setForbiddenplmns");
5073 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5074 }
5075 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5076 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5077 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5078 }
5079 if (fplmns == null) {
5080 throw new IllegalArgumentException("Fplmn List provided is null");
5081 }
5082 for (String fplmn : fplmns) {
5083 if (!CellIdentity.isValidPlmn(fplmn)) {
5084 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5085 }
5086 }
5087 final long identity = Binder.clearCallingIdentity();
5088 try {
5089 Object response = sendRequest(
5090 CMD_SET_FORBIDDEN_PLMNS,
5091 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5092 subId);
5093 return (int) response;
5094 } finally {
5095 Binder.restoreCallingIdentity(identity);
5096 }
5097 }
5098
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005099 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005100 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5102 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005103
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005104 final long identity = Binder.clearCallingIdentity();
5105 try {
5106 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5107 if (response.payload == null) {
5108 return "";
5109 }
Evan Charltonc66da362014-05-16 14:06:40 -07005110
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005111 // Append the returned status code to the end of the response payload.
5112 String s = Integer.toHexString(
5113 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5114 s = IccUtils.bytesToHexString(response.payload) + s;
5115 return s;
5116 } finally {
5117 Binder.restoreCallingIdentity(identity);
5118 }
Evan Charltonc66da362014-05-16 14:06:40 -07005119 }
5120
Jake Hambye994d462014-02-03 13:10:13 -08005121 /**
5122 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5123 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5124 *
5125 * @param itemID the ID of the item to read
5126 * @return the NV item as a String, or null on error.
5127 */
5128 @Override
5129 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005130 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005131 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5132 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133
5134 final long identity = Binder.clearCallingIdentity();
5135 try {
5136 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005137 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005138 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5139 return value;
5140 } finally {
5141 Binder.restoreCallingIdentity(identity);
5142 }
Jake Hambye994d462014-02-03 13:10:13 -08005143 }
5144
5145 /**
5146 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5147 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5148 *
5149 * @param itemID the ID of the item to read
5150 * @param itemValue the value to write, as a String
5151 * @return true on success; false on any failure
5152 */
5153 @Override
5154 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005155 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5157 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158
5159 final long identity = Binder.clearCallingIdentity();
5160 try {
5161 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5162 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005163 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005164 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5165 return success;
5166 } finally {
5167 Binder.restoreCallingIdentity(identity);
5168 }
Jake Hambye994d462014-02-03 13:10:13 -08005169 }
5170
5171 /**
5172 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5173 * Used for device configuration by some CDMA operators.
5174 *
5175 * @param preferredRoamingList byte array containing the new PRL
5176 * @return true on success; false on any failure
5177 */
5178 @Override
5179 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5181 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005182
5183 final long identity = Binder.clearCallingIdentity();
5184 try {
5185 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5186 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5187 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5188 return success;
5189 } finally {
5190 Binder.restoreCallingIdentity(identity);
5191 }
Jake Hambye994d462014-02-03 13:10:13 -08005192 }
5193
5194 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005195 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005196 * Used for device configuration by some CDMA operators.
5197 *
chen xu6dac5ab2018-10-26 17:39:23 -07005198 * @param slotIndex - device slot.
5199 *
Jake Hambye994d462014-02-03 13:10:13 -08005200 * @return true on success; false on any failure
5201 */
5202 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005203 public boolean resetModemConfig(int slotIndex) {
5204 Phone phone = PhoneFactory.getPhone(slotIndex);
5205 if (phone != null) {
5206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5207 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208
chen xu6dac5ab2018-10-26 17:39:23 -07005209 final long identity = Binder.clearCallingIdentity();
5210 try {
5211 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5212 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5213 return success;
5214 } finally {
5215 Binder.restoreCallingIdentity(identity);
5216 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005217 }
chen xu6dac5ab2018-10-26 17:39:23 -07005218 return false;
5219 }
5220
5221 /**
5222 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5223 *
5224 * @param slotIndex - device slot.
5225 *
5226 * @return true on success; false on any failure
5227 */
5228 @Override
5229 public boolean rebootModem(int slotIndex) {
5230 Phone phone = PhoneFactory.getPhone(slotIndex);
5231 if (phone != null) {
5232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5233 mApp, phone.getSubId(), "rebootModem");
5234
5235 final long identity = Binder.clearCallingIdentity();
5236 try {
5237 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5238 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5239 return success;
5240 } finally {
5241 Binder.restoreCallingIdentity(identity);
5242 }
5243 }
5244 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005245 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005246
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005247 public String[] getPcscfAddress(String apnType, String callingPackage,
5248 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005249 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005250 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5251 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005252 return new String[0];
5253 }
5254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005255 final long identity = Binder.clearCallingIdentity();
5256 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005257 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005258 } finally {
5259 Binder.restoreCallingIdentity(identity);
5260 }
Wink Saville36469e72014-06-11 15:17:00 -07005261 }
5262
Brad Ebinger51f743a2017-01-23 13:50:20 -08005263 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005264 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5265 * {@link #disableIms(int)}.
5266 * @param slotIndex device slot.
5267 */
5268 public void resetIms(int slotIndex) {
5269 enforceModifyPermission();
5270
5271 final long identity = Binder.clearCallingIdentity();
5272 try {
5273 if (mImsResolver == null) {
5274 // may happen if the does not support IMS.
5275 return;
5276 }
5277 mImsResolver.disableIms(slotIndex);
5278 mImsResolver.enableIms(slotIndex);
5279 } finally {
5280 Binder.restoreCallingIdentity(identity);
5281 }
5282 }
5283
5284 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005285 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5286 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005287 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005288 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005289 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290
5291 final long identity = Binder.clearCallingIdentity();
5292 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005293 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005294 // may happen if the device does not support IMS.
5295 return;
5296 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005297 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 } finally {
5299 Binder.restoreCallingIdentity(identity);
5300 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005301 }
5302
5303 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005304 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5305 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005306 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005307 public void disableIms(int slotId) {
5308 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005309
5310 final long identity = Binder.clearCallingIdentity();
5311 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005312 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005313 // may happen if the device does not support IMS.
5314 return;
5315 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005316 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005317 } finally {
5318 Binder.restoreCallingIdentity(identity);
5319 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005320 }
5321
5322 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005323 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5324 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005325 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005326 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005327 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005328 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005329
5330 final long identity = Binder.clearCallingIdentity();
5331 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005332 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005333 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5334 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005335 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005336 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005337 } finally {
5338 Binder.restoreCallingIdentity(identity);
5339 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005340 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005341 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005342 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5343 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005344 @Override
5345 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005346 enforceModifyPermission();
5347
5348 final long identity = Binder.clearCallingIdentity();
5349 try {
5350 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005351 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005352 } finally {
5353 Binder.restoreCallingIdentity(identity);
5354 }
5355 }
5356
5357 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005358 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005359 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005360 */
5361 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5362 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005363
5364 final long identity = Binder.clearCallingIdentity();
5365 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005366 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005367 // may happen if the device does not support IMS.
5368 return null;
5369 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005370 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005371 } finally {
5372 Binder.restoreCallingIdentity(identity);
5373 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005374 }
5375
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005376 /**
5377 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005378 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005379 */
5380 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5381 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005382
5383 final long identity = Binder.clearCallingIdentity();
5384 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005385 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005386 // may happen if the device does not support IMS.
5387 return null;
5388 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005389 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005390 } finally {
5391 Binder.restoreCallingIdentity(identity);
5392 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005393 }
5394
Brad Ebinger884c07b2018-02-15 16:17:40 -08005395 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005396 * Sets the ImsService Package Name that Telephony will bind to.
5397 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005398 * @param slotIndex the slot ID that the ImsService should bind for.
5399 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005400 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005401 * @param featureTypes An integer array of feature types associated with a packageName.
5402 * @param packageName The name of the package that the current configuration will be replaced
5403 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005404 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005405 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005406 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5407 int[] featureTypes, String packageName) {
5408 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5409 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5411 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005412 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005413
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005414 final long identity = Binder.clearCallingIdentity();
5415 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005416 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005417 // may happen if the device does not support IMS.
5418 return false;
5419 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005420 Map<Integer, String> featureConfig = new HashMap<>();
5421 for (int featureType : featureTypes) {
5422 featureConfig.put(featureType, packageName);
5423 }
5424 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5425 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426 } finally {
5427 Binder.restoreCallingIdentity(identity);
5428 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005429 }
5430
5431 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005432 * Clears any carrier ImsService overrides for the slot index specified that were previously
5433 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5434 *
5435 * This should only be used for testing.
5436 *
5437 * @param slotIndex the slot ID that the ImsService should bind for.
5438 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5439 */
5440 @Override
5441 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5442 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5443 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5444 "clearCarrierImsServiceOverride");
5445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5446 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5447 "clearCarrierImsServiceOverride");
5448
5449 final long identity = Binder.clearCallingIdentity();
5450 try {
5451 if (mImsResolver == null) {
5452 // may happen if the device does not support IMS.
5453 return false;
5454 }
5455 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5456 } finally {
5457 Binder.restoreCallingIdentity(identity);
5458 }
5459 }
5460
5461 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005462 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005463 *
5464 * @param slotId The slot that the ImsService is associated with.
5465 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5466 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005467 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005468 * @return the package name of the ImsService configuration.
5469 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005470 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5471 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005472 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005473 TelephonyPermissions
5474 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5475 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5476 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005478 final long identity = Binder.clearCallingIdentity();
5479 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005480 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005481 // may happen if the device does not support IMS.
5482 return "";
5483 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005484 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005485 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5486 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005487 } finally {
5488 Binder.restoreCallingIdentity(identity);
5489 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005490 }
5491
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005492 /**
5493 * Get the MmTelFeature state associated with the requested subscription id.
5494 * @param subId The subscription that the MmTelFeature is associated with.
5495 * @param callback A callback with an integer containing the
5496 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5497 */
5498 @Override
5499 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5500 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5501 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5502 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5503 "IMS not available on device.");
5504 }
5505 final long token = Binder.clearCallingIdentity();
5506 try {
5507 int slotId = getSlotIndex(subId);
5508 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5509 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5510 + subId + "'");
5511 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5512 }
5513 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5514 try {
5515 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5516 } catch (RemoteException e) {
5517 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5518 + "Ignore");
5519 }
5520 });
5521 } finally {
5522 Binder.restoreCallingIdentity(token);
5523 }
5524 }
5525
Wink Saville36469e72014-06-11 15:17:00 -07005526 public void setImsRegistrationState(boolean registered) {
5527 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528
5529 final long identity = Binder.clearCallingIdentity();
5530 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005531 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005532 } finally {
5533 Binder.restoreCallingIdentity(identity);
5534 }
Wink Saville36469e72014-06-11 15:17:00 -07005535 }
5536
5537 /**
Stuart Scott54788802015-03-30 13:18:01 -07005538 * Set the network selection mode to automatic.
5539 *
5540 */
5541 @Override
5542 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005543 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5544 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005545
5546 final long identity = Binder.clearCallingIdentity();
5547 try {
shilufc958392020-01-20 11:36:01 -08005548 if (!isActiveSubscription(subId)) {
5549 return;
5550 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005551 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5552 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5553 } finally {
5554 Binder.restoreCallingIdentity(identity);
5555 }
Stuart Scott54788802015-03-30 13:18:01 -07005556 }
5557
Jack Yud10cdd42020-09-28 20:28:01 -07005558 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005559 * Ask the radio to connect to the input network and change selection mode to manual.
5560 *
5561 * @param subId the id of the subscription.
5562 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5563 * the operator to attach to.
5564 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5565 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5566 * normal network selection next time.
5567 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005568 */
5569 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005570 public boolean setNetworkSelectionModeManual(
5571 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5573 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005574
5575 if (!isActiveSubscription(subId)) {
5576 return false;
5577 }
5578
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579 final long identity = Binder.clearCallingIdentity();
5580 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005581 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005583 if (DBG) {
5584 log("setNetworkSelectionModeManual: subId: " + subId
5585 + " operator: " + operatorInfo);
5586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5588 } finally {
5589 Binder.restoreCallingIdentity(identity);
5590 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005591 }
shilu84f6e8b2019-12-19 13:58:01 -08005592 /**
5593 * Get the manual network selection
5594 *
5595 * @param subId the id of the subscription.
5596 *
5597 * @return the previously saved user selected PLMN
5598 */
5599 @Override
5600 public String getManualNetworkSelectionPlmn(int subId) {
5601 TelephonyPermissions
5602 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5603 mApp, subId, "getManualNetworkSelectionPlmn");
5604
5605 final long identity = Binder.clearCallingIdentity();
5606 try {
5607 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005608 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005609 }
5610
5611 final Phone phone = getPhone(subId);
5612 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005613 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005614 }
5615 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5616 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5617 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5618 } finally {
5619 Binder.restoreCallingIdentity(identity);
5620 }
5621 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005622
5623 /**
5624 * Scans for available networks.
5625 */
5626 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005627 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5628 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5630 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005631 LocationAccessPolicy.LocationPermissionResult locationResult =
5632 LocationAccessPolicy.checkLocationPermission(mApp,
5633 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5634 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005635 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005636 .setCallingPid(Binder.getCallingPid())
5637 .setCallingUid(Binder.getCallingUid())
5638 .setMethod("getCellNetworkScanResults")
5639 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005640 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5641 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005642 .build());
5643 switch (locationResult) {
5644 case DENIED_HARD:
5645 throw new SecurityException("Not allowed to access scan results -- location");
5646 case DENIED_SOFT:
5647 return null;
5648 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005649
Pengquan Menga1bb6272018-09-06 09:59:22 -07005650 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005651 try {
5652 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005653 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005654 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655 } finally {
5656 Binder.restoreCallingIdentity(identity);
5657 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005658 }
5659
5660 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005661 * Get the call forwarding info, given the call forwarding reason.
5662 */
5663 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005664 public void getCallForwarding(int subId, int callForwardingReason,
5665 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005666 enforceReadPrivilegedPermission("getCallForwarding");
5667 long identity = Binder.clearCallingIdentity();
5668 try {
5669 if (DBG) {
5670 log("getCallForwarding: subId " + subId
5671 + " callForwardingReason" + callForwardingReason);
5672 }
Hall Liu27d24262020-09-18 19:04:59 -07005673
5674 Phone phone = getPhone(subId);
5675 if (phone == null) {
5676 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005677 callback.onError(
5678 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005679 } catch (RemoteException e) {
5680 // ignore
5681 }
5682 return;
5683 }
5684
5685 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5686 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5687 @Override
5688 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5689 try {
5690 callback.onCallForwardingInfoAvailable(info);
5691 } catch (RemoteException e) {
5692 // ignore
5693 }
5694 }
5695
5696 @Override
5697 public void onError(int error) {
5698 try {
5699 callback.onError(error);
5700 } catch (RemoteException e) {
5701 // ignore
5702 }
5703 }
5704 });
5705 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005706 } finally {
5707 Binder.restoreCallingIdentity(identity);
5708 }
5709 }
5710
5711 /**
5712 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5713 * reason, the number to forward, and the timeout before the forwarding is attempted.
5714 */
5715 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005716 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5717 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005718 enforceModifyPermission();
5719 long identity = Binder.clearCallingIdentity();
5720 try {
5721 if (DBG) {
5722 log("setCallForwarding: subId " + subId
5723 + " callForwardingInfo" + callForwardingInfo);
5724 }
Hall Liu27d24262020-09-18 19:04:59 -07005725
5726 Phone phone = getPhone(subId);
5727 if (phone == null) {
5728 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005729 callback.accept(
5730 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005731 } catch (RemoteException e) {
5732 // ignore
5733 }
5734 return;
5735 }
5736
5737 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5738 FunctionalUtils.ignoreRemoteException(callback::accept));
5739
5740 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005741 } finally {
5742 Binder.restoreCallingIdentity(identity);
5743 }
5744 }
5745
5746 /**
Hall Liu27d24262020-09-18 19:04:59 -07005747 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005748 */
5749 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005750 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005751 enforceReadPrivilegedPermission("getCallForwarding");
5752 long identity = Binder.clearCallingIdentity();
5753 try {
Hall Liu27d24262020-09-18 19:04:59 -07005754
5755 Phone phone = getPhone(subId);
5756 if (phone == null) {
5757 try {
5758 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5759 } catch (RemoteException e) {
5760 // ignore
5761 }
5762 return;
5763 }
5764
5765 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5766
Shuo Qian4a594052020-01-23 11:59:30 -08005767 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005768 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005769 } finally {
5770 Binder.restoreCallingIdentity(identity);
5771 }
5772 }
5773
5774 /**
Hall Liu27d24262020-09-18 19:04:59 -07005775 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005776 */
5777 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005778 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005779 enforceModifyPermission();
5780 long identity = Binder.clearCallingIdentity();
5781 try {
Hall Liu27d24262020-09-18 19:04:59 -07005782 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5783
5784 Phone phone = getPhone(subId);
5785 if (phone == null) {
5786 try {
5787 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5788 } catch (RemoteException e) {
5789 // ignore
5790 }
5791 return;
5792 }
5793
5794 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5795 FunctionalUtils.ignoreRemoteException(callback::accept));
5796
5797 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005798 } finally {
5799 Binder.restoreCallingIdentity(identity);
5800 }
5801 }
5802
5803 /**
yinxub1bed742017-04-17 11:45:04 -07005804 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005805 *
yinxub1bed742017-04-17 11:45:04 -07005806 * @param subId id of the subscription
5807 * @param request contains the radio access networks with bands/channels to scan
5808 * @param messenger callback messenger for scan results or errors
5809 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005810 * @return the id of the requested scan which can be used to stop the scan.
5811 */
5812 @Override
5813 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005814 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5816 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005817 LocationAccessPolicy.LocationPermissionResult locationResult =
5818 LocationAccessPolicy.checkLocationPermission(mApp,
5819 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5820 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005821 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005822 .setCallingPid(Binder.getCallingPid())
5823 .setCallingUid(Binder.getCallingUid())
5824 .setMethod("requestNetworkScan")
5825 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005826 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5827 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005828 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005829 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005830 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5831 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005832 if (e != null) {
5833 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5834 throw e;
5835 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005836 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005837 return TelephonyScanManager.INVALID_SCAN_ID;
5838 }
5839 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005840 }
Hall Liu912dfd32019-04-25 14:02:26 -07005841 int callingUid = Binder.getCallingUid();
5842 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005843 final long identity = Binder.clearCallingIdentity();
5844 try {
5845 return mNetworkScanRequestTracker.startNetworkScan(
5846 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005847 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005848 } finally {
5849 Binder.restoreCallingIdentity(identity);
5850 }
yinxu504e1392017-04-12 16:03:22 -07005851 }
5852
Hall Liub2ac8ef2019-02-28 15:56:23 -08005853 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005854 NetworkScanRequest request, int subId, String callingPackage) {
5855 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005856 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5857 boolean hasNetworkScanPermission =
5858 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5859 == PERMISSION_GRANTED;
5860
5861 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5862 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5863 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005864 }
5865
5866 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5867 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005868 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5869 return new SecurityException("Specific channels must not be"
5870 + " scanned without location access.");
5871 }
5872 }
5873 }
5874
Hall Liub2ac8ef2019-02-28 15:56:23 -08005875 return null;
5876 }
5877
yinxu504e1392017-04-12 16:03:22 -07005878 /**
5879 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005880 *
5881 * @param subId id of the subscription
5882 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005883 */
5884 @Override
5885 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5887 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005888
Hall Liu912dfd32019-04-25 14:02:26 -07005889 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005890 final long identity = Binder.clearCallingIdentity();
5891 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005892 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893 } finally {
5894 Binder.restoreCallingIdentity(identity);
5895 }
yinxu504e1392017-04-12 16:03:22 -07005896 }
5897
5898 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005899 * Get the calculated preferred network type.
5900 * Used for debugging incorrect network type.
5901 *
5902 * @return the preferred network type, defined in RILConstants.java.
5903 */
5904 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005905 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005906 final Phone defaultPhone = getDefaultPhone();
5907 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005908 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005909 return RILConstants.PREFERRED_NETWORK_MODE;
5910 }
5911
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005912 final long identity = Binder.clearCallingIdentity();
5913 try {
5914 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005915 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005916 } finally {
5917 Binder.restoreCallingIdentity(identity);
5918 }
Junda Liu84d15a22014-07-02 11:21:04 -07005919 }
5920
5921 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005922 * Get the preferred network type.
5923 * Used for device configuration by some CDMA operators.
5924 *
5925 * @return the preferred network type, defined in RILConstants.java.
5926 */
5927 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005928 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005929 TelephonyPermissions
5930 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5931 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005932
5933 final long identity = Binder.clearCallingIdentity();
5934 try {
5935 if (DBG) log("getPreferredNetworkType");
5936 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5937 int networkType = (result != null ? result[0] : -1);
5938 if (DBG) log("getPreferredNetworkType: " + networkType);
5939 return networkType;
5940 } finally {
5941 Binder.restoreCallingIdentity(identity);
5942 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005943 }
5944
5945 /**
5946 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005947 *
5948 * @param networkType the preferred network type, defined in RILConstants.java.
5949 * @return true on success; false on any failure.
5950 */
5951 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005952 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5954 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005955
5956 final long identity = Binder.clearCallingIdentity();
5957 try {
calvinpan8ed33732020-03-12 14:17:55 +08005958 Boolean success = (Boolean) sendRequest(
5959 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005960
5961 if (success) {
5962 Settings.Global.putInt(mApp.getContentResolver(),
5963 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5964 }
calvinpan8ed33732020-03-12 14:17:55 +08005965 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5966 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005967 } finally {
5968 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005969 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005970 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005971
5972 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005973 * Get the allowed network types that store in the telephony provider.
5974 *
5975 * @param subId the id of the subscription.
5976 * @return allowedNetworkTypes the allowed network types.
5977 */
5978 @Override
5979 public long getAllowedNetworkTypes(int subId) {
5980 TelephonyPermissions
5981 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5982 mApp, subId, "getAllowedNetworkTypes");
5983
5984 final long identity = Binder.clearCallingIdentity();
5985 try {
5986 return SubscriptionManager.getLongSubscriptionProperty(
5987 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5988 } finally {
5989 Binder.restoreCallingIdentity(identity);
5990 }
5991 }
5992
5993 /**
5994 * Set the allowed network types.
5995 *
5996 * @param subId the id of the subscription.
5997 * @param allowedNetworkTypes the allowed network types.
5998 * @return true on success; false on any failure.
5999 */
6000 @Override
6001 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
6002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6003 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08006004
calvinpan8ed33732020-03-12 14:17:55 +08006005 SubscriptionManager.setSubscriptionProperty(subId,
6006 SubscriptionManager.ALLOWED_NETWORK_TYPES,
6007 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08006008
calvinpan8ed33732020-03-12 14:17:55 +08006009 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6010 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6011 RILConstants.PREFERRED_NETWORK_MODE);
6012 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08006013 }
6014
6015 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006016 * Get the allowed network types for certain reason.
6017 *
6018 * @param subId the id of the subscription.
6019 * @param reason the reason the allowed network type change is taking place
6020 * @return the allowed network types.
6021 */
6022 @Override
6023 public long getAllowedNetworkTypesForReason(int subId,
6024 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6025 TelephonyPermissions
6026 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6027 mApp, subId, "getAllowedNetworkTypesForReason");
6028 final long identity = Binder.clearCallingIdentity();
6029 try {
6030 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6031 } finally {
6032 Binder.restoreCallingIdentity(identity);
6033 }
6034 }
6035
6036 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006037 * Enable/Disable E-UTRA-NR Dual Connectivity
6038 * @param subId subscription id of the sim card
6039 * @param nrDualConnectivityState expected NR dual connectivity state
6040 * This can be passed following states
6041 * <ol>
6042 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6043 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6044 * <li>Disable NR dual connectivity and force secondary cell to be released
6045 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6046 * </ol>
6047 * @return operation result.
6048 */
6049 @Override
6050 public int setNrDualConnectivityState(int subId,
6051 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6052 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6053 mApp, subId, "enableNRDualConnectivity");
6054 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6055 final long identity = Binder.clearCallingIdentity();
6056 try {
6057 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6058 nrDualConnectivityState, subId,
6059 workSource);
6060 if (DBG) log("enableNRDualConnectivity result: " + result);
6061 return result;
6062 } finally {
6063 Binder.restoreCallingIdentity(identity);
6064 }
6065 }
6066
6067 /**
6068 * Is E-UTRA-NR Dual Connectivity enabled
6069 * @return true if dual connectivity is enabled else false
6070 */
6071 @Override
6072 public boolean isNrDualConnectivityEnabled(int subId) {
6073 TelephonyPermissions
6074 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6075 mApp, subId, "isNRDualConnectivityEnabled");
6076 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6077 final long identity = Binder.clearCallingIdentity();
6078 try {
6079 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6080 null, subId, workSource);
6081 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6082 return isEnabled;
6083 } finally {
6084 Binder.restoreCallingIdentity(identity);
6085 }
6086 }
6087
6088 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07006089 * get carrier bandwidth per primary and secondary carrier
6090 * @param subId subscription id of the sim card
6091 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6092 */
6093 @Override
6094 public CarrierBandwidth getCarrierBandwidth(int subId) {
6095 TelephonyPermissions
6096 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6097 mApp, subId, "isNRDualConnectivityEnabled");
6098 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6099 final long identity = Binder.clearCallingIdentity();
6100 try {
6101 CarrierBandwidth carrierBandwidth =
6102 getPhoneFromSubId(subId).getCarrierBandwidth();
6103 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6104 return carrierBandwidth;
6105 } finally {
6106 Binder.restoreCallingIdentity(identity);
6107 }
6108 }
6109
6110 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006111 * Get the effective allowed network types on the device.
6112 * This API will return an intersection of allowed network types for all reasons,
6113 * including the configuration done through setAllowedNetworkTypes
6114 *
6115 * @param subId the id of the subscription.
6116 * @return the allowed network types
6117 */
6118 @Override
6119 public long getEffectiveAllowedNetworkTypes(int subId) {
6120 TelephonyPermissions
6121 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6122 mApp, subId, "getEffectiveAllowedNetworkTypes");
6123 final long identity = Binder.clearCallingIdentity();
6124 try {
6125 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6126 } finally {
6127 Binder.restoreCallingIdentity(identity);
6128 }
6129 }
6130
6131 /**
6132 * Set the allowed network types of the device and
6133 * provide the reason triggering the allowed network change.
6134 *
6135 * @param subId the id of the subscription.
6136 * @param reason the reason the allowed network type change is taking place
6137 * @param allowedNetworkTypes the allowed network types.
6138 * @return true on success; false on any failure.
6139 */
6140 @Override
6141 public boolean setAllowedNetworkTypesForReason(int subId,
6142 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6144 mApp, subId, "setAllowedNetworkTypesForReason");
6145 final long identity = Binder.clearCallingIdentity();
6146 try {
6147 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6148 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6149 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6150 RILConstants.PREFERRED_NETWORK_MODE);
6151 return setPreferredNetworkType(subId, preferredNetworkMode);
6152 } finally {
6153 Binder.restoreCallingIdentity(identity);
6154 }
6155 }
6156
6157 /**
Miaoa84611c2019-03-15 09:21:10 +08006158 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006159 *
Miaoa84611c2019-03-15 09:21:10 +08006160 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006161 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006162 * @hide
6163 */
6164 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006165 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006166 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006167 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006168 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006169 try {
Miaoa84611c2019-03-15 09:21:10 +08006170 if (phone != null) {
6171 return phone.hasMatchedTetherApnSetting();
6172 } else {
6173 return false;
6174 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006175 } finally {
6176 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006177 }
Junda Liu475951f2014-11-07 16:45:03 -08006178 }
6179
6180 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006181 * Enable or disable always reporting signal strength changes from radio.
6182 *
6183 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6184 */
6185 @Override
6186 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6187 enforceModifyPermission();
6188 enforceSystemCaller();
6189
6190 final long identity = Binder.clearCallingIdentity();
6191 final Phone phone = getPhone(subId);
6192 try {
6193 if (phone != null) {
6194 if (DBG) {
6195 log("setAlwaysReportSignalStrength: subId=" + subId
6196 + " isEnable=" + isEnable);
6197 }
6198 phone.setAlwaysReportSignalStrength(isEnable);
6199 } else {
6200 loge("setAlwaysReportSignalStrength: no phone found for subId="
6201 + subId);
6202 }
6203 } finally {
6204 Binder.restoreCallingIdentity(identity);
6205 }
6206 }
6207
6208 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006209 * Get the user enabled state of Mobile Data.
6210 *
6211 * TODO: remove and use isUserDataEnabled.
6212 * This can't be removed now because some vendor codes
6213 * calls through ITelephony directly while they should
6214 * use TelephonyManager.
6215 *
6216 * @return true on enabled
6217 */
6218 @Override
6219 public boolean getDataEnabled(int subId) {
6220 return isUserDataEnabled(subId);
6221 }
6222
6223 /**
6224 * Get whether mobile data is enabled per user setting.
6225 *
6226 * There are other factors deciding whether mobile data is actually enabled, but they are
6227 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006228 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006229 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006230 *
6231 * @return {@code true} if data is enabled else {@code false}
6232 */
6233 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006234 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006235 try {
6236 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6237 null);
6238 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6240 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006241 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006242
6243 final long identity = Binder.clearCallingIdentity();
6244 try {
6245 int phoneId = mSubscriptionController.getPhoneId(subId);
6246 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6247 Phone phone = PhoneFactory.getPhone(phoneId);
6248 if (phone != null) {
6249 boolean retVal = phone.isUserDataEnabled();
6250 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6251 return retVal;
6252 } else {
6253 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6254 return false;
6255 }
6256 } finally {
6257 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006258 }
6259 }
6260
6261 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006262 * Checks if the device is capable of mobile data by considering whether whether the
6263 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6264 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006265 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006266 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006267 */
6268 @Override
6269 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006270 try {
6271 try {
6272 mApp.enforceCallingOrSelfPermission(
6273 android.Manifest.permission.ACCESS_NETWORK_STATE,
6274 null);
6275 } catch (Exception e) {
6276 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6277 "isDataEnabled");
6278 }
6279 } catch (Exception e) {
6280 enforceReadPrivilegedPermission("isDataEnabled");
6281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282
6283 final long identity = Binder.clearCallingIdentity();
6284 try {
6285 int phoneId = mSubscriptionController.getPhoneId(subId);
6286 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6287 Phone phone = PhoneFactory.getPhone(phoneId);
6288 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006289 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6291 return retVal;
6292 } else {
6293 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6294 return false;
6295 }
6296 } finally {
6297 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006298 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006299 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006300
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006301 /**
6302 * Check if data is enabled for a specific reason
6303 * @param subId Subscription index
6304 * @param reason the reason the data enable change is taking place
6305 * @return {@code true} if the overall data is enabled; {@code false} if not.
6306 */
6307 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006308 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006309 @TelephonyManager.DataEnabledReason int reason) {
6310 try {
6311 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6312 null);
6313 } catch (Exception e) {
6314 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006315 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006316 }
6317
6318
6319 final long identity = Binder.clearCallingIdentity();
6320 try {
6321 int phoneId = mSubscriptionController.getPhoneId(subId);
6322 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006323 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006324 + " reason=" + reason);
6325 }
6326 Phone phone = PhoneFactory.getPhone(phoneId);
6327 if (phone != null) {
6328 boolean retVal;
6329 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6330 retVal = phone.isUserDataEnabled();
6331 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006332 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006333 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006334 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006335 return retVal;
6336 } else {
6337 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006338 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006339 + subId + " retVal=false");
6340 }
6341 return false;
6342 }
6343 } finally {
6344 Binder.restoreCallingIdentity(identity);
6345 }
6346 }
6347
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006348 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006349 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006350 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6351 // Skip the check if it's one of these special uids
6352 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6353 }
6354
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006355 //load access rules from carrier configs, and check those as well: b/139133814
6356 SubscriptionController subController = SubscriptionController.getInstance();
6357 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6358 || subController == null) return privilegeFromSim;
6359
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006360 PackageManager pkgMgr = phone.getContext().getPackageManager();
6361 String[] packages = pkgMgr.getPackagesForUid(uid);
6362
6363 final long identity = Binder.clearCallingIdentity();
6364 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006365 int subId = phone.getSubId();
6366 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6367 // A test override is in place for the privileges for this subId, so don't try to
6368 // read the subscription privileges.
6369 return privilegeFromSim;
6370 }
6371 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006372 SubscriptionManager subManager = (SubscriptionManager)
6373 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6374 for (String pkg : packages) {
6375 if (subManager.canManageSubscription(subInfo, pkg)) {
6376 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6377 }
6378 }
6379 return privilegeFromSim;
6380 } finally {
6381 Binder.restoreCallingIdentity(identity);
6382 }
6383 }
6384
6385 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6386 String pkgName) {
6387 //load access rules from carrier configs, and check those as well: b/139133814
6388 SubscriptionController subController = SubscriptionController.getInstance();
6389 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6390 || subController == null) return privilegeFromSim;
6391
6392 final long identity = Binder.clearCallingIdentity();
6393 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006394 int subId = phone.getSubId();
6395 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6396 // A test override is in place for the privileges for this subId, so don't try to
6397 // read the subscription privileges.
6398 return privilegeFromSim;
6399 }
6400 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006401 SubscriptionManager subManager = (SubscriptionManager)
6402 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6403 return subManager.canManageSubscription(subInfo, pkgName)
6404 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6405 } finally {
6406 Binder.restoreCallingIdentity(identity);
6407 }
6408 }
6409
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006410 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006411 public int getCarrierPrivilegeStatus(int subId) {
6412 final Phone phone = getPhone(subId);
6413 if (phone == null) {
6414 loge("getCarrierPrivilegeStatus: Invalid subId");
6415 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6416 }
6417 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006418 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006419 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006420 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6421 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006422
6423 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6424 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006425 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006426 }
Junda Liu29340342014-07-10 15:23:27 -07006427
6428 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006429 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006430 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006431 final Phone phone = getPhone(subId);
6432 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006433 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006434 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6435 }
6436 UiccProfile profile =
6437 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6438 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006439 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006440 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6441 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006442 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006443 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006444 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006445 }
6446
6447 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006448 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6449 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006450 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006451 }
6452
6453 int phoneId = SubscriptionManager.getPhoneId(subId);
6454 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006455 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006456 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006457 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6458 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006459 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6460 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6461 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006462 }
6463
6464 @Override
6465 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006466 if (TextUtils.isEmpty(pkgName))
6467 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006468 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6469 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6470 UiccCard card = UiccController.getInstance().getUiccCard(i);
6471 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006472 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006473 continue;
6474 }
6475
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006476 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6477 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6478 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006479 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6480 break;
6481 }
6482 }
6483
6484 return result;
Junda Liu29340342014-07-10 15:23:27 -07006485 }
Derek Tan89e89d42014-07-08 17:00:10 -07006486
6487 @Override
Junda Liue64de782015-04-16 17:19:16 -07006488 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6489 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6490 loge("phoneId " + phoneId + " is not valid.");
6491 return null;
6492 }
6493 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006494 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006495 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006496 return null ;
6497 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006498 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006499 }
6500
Amith Yamasani6e118872016-02-19 12:53:51 -08006501 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006502 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006503 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006504 List<String> privilegedPackages = new ArrayList<>();
6505 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006506 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6507 // has UICC in that slot.
6508 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006509 if (card.hasCarrierPrivilegeRules()) {
6510 if (packages == null) {
6511 // Only check packages in user 0 for now
6512 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006513 PackageManager.MATCH_DISABLED_COMPONENTS
6514 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006515 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006516 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006517 }
6518 for (int p = packages.size() - 1; p >= 0; p--) {
6519 PackageInfo pkgInfo = packages.get(p);
6520 if (pkgInfo != null && pkgInfo.packageName != null
6521 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006522 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006523 privilegedPackages.add(pkgInfo.packageName);
6524 }
6525 }
6526 }
6527 }
6528 return privilegedPackages;
6529 }
6530
chen xuf7e9fe82019-05-09 19:31:02 -07006531 @Override
6532 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006533 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6534
6535 final long identity = Binder.clearCallingIdentity();
6536
chen xuf7e9fe82019-05-09 19:31:02 -07006537 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006538 try {
6539 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6540 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6541 }
6542 } finally {
6543 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006544 }
6545 return privilegedPackages;
6546 }
6547
Wink Savilleb564aae2014-10-23 10:18:09 -07006548 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006549 final Phone phone = getPhone(subId);
6550 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006551 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006552 return null;
6553 }
6554 String iccId = card.getIccId();
6555 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006556 return null;
6557 }
6558 return iccId;
6559 }
6560
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006561 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006562 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6563 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006564 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006565 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006566
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006567 final long identity = Binder.clearCallingIdentity();
6568 try {
6569 final String iccId = getIccId(subId);
6570 final Phone phone = getPhone(subId);
6571 if (phone == null) {
6572 return false;
6573 }
6574 final String subscriberId = phone.getSubscriberId();
6575
6576 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006577 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006578 + subscriberId + " to " + number);
6579 }
6580
6581 if (TextUtils.isEmpty(iccId)) {
6582 return false;
6583 }
6584
6585 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6586
6587 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6588 if (alphaTag == null) {
6589 editor.remove(alphaTagPrefKey);
6590 } else {
6591 editor.putString(alphaTagPrefKey, alphaTag);
6592 }
6593
6594 // Record both the line number and IMSI for this ICCID, since we need to
6595 // track all merged IMSIs based on line number
6596 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6597 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6598 if (number == null) {
6599 editor.remove(numberPrefKey);
6600 editor.remove(subscriberPrefKey);
6601 } else {
6602 editor.putString(numberPrefKey, number);
6603 editor.putString(subscriberPrefKey, subscriberId);
6604 }
6605
6606 editor.commit();
6607 return true;
6608 } finally {
6609 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006610 }
Derek Tan7226c842014-07-02 17:42:23 -07006611 }
6612
6613 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006614 public String getLine1NumberForDisplay(int subId, String callingPackage,
6615 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006616 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006618 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006619 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006620 return null;
6621 }
Derek Tan97ebb422014-09-05 16:55:38 -07006622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006623 final long identity = Binder.clearCallingIdentity();
6624 try {
6625 String iccId = getIccId(subId);
6626 if (iccId != null) {
6627 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6628 if (DBG_MERGE) {
6629 log("getLine1NumberForDisplay returning "
6630 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6631 }
6632 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006633 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006634 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6635 return null;
6636 } finally {
6637 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006638 }
Derek Tan7226c842014-07-02 17:42:23 -07006639 }
6640
6641 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006642 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6643 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006644 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006645 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006646 return null;
6647 }
Derek Tan97ebb422014-09-05 16:55:38 -07006648
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006649 final long identity = Binder.clearCallingIdentity();
6650 try {
6651 String iccId = getIccId(subId);
6652 if (iccId != null) {
6653 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6654 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6655 }
6656 return null;
6657 } finally {
6658 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006659 }
Derek Tan7226c842014-07-02 17:42:23 -07006660 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006661
6662 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006663 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6664 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006665 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6666 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006667 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006668 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006669 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006670 return null;
6671 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006672
Jordan Liub49b04b2019-05-06 14:45:15 -07006673 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6674 // the process, where TelephonyManager was instantiated.
6675 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006676 final long identity = Binder.clearCallingIdentity();
6677 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006678 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006679 final TelephonyManager tele = TelephonyManager.from(context);
6680 final SubscriptionManager sub = SubscriptionManager.from(context);
6681
6682 // Figure out what subscribers are currently active
6683 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006684
Jordan Liub49b04b2019-05-06 14:45:15 -07006685 // Only consider subs which match the current subId
6686 // This logic can be simplified. See b/131189269 for progress.
6687 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006688 activeSubscriberIds.add(tele.getSubscriberId(subId));
6689 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006690
6691 // First pass, find a number override for an active subscriber
6692 String mergeNumber = null;
6693 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6694 for (String key : prefs.keySet()) {
6695 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6696 final String subscriberId = (String) prefs.get(key);
6697 if (activeSubscriberIds.contains(subscriberId)) {
6698 final String iccId = key.substring(
6699 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6700 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6701 mergeNumber = (String) prefs.get(numberKey);
6702 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006703 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006704 + " for active subscriber " + subscriberId);
6705 }
6706 if (!TextUtils.isEmpty(mergeNumber)) {
6707 break;
6708 }
6709 }
6710 }
6711 }
6712
6713 // Shortcut when no active merged subscribers
6714 if (TextUtils.isEmpty(mergeNumber)) {
6715 return null;
6716 }
6717
6718 // Second pass, find all subscribers under that line override
6719 final ArraySet<String> result = new ArraySet<>();
6720 for (String key : prefs.keySet()) {
6721 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6722 final String number = (String) prefs.get(key);
6723 if (mergeNumber.equals(number)) {
6724 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6725 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6726 final String subscriberId = (String) prefs.get(subscriberKey);
6727 if (!TextUtils.isEmpty(subscriberId)) {
6728 result.add(subscriberId);
6729 }
6730 }
6731 }
6732 }
6733
6734 final String[] resultArray = result.toArray(new String[result.size()]);
6735 Arrays.sort(resultArray);
6736 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006737 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006738 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6739 }
6740 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006741 } finally {
6742 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006743 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006744 }
6745
6746 @Override
zoey chen38003472019-12-13 17:16:31 +08006747 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6748 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006749
6750 final long identity = Binder.clearCallingIdentity();
6751 try {
6752 final TelephonyManager telephonyManager = mApp.getSystemService(
6753 TelephonyManager.class);
6754 String subscriberId = telephonyManager.getSubscriberId(subId);
6755 if (subscriberId == null) {
6756 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006757 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006758 + subId);
6759 }
6760 return null;
6761 }
6762
6763 final SubscriptionInfo info = SubscriptionController.getInstance()
6764 .getSubscriptionInfo(subId);
6765 final ParcelUuid groupUuid = info.getGroupUuid();
6766 // If it doesn't belong to any group, return just subscriberId of itself.
6767 if (groupUuid == null) {
6768 return new String[]{subscriberId};
6769 }
6770
6771 // Get all subscriberIds from the group.
6772 final List<String> mergedSubscriberIds = new ArrayList<>();
6773 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006774 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006775 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006776 for (SubscriptionInfo subInfo : groupInfos) {
6777 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6778 if (subscriberId != null) {
6779 mergedSubscriberIds.add(subscriberId);
6780 }
6781 }
6782
6783 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6784 } finally {
6785 Binder.restoreCallingIdentity(identity);
6786
6787 }
6788 }
6789
6790 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006791 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006792 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006793 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006794
6795 final long identity = Binder.clearCallingIdentity();
6796 try {
6797 final Phone phone = getPhone(subId);
6798 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6799 } finally {
6800 Binder.restoreCallingIdentity(identity);
6801 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006802 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006803
6804 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006805 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006806 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6807 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006808 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6809 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006810
6811 final long identity = Binder.clearCallingIdentity();
6812 try {
6813 final Phone phone = getPhone(subId);
6814 if (phone == null) {
6815 return false;
6816 }
6817 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6818 cdmaNonRoamingList);
6819 } finally {
6820 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006821 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006822 }
6823
6824 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006825 @Deprecated
6826 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6827 enforceModifyPermission();
6828
6829 int returnValue = 0;
6830 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006831 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006832 if(result.exception == null) {
6833 if (result.result != null) {
6834 byte[] responseData = (byte[])(result.result);
6835 if(responseData.length > oemResp.length) {
6836 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6837 responseData.length + "bytes. Buffer Size is " +
6838 oemResp.length + "bytes.");
6839 }
6840 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6841 returnValue = responseData.length;
6842 }
6843 } else {
6844 CommandException ex = (CommandException) result.exception;
6845 returnValue = ex.getCommandError().ordinal();
6846 if(returnValue > 0) returnValue *= -1;
6847 }
6848 } catch (RuntimeException e) {
6849 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6850 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6851 if(returnValue > 0) returnValue *= -1;
6852 }
6853
6854 return returnValue;
6855 }
6856
6857 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006858 public void setRadioCapability(RadioAccessFamily[] rafs) {
6859 try {
6860 ProxyController.getInstance().setRadioCapability(rafs);
6861 } catch (RuntimeException e) {
6862 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6863 }
6864 }
6865
6866 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006867 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006868 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006869 try {
6870 TelephonyPermissions
6871 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6872 mApp, phone.getSubId(), "getRadioAccessFamily");
6873 } catch (SecurityException e) {
6874 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6875 throw e;
6876 }
chen xub97461a2018-10-26 14:17:57 -07006877 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006878 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006879 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006880 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006881 final long identity = Binder.clearCallingIdentity();
6882 try {
chen xub97461a2018-10-26 14:17:57 -07006883 TelephonyPermissions
6884 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6885 mApp, phone.getSubId(), "getRadioAccessFamily");
6886 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006887 } finally {
6888 Binder.restoreCallingIdentity(identity);
6889 }
chen xub97461a2018-10-26 14:17:57 -07006890 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006891 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006892
6893 @Override
6894 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006895 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006896 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006897
6898 final long identity = Binder.clearCallingIdentity();
6899 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006900 ImsManager.getInstance(defaultPhone.getContext(),
6901 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006902 } finally {
6903 Binder.restoreCallingIdentity(identity);
6904 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006905 }
6906
6907 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006908 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006909 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006910 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6911 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006912 return false;
6913 }
Svet Ganovb320e182015-04-16 12:30:10 -07006914
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006915 final long identity = Binder.clearCallingIdentity();
6916 try {
6917 // Check the user preference and the system-level IMS setting. Even if the user has
6918 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6919 // In the long run, we may instead need to check if there exists a connection service
6920 // which can support video calling.
6921 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006922 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006923 return imsManager.isVtEnabledByPlatform()
6924 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6925 && imsManager.isVtEnabledByUser();
6926 } finally {
6927 Binder.restoreCallingIdentity(identity);
6928 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006929 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006930
Andrew Leea1239f22015-03-02 17:44:07 -08006931 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006932 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6933 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006934 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006935 mApp, subId, callingPackage, callingFeatureId,
6936 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006937 return false;
6938 }
6939
6940 final long identity = Binder.clearCallingIdentity();
6941 try {
6942 CarrierConfigManager configManager =
6943 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006944 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006945 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6946 } finally {
6947 Binder.restoreCallingIdentity(identity);
6948 }
Andrew Leea1239f22015-03-02 17:44:07 -08006949 }
6950
6951 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006952 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006953 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006954 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006955 return false;
6956 }
6957
6958 final long identity = Binder.clearCallingIdentity();
6959 try {
6960 CarrierConfigManager configManager =
6961 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006962 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006963 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6964 } finally {
6965 Binder.restoreCallingIdentity(identity);
6966 }
Andrew Leea1239f22015-03-02 17:44:07 -08006967 }
6968
Andrew Lee9431b832015-03-09 18:46:45 -07006969 @Override
6970 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006971 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006972 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006973 }
6974
6975 @Override
6976 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006977 final long identity = Binder.clearCallingIdentity();
6978 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006979 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006980 } finally {
6981 Binder.restoreCallingIdentity(identity);
6982 }
Andrew Lee9431b832015-03-09 18:46:45 -07006983 }
6984
Hall Liuf6668912018-10-31 17:05:23 -07006985 /**
6986 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6987 * support for the feature and device firmware support.
6988 *
6989 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6990 */
6991 @Override
6992 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006993 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006994 final Phone phone = getPhone(subscriptionId);
6995 if (phone == null) {
6996 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6997 return false;
6998 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006999 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007000 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007001 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7002 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007003 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007004 return isCarrierSupported && isDeviceSupported;
7005 } finally {
7006 Binder.restoreCallingIdentity(identity);
7007 }
Hall Liu98187582018-01-22 19:15:32 -08007008 }
7009
Hall Liuf6668912018-10-31 17:05:23 -07007010 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007011 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7012 * RTT setting, will return true if the device and carrier both support RTT.
7013 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007014 */
7015 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007016 final long identity = Binder.clearCallingIdentity();
7017 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007018 boolean isRttSupported = isRttSupported(subscriptionId);
7019 boolean isUserRttSettingOn = Settings.Secure.getInt(
7020 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7021 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7022 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7023 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024 } finally {
7025 Binder.restoreCallingIdentity(identity);
7026 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007027 }
7028
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007029 @Deprecated
7030 @Override
7031 public String getDeviceId(String callingPackage) {
7032 return getDeviceIdWithFeature(callingPackage, null);
7033 }
7034
Sanket Padawe7310cc72015-01-14 09:53:20 -08007035 /**
7036 * Returns the unique device ID of phone, for example, the IMEI for
7037 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7038 *
7039 * <p>Requires Permission:
7040 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7041 */
7042 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007043 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007044 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007045 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007046 return null;
7047 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007048 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007049 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007050 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007051 return null;
7052 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007053
7054 final long identity = Binder.clearCallingIdentity();
7055 try {
7056 return phone.getDeviceId();
7057 } finally {
7058 Binder.restoreCallingIdentity(identity);
7059 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007060 }
7061
Ping Sunc67b7c22016-03-02 19:16:45 +08007062 /**
7063 * {@hide}
7064 * Returns the IMS Registration Status on a particular subid
7065 *
7066 * @param subId
7067 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007068 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007069 Phone phone = getPhone(subId);
7070 if (phone != null) {
7071 return phone.isImsRegistered();
7072 } else {
7073 return false;
7074 }
7075 }
7076
Santos Cordon7a1885b2015-02-03 11:15:19 -08007077 @Override
7078 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 final long identity = Binder.clearCallingIdentity();
7080 try {
7081 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7082 } finally {
7083 Binder.restoreCallingIdentity(identity);
7084 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007085 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007086
Tyler Gunnf70ed162019-04-03 15:28:53 -07007087 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007088 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007089 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007090 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007091 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007092 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7093 }
7094 final long identity = Binder.clearCallingIdentity();
7095 try {
7096 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7097 } finally {
7098 Binder.restoreCallingIdentity(identity);
7099 }
7100 }
7101
7102 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007103 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007104 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7105 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007106 final long identity = Binder.clearCallingIdentity();
7107 try {
7108 Phone phone = getPhone(subscriptionId);
7109 if (phone == null) {
7110 return null;
7111 }
7112 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7113 } finally {
7114 Binder.restoreCallingIdentity(identity);
7115 }
7116 }
7117
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007118 /**
7119 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007120 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007121 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007122 final long identity = Binder.clearCallingIdentity();
7123 try {
7124 Phone phone = getPhone(subId);
7125 if (phone != null) {
7126 return phone.isWifiCallingEnabled();
7127 } else {
7128 return false;
7129 }
7130 } finally {
7131 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007132 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007133 }
7134
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007135 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007136 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007137 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007138 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007139 final long identity = Binder.clearCallingIdentity();
7140 try {
7141 Phone phone = getPhone(subId);
7142 if (phone != null) {
7143 return phone.isVideoEnabled();
7144 } else {
7145 return false;
7146 }
7147 } finally {
7148 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007149 }
7150 }
7151
7152 /**
7153 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7154 * defined in {@link ImsRegistrationImplBase}.
7155 */
7156 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007157 final long identity = Binder.clearCallingIdentity();
7158 try {
7159 Phone phone = getPhone(subId);
7160 if (phone != null) {
7161 return phone.getImsRegistrationTech();
7162 } else {
7163 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7164 }
7165 } finally {
7166 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007167 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007168 }
7169
Stuart Scott8eef64f2015-04-08 15:13:54 -07007170 @Override
7171 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007172 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007173 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7174 return;
7175 }
7176
Svet Ganovcc087f82015-05-12 20:35:54 -07007177 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007178
Svet Ganovcc087f82015-05-12 20:35:54 -07007179 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007180 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7181 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007182 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007183 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007184 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007185 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007186 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7187 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007188 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007189 // There has been issues when Sms raw table somehow stores orphan
7190 // fragments. They lead to garbled message when new fragments come
7191 // in and combined with those stale ones. In case this happens again,
7192 // user can reset all network settings which will clean up this table.
7193 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007194 // Clean up IMS settings as well here.
7195 int slotId = getSlotIndex(subId);
7196 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7197 ImsManager.getInstance(mApp, slotId).factoryReset();
7198 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007199
7200 // Erase modem config if erase modem on network setting is enabled.
7201 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7202 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7203 if (configValue != null && Boolean.parseBoolean(configValue)) {
7204 sendEraseModemConfig(getDefaultPhone());
7205 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007206 } finally {
7207 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007208 }
7209 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007210
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007211 private void cleanUpSmsRawTable(Context context) {
7212 ContentResolver resolver = context.getContentResolver();
7213 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7214 resolver.delete(uri, null, null);
7215 }
7216
Narayan Kamath1c496c22015-04-16 14:40:19 +01007217 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007218 public String getSimLocaleForSubscriber(int subId) {
7219 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7220 final Phone phone = getPhone(subId);
7221 if (phone == null) {
7222 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007223 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007224 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007225 final long identity = Binder.clearCallingIdentity();
7226 try {
chen xu5d3637b2019-01-21 23:31:38 -08007227 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007228 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007229 if (info == null) {
7230 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7231 return null;
7232 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007233 // Try and fetch the locale from the carrier properties or from the SIM language
7234 // preferences (EF-PL and EF-LI)...
7235 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007236 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007237 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7238 if (localeFromDefaultSim != null) {
7239 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7240 if (DBG) log("Using locale from subId: " + subId + " locale: "
7241 + localeFromDefaultSim);
7242 return localeFromDefaultSim.toLanguageTag();
7243 } else {
7244 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007245 }
7246 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007247
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007248 // The SIM language preferences only store a language (e.g. fr = French), not an
7249 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7250 // the SIM and carrier preferences does not include a country we add the country
7251 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007252 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007253 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007254 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007255 return mccLocale.toLanguageTag();
7256 }
7257
7258 if (DBG) log("No locale found - returning null");
7259 return null;
7260 } finally {
7261 Binder.restoreCallingIdentity(identity);
7262 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007263 }
7264
7265 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007266 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007267 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007268 }
7269
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007270 /**
7271 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7272 */
7273 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007274 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007275 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007276 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007277
Chenjie Yu1ba97252018-01-11 18:16:20 -08007278 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007279 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007280
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007281 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007282 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7283 * representing the state of the modem.
7284 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007285 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7286 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007287 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007288 */
7289 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007290 public void requestModemActivityInfo(ResultReceiver result) {
7291 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007292 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007293
7294 final long identity = Binder.clearCallingIdentity();
7295 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007296 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007297 } finally {
7298 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007299 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007300 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007301
Siddharth Rayb8114062018-06-17 15:02:38 -07007302 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7303 // less than total activity duration.
7304 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7305 if (info == null) {
7306 return false;
7307 }
7308 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007309 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7310 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7311
Siddharth Rayb8114062018-06-17 15:02:38 -07007312 return (info.isValid()
7313 && (info.getSleepTimeMillis() <= activityDurationMs)
7314 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007315 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007316 && (totalTxTimeMs <= activityDurationMs));
7317 }
7318
Jack Yu85bd38a2015-11-09 11:34:32 -08007319 /**
7320 * {@hide}
7321 * Returns the service state information on specified subscription.
7322 */
7323 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007324 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7325 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007326 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007327 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007328 return null;
7329 }
7330
Hall Liuf19c44f2018-11-27 14:38:17 -08007331 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7332 LocationAccessPolicy.checkLocationPermission(mApp,
7333 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7334 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007335 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007336 .setCallingPid(Binder.getCallingPid())
7337 .setCallingUid(Binder.getCallingUid())
7338 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007339 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007340 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007341 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7342 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007343 .build());
7344
7345 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7346 LocationAccessPolicy.checkLocationPermission(mApp,
7347 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7348 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007349 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007350 .setCallingPid(Binder.getCallingPid())
7351 .setCallingUid(Binder.getCallingUid())
7352 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007353 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007354 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007355 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7356 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007357 .build());
7358 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7359 boolean hasFinePermission =
7360 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7361 boolean hasCoarsePermission =
7362 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7363
Jack Yu479f40e2020-10-27 21:29:25 -07007364 final Phone phone = getPhone(subId);
7365 if (phone == null) {
7366 return null;
7367 }
7368
Jordan Liu0f2bc442020-11-18 16:47:37 -08007369 final long identity = Binder.clearCallingIdentity();
7370
Jack Yu479f40e2020-10-27 21:29:25 -07007371 boolean isCallingPackageDataService = phone.getDataServicePackages()
7372 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007373 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007374 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7375 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7376 Rlog.d(LOG_TAG,
7377 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7378 return null;
7379 }
7380
Hall Liuf19c44f2018-11-27 14:38:17 -08007381 ServiceState ss = phone.getServiceState();
7382
7383 // Scrub out the location info in ServiceState depending on what level of access
7384 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007385 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007386 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7387 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007388 } finally {
7389 Binder.restoreCallingIdentity(identity);
7390 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007391 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007392
7393 /**
7394 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7395 *
7396 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7397 * voicemail ringtone.
7398 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7399 * PhoneAccount.
7400 */
7401 @Override
7402 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007403 final long identity = Binder.clearCallingIdentity();
7404 try {
7405 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7406 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007407 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007408 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007409
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007410 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7411 } finally {
7412 Binder.restoreCallingIdentity(identity);
7413 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007414 }
7415
7416 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007417 * Sets the per-account voicemail ringtone.
7418 *
7419 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7420 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7421 *
7422 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7423 * voicemail ringtone.
7424 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7425 * PhoneAccount.
7426 */
7427 @Override
7428 public void setVoicemailRingtoneUri(String callingPackage,
7429 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007430 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007431 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007432 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7433 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7435 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7436 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007437 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438
7439 final long identity = Binder.clearCallingIdentity();
7440 try {
7441 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7442 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007443 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007444 }
7445 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7446 } finally {
7447 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007448 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007449 }
7450
7451 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007452 * Returns whether vibration is set for voicemail notification in Phone settings.
7453 *
7454 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7455 * voicemail vibration setting.
7456 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7457 */
7458 @Override
7459 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007460 final long identity = Binder.clearCallingIdentity();
7461 try {
7462 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7463 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007464 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007465 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007467 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7468 } finally {
7469 Binder.restoreCallingIdentity(identity);
7470 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007471 }
7472
Youhan Wange64578a2016-05-02 15:32:42 -07007473 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007474 * Sets the per-account voicemail vibration.
7475 *
7476 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7477 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7478 *
7479 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7480 * voicemail vibration setting.
7481 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7482 * specific PhoneAccount.
7483 */
7484 @Override
7485 public void setVoicemailVibrationEnabled(String callingPackage,
7486 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007487 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007488 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007489 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7490 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7492 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7493 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007494 }
7495
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007496 final long identity = Binder.clearCallingIdentity();
7497 try {
7498 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7499 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007500 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007501 }
7502 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7503 } finally {
7504 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007505 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007506 }
7507
7508 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007509 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7510 *
7511 * @throws SecurityException if the caller does not have the required permission
7512 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007513 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007514 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007515 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007516 }
7517
7518 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007519 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7520 * permission.
7521 *
7522 * @throws SecurityException if the caller does not have the required permission
7523 */
7524 private void enforceSendSmsPermission() {
7525 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7526 }
7527
7528 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007529 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007530 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007531 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007532 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007533 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 final long identity = Binder.clearCallingIdentity();
7535 try {
7536 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007537 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538 if (componentName == null) {
7539 throw new SecurityException(
7540 "Caller not current active visual voicemail package[null]");
7541 }
7542 String vvmPackage = componentName.getPackageName();
7543 if (!callingPackage.equals(vvmPackage)) {
7544 throw new SecurityException("Caller not current active visual voicemail package["
7545 + vvmPackage + "]");
7546 }
7547 } finally {
7548 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007549 }
7550 }
7551
7552 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007553 * Return the application ID for the app type.
7554 *
7555 * @param subId the subscription ID that this request applies to.
7556 * @param appType the uicc app type.
7557 * @return Application ID for specificied app type, or null if no uicc.
7558 */
7559 @Override
7560 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007561 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007562 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007563
7564 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007565 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007566 if (phone == null) {
7567 return null;
7568 }
7569 String aid = null;
7570 try {
7571 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7572 .getApplicationByType(appType).getAid();
7573 } catch (Exception e) {
7574 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7575 }
7576 return aid;
7577 } finally {
7578 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007579 }
Youhan Wange64578a2016-05-02 15:32:42 -07007580 }
7581
Youhan Wang4001d252016-05-11 10:29:41 -07007582 /**
7583 * Return the Electronic Serial Number.
7584 *
7585 * @param subId the subscription ID that this request applies to.
7586 * @return ESN or null if error.
7587 */
7588 @Override
7589 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007590 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007591 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007592
7593 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007594 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007595 if (phone == null) {
7596 return null;
7597 }
7598 String esn = null;
7599 try {
7600 esn = phone.getEsn();
7601 } catch (Exception e) {
7602 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7603 }
7604 return esn;
7605 } finally {
7606 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007607 }
Youhan Wang4001d252016-05-11 10:29:41 -07007608 }
7609
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007610 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007611 * Return the Preferred Roaming List Version.
7612 *
7613 * @param subId the subscription ID that this request applies to.
7614 * @return PRLVersion or null if error.
7615 */
7616 @Override
7617 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007618 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007619 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007620
7621 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007622 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007623 if (phone == null) {
7624 return null;
7625 }
7626 String cdmaPrlVersion = null;
7627 try {
7628 cdmaPrlVersion = phone.getCdmaPrlVersion();
7629 } catch (Exception e) {
7630 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7631 }
7632 return cdmaPrlVersion;
7633 } finally {
7634 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007635 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007636 }
7637
7638 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007639 * Get snapshot of Telephony histograms
7640 * @return List of Telephony histograms
7641 * @hide
7642 */
7643 @Override
7644 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7646 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007647
7648 final long identity = Binder.clearCallingIdentity();
7649 try {
7650 return RIL.getTelephonyRILTimingHistograms();
7651 } finally {
7652 Binder.restoreCallingIdentity(identity);
7653 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007654 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007655
7656 /**
7657 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007658 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7659 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007660 * Require system privileges. In the future we may add this to carrier APIs.
7661 *
Michele Berionne482f8202018-11-27 18:57:59 -08007662 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007663 */
7664 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007665 @TelephonyManager.SetCarrierRestrictionResult
7666 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007667 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007668 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007669
Michele Berionne482f8202018-11-27 18:57:59 -08007670 if (carrierRestrictionRules == null) {
7671 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007672 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007673
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007674 final long identity = Binder.clearCallingIdentity();
7675 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007676 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007677 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007678 } finally {
7679 Binder.restoreCallingIdentity(identity);
7680 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007681 }
7682
7683 /**
7684 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007685 * Get the allowed carrier list and the excluded carrier list, including the priority between
7686 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007687 * Require system privileges. In the future we may add this to carrier APIs.
7688 *
Michele Berionne482f8202018-11-27 18:57:59 -08007689 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007690 */
7691 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007692 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007693 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007694 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007695
7696 final long identity = Binder.clearCallingIdentity();
7697 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007698 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7699 if (response instanceof CarrierRestrictionRules) {
7700 return (CarrierRestrictionRules) response;
7701 }
7702 // Response is an Exception of some kind,
7703 // which is signalled to the user as a NULL retval
7704 return null;
7705 } catch (Exception e) {
7706 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7707 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007708 } finally {
7709 Binder.restoreCallingIdentity(identity);
7710 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007711 }
7712
fionaxu59545b42016-05-25 15:53:37 -07007713 /**
fionaxu59545b42016-05-25 15:53:37 -07007714 * Action set from carrier signalling broadcast receivers to enable/disable radio
7715 * @param subId the subscription ID that this action applies to.
7716 * @param enabled control enable or disable radio.
7717 * {@hide}
7718 */
7719 @Override
7720 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7721 enforceModifyPermission();
7722 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007723
7724 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007725 if (phone == null) {
7726 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7727 return;
7728 }
7729 try {
7730 phone.carrierActionSetRadioEnabled(enabled);
7731 } catch (Exception e) {
7732 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007733 } finally {
7734 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007735 }
7736 }
7737
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007738 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007739 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7740 * network status based on which carrier apps could apply actions accordingly,
7741 * enable/disable default url handler for example.
7742 *
7743 * @param subId the subscription ID that this action applies to.
7744 * @param report control start/stop reporting the default network status.
7745 * {@hide}
7746 */
7747 @Override
7748 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7749 enforceModifyPermission();
7750 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007751
7752 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007753 if (phone == null) {
7754 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7755 return;
7756 }
7757 try {
7758 phone.carrierActionReportDefaultNetworkStatus(report);
7759 } catch (Exception e) {
7760 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007761 } finally {
7762 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007763 }
7764 }
7765
7766 /**
fionaxud9622282017-07-17 17:51:30 -07007767 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7768 * @param subId the subscription ID that this action applies to.
7769 * {@hide}
7770 */
7771 @Override
7772 public void carrierActionResetAll(int subId) {
7773 enforceModifyPermission();
7774 final Phone phone = getPhone(subId);
7775 if (phone == null) {
7776 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7777 return;
7778 }
7779 try {
7780 phone.carrierActionResetAll();
7781 } catch (Exception e) {
7782 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7783 }
7784 }
7785
7786 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007787 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7788 * bug report is being generated.
7789 */
7790 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007791 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007792 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7793 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007794 writer.println("Permission Denial: can't dump Phone from pid="
7795 + Binder.getCallingPid()
7796 + ", uid=" + Binder.getCallingUid()
7797 + "without permission "
7798 + android.Manifest.permission.DUMP);
7799 return;
7800 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007801 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007802 }
Jack Yueb89b242016-06-22 13:27:47 -07007803
Brad Ebingerdac2f002018-04-03 15:17:52 -07007804 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007805 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7806 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7807 @NonNull String[] args) {
7808 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7809 this, in.getFileDescriptor(), out.getFileDescriptor(),
7810 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007811 }
7812
Jack Yueb89b242016-06-22 13:27:47 -07007813 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007814 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007815 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007816 * @param reason the reason the data enable change is taking place
7817 * @param enabled True if enabling the data, otherwise disabling.
7818 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007819 */
7820 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007821 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007822 boolean enabled) {
7823 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7824 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7825 try {
7826 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007827 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007828 } catch (SecurityException se) {
7829 enforceModifyPermission();
7830 }
7831 } else {
7832 enforceModifyPermission();
7833 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007834
7835 final long identity = Binder.clearCallingIdentity();
7836 try {
7837 Phone phone = getPhone(subId);
7838 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007839 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7840 phone.carrierActionSetMeteredApnsEnabled(enabled);
7841 } else {
7842 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7843 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007844 }
7845 } finally {
7846 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007847 }
7848 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007849
7850 /**
7851 * Get Client request stats
7852 * @return List of Client Request Stats
7853 * @hide
7854 */
7855 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007856 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7857 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007858 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007859 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007860 return null;
7861 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007862 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007863
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007864 final long identity = Binder.clearCallingIdentity();
7865 try {
7866 if (phone != null) {
7867 return phone.getClientRequestStats();
7868 }
7869
7870 return null;
7871 } finally {
7872 Binder.restoreCallingIdentity(identity);
7873 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007874 }
7875
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007876 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007877 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007878 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007879 }
Jack Yueb4124c2017-02-16 15:32:43 -08007880
7881 /**
Grace Chen70990072017-03-24 17:21:30 -07007882 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007883 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007884 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007885 * @param state State of SIM (power down, power up, pass through)
7886 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7887 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7888 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007889 *
7890 **/
7891 @Override
Grace Chen70990072017-03-24 17:21:30 -07007892 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007893 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007894 Phone phone = PhoneFactory.getPhone(slotIndex);
7895
vagdeviaf9a5b92018-08-15 16:01:53 -07007896 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7897
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007898 final long identity = Binder.clearCallingIdentity();
7899 try {
7900 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08007901 phone.setSimPowerState(state, null, workSource);
7902 }
7903 } finally {
7904 Binder.restoreCallingIdentity(identity);
7905 }
7906 }
7907
7908 /**
7909 * Set SIM card power state.
7910 *
7911 * @param slotIndex SIM slot id.
7912 * @param state State of SIM (power down, power up, pass through)
7913 * @param callback callback to trigger after success or failure
7914 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7915 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7916 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7917 *
7918 **/
7919 @Override
7920 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7921 IIntegerConsumer callback) {
7922 enforceModifyPermission();
7923 Phone phone = PhoneFactory.getPhone(slotIndex);
7924
7925 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7926
7927 final long identity = Binder.clearCallingIdentity();
7928 try {
7929 if (phone != null) {
7930 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
7931 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007932 }
7933 } finally {
7934 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007935 }
7936 }
Shuo Qiandd210312017-04-12 22:11:33 +00007937
Tyler Gunn65d45c22017-06-05 11:22:26 -07007938 private boolean isUssdApiAllowed(int subId) {
7939 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007940 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007941 if (configManager == null) {
7942 return false;
7943 }
7944 PersistableBundle pb = configManager.getConfigForSubId(subId);
7945 if (pb == null) {
7946 return false;
7947 }
7948 return pb.getBoolean(
7949 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7950 }
7951
Shuo Qiandd210312017-04-12 22:11:33 +00007952 /**
7953 * Check if phone is in emergency callback mode
7954 * @return true if phone is in emergency callback mode
7955 * @param subId sub id
7956 */
goneil9c5f4872017-12-05 14:07:56 -08007957 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007958 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007959 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007960 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007961
7962 final long identity = Binder.clearCallingIdentity();
7963 try {
7964 if (phone != null) {
7965 return phone.isInEcm();
7966 } else {
7967 return false;
7968 }
7969 } finally {
7970 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007971 }
7972 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007973
7974 /**
7975 * Get the current signal strength information for the given subscription.
7976 * Because this information is not updated when the device is in a low power state
7977 * it should not be relied-upon to be current.
7978 * @param subId Subscription index
7979 * @return the most recent cached signal strength info from the modem
7980 */
7981 @Override
7982 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007983 final long identity = Binder.clearCallingIdentity();
7984 try {
7985 Phone p = getPhone(subId);
7986 if (p == null) {
7987 return null;
7988 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007989
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007990 return p.getSignalStrength();
7991 } finally {
7992 Binder.restoreCallingIdentity(identity);
7993 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007994 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007995
Pengquan Meng77b7f132018-08-22 14:49:57 -07007996 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007997 * Get the current modem radio state for the given slot.
7998 * @param slotIndex slot index.
7999 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008000 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008001 * @return the current radio power state from the modem
8002 */
8003 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008004 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008005 Phone phone = PhoneFactory.getPhone(slotIndex);
8006 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008007 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8008 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008009 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8010 }
8011
8012 final long identity = Binder.clearCallingIdentity();
8013 try {
8014 return phone.getRadioPowerState();
8015 } finally {
8016 Binder.restoreCallingIdentity(identity);
8017 }
8018 }
8019 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8020 }
8021
8022 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008023 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8024 *
8025 * <p>Requires one of the following permissions:
8026 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8027 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8028 * privileges.
8029 *
8030 * @param subId subscription id
8031 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8032 * {@code false}.
8033 */
8034 @Override
8035 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008036 try {
8037 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8038 null);
8039 } catch (Exception e) {
8040 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8041 mApp, subId, "isDataRoamingEnabled");
8042 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008043
Pengquan Menga1bb6272018-09-06 09:59:22 -07008044 boolean isEnabled = false;
8045 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008046 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008047 Phone phone = getPhone(subId);
8048 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008049 } finally {
8050 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008051 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008052 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008053 }
8054
8055
8056 /**
8057 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8058 *
8059 * <p> Requires permission:
8060 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8061 * privileges.
8062 *
8063 * @param subId subscription id
8064 * @param isEnabled {@code true} means enable, {@code false} means disable.
8065 */
8066 @Override
8067 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8069 mApp, subId, "setDataRoamingEnabled");
8070
Pengquan Menga1bb6272018-09-06 09:59:22 -07008071 final long identity = Binder.clearCallingIdentity();
8072 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008073 Phone phone = getPhone(subId);
8074 if (phone != null) {
8075 phone.setDataRoamingEnabled(isEnabled);
8076 }
8077 } finally {
8078 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008079 }
8080 }
8081
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008082 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008083 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008084 TelephonyPermissions
8085 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008086 mApp, subId, "isManualNetworkSelectionAllowed");
8087
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008088 boolean isAllowed = true;
8089 final long identity = Binder.clearCallingIdentity();
8090 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008091 Phone phone = getPhone(subId);
8092 if (phone != null) {
8093 isAllowed = phone.isCspPlmnEnabled();
8094 }
8095 } finally {
8096 Binder.restoreCallingIdentity(identity);
8097 }
8098 return isAllowed;
8099 }
8100
8101 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008102 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008103 // Verify that tha callingPackage belongs to the calling UID
8104 mApp.getSystemService(AppOpsManager.class)
8105 .checkPackage(Binder.getCallingUid(), callingPackage);
8106
Jordan Liu1e142fc2019-04-22 15:10:43 -07008107 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008108 try {
8109 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008110 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008111 } catch (SecurityException e) {
8112 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8113 // has carrier privileges on an active UICC
8114 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8115 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008116 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008117 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008118 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008119
8120 final long identity = Binder.clearCallingIdentity();
8121 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008122 UiccController uiccController = UiccController.getInstance();
8123 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008124 if (hasReadPermission) {
8125 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008126 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008127
8128 // Remove private info if the caller doesn't have access
8129 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8130 for (UiccCardInfo cardInfo : cardInfos) {
8131 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8132 // is available
8133 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8134 if (card == null || card.getUiccProfile() == null) {
8135 // assume no access if the card or profile is unavailable
8136 filteredInfos.add(cardInfo.getUnprivileged());
8137 continue;
8138 }
8139 UiccProfile profile = card.getUiccProfile();
8140 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8141 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8142 filteredInfos.add(cardInfo);
8143 } else {
8144 filteredInfos.add(cardInfo.getUnprivileged());
8145 }
8146 }
8147 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008148 } finally {
8149 Binder.restoreCallingIdentity(identity);
8150 }
8151 }
8152
8153 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008154 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008155 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008156
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008157 final long identity = Binder.clearCallingIdentity();
8158 try {
8159 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8160 if (slots == null) {
8161 Rlog.i(LOG_TAG, "slots is null.");
8162 return null;
8163 }
8164
8165 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8166 for (int i = 0; i < slots.length; i++) {
8167 UiccSlot slot = slots[i];
8168 if (slot == null) {
8169 continue;
8170 }
8171
Jordan Liu7be7e652019-05-06 18:55:02 +00008172 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008173 UiccCard card = slot.getUiccCard();
8174 if (card != null) {
8175 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008176 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008177 cardId = slot.getEid();
8178 if (TextUtils.isEmpty(cardId)) {
8179 cardId = slot.getIccId();
8180 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008181 }
8182
Jordan Liu857451f2019-05-09 16:35:35 -07008183 if (cardId != null) {
8184 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8185 // if cardId is an EID, it's all digits so this is fine
8186 cardId = IccUtils.stripTrailingFs(cardId);
8187 }
8188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008189 int cardState = 0;
8190 switch (slot.getCardState()) {
8191 case CARDSTATE_ABSENT:
8192 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8193 break;
8194 case CARDSTATE_PRESENT:
8195 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8196 break;
8197 case CARDSTATE_ERROR:
8198 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8199 break;
8200 case CARDSTATE_RESTRICTED:
8201 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8202 break;
8203 default:
8204 break;
8205
8206 }
8207
8208 infos[i] = new UiccSlotInfo(
8209 slot.isActive(),
8210 slot.isEuicc(),
8211 cardId,
8212 cardState,
8213 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008214 slot.isExtendedApduSupported(),
8215 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008216 }
8217 return infos;
8218 } finally {
8219 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008220 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008221 }
8222
8223 @Override
8224 public boolean switchSlots(int[] physicalSlots) {
8225 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008226
8227 final long identity = Binder.clearCallingIdentity();
8228 try {
8229 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8230 } finally {
8231 Binder.restoreCallingIdentity(identity);
8232 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008233 }
Jack Yu4c988042018-02-27 15:30:01 -08008234
8235 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008236 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008237 final long identity = Binder.clearCallingIdentity();
8238 try {
8239 return UiccController.getInstance().getCardIdForDefaultEuicc();
8240 } finally {
8241 Binder.restoreCallingIdentity(identity);
8242 }
8243 }
8244
Pengquan Meng85728fb2018-03-12 16:31:21 -07008245 /**
goneil47ffb6e2018-04-06 15:40:58 -07008246 * A test API to reload the UICC profile.
8247 *
8248 * <p>Requires that the calling app has permission
8249 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8250 * @hide
8251 */
8252 @Override
8253 public void refreshUiccProfile(int subId) {
8254 enforceModifyPermission();
8255
8256 final long identity = Binder.clearCallingIdentity();
8257 try {
8258 Phone phone = getPhone(subId);
8259 if (phone == null) {
8260 return;
8261 }
8262 UiccCard uiccCard = phone.getUiccCard();
8263 if (uiccCard == null) {
8264 return;
8265 }
8266 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8267 if (uiccProfile == null) {
8268 return;
8269 }
8270 uiccProfile.refresh();
8271 } finally {
8272 Binder.restoreCallingIdentity(identity);
8273 }
8274 }
8275
8276 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008277 * Returns false if the mobile data is disabled by default, otherwise return true.
8278 */
8279 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008280 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008281 }
8282
8283 /**
8284 * Returns true if the data roaming is enabled by default, i.e the system property
8285 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8286 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8287 */
8288 private boolean getDefaultDataRoamingEnabled(int subId) {
8289 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008290 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008291 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008292 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8293 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8294 return isDataRoamingEnabled;
8295 }
8296
8297 /**
8298 * Returns the default network type for the given {@code subId}, if the default network type is
8299 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8300 */
8301 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008302 List<Integer> list = TelephonyProperties.default_network();
8303 int phoneId = mSubscriptionController.getPhoneId(subId);
8304 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8305 return list.get(phoneId);
8306 }
8307 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008308 }
fionaxua13278b2018-03-21 00:08:13 -07008309
8310 @Override
8311 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008312 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008313 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008314
8315 final long identity = Binder.clearCallingIdentity();
8316 try {
8317 final Phone phone = getPhone(subId);
8318 if (phone == null) {
8319 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8320 return;
8321 }
chen xueaba88a2019-03-15 13:15:10 -07008322 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8323 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008324 if (carrierPrivilegeRules == null) {
8325 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8326 } else {
8327 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8328 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008329 } finally {
8330 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008331 }
fionaxua13278b2018-03-21 00:08:13 -07008332 }
8333
8334 @Override
8335 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008336 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008337
8338 final long identity = Binder.clearCallingIdentity();
8339 try {
8340 final Phone phone = getPhone(subId);
8341 if (phone == null) {
8342 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8343 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8344 }
8345 return phone.getCarrierIdListVersion();
8346 } finally {
8347 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008348 }
fionaxua13278b2018-03-21 00:08:13 -07008349 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008350
8351 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008352 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8353 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008354 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008355 mApp, subId, callingPackage, callingFeatureId,
8356 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008357 return -1;
8358 }
8359
8360 final long identity = Binder.clearCallingIdentity();
8361 try {
8362 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8363 } finally {
8364 Binder.restoreCallingIdentity(identity);
8365 }
8366 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008367
8368 @Override
8369 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008370 TelephonyPermissions
8371 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008372 mApp, subId, "getCdmaRoamingMode");
8373
8374 final long identity = Binder.clearCallingIdentity();
8375 try {
8376 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8377 } finally {
8378 Binder.restoreCallingIdentity(identity);
8379 }
8380 }
8381
8382 @Override
8383 public boolean setCdmaRoamingMode(int subId, int mode) {
8384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8385 mApp, subId, "setCdmaRoamingMode");
8386
8387 final long identity = Binder.clearCallingIdentity();
8388 try {
8389 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8390 } finally {
8391 Binder.restoreCallingIdentity(identity);
8392 }
8393 }
8394
8395 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008396 public int getCdmaSubscriptionMode(int subId) {
8397 TelephonyPermissions
8398 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8399 mApp, subId, "getCdmaSubscriptionMode");
8400
8401 final long identity = Binder.clearCallingIdentity();
8402 try {
8403 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8404 } finally {
8405 Binder.restoreCallingIdentity(identity);
8406 }
8407 }
8408
8409 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008410 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8412 mApp, subId, "setCdmaSubscriptionMode");
8413
8414 final long identity = Binder.clearCallingIdentity();
8415 try {
8416 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8417 } finally {
8418 Binder.restoreCallingIdentity(identity);
8419 }
8420 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008421
sqianc5eccab2018-10-19 18:46:41 -07008422 @Override
sqian8c685422019-02-22 15:55:18 -08008423 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008424 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008425 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008426 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8427 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008428 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8429 }
8430 final long identity = Binder.clearCallingIdentity();
8431 try {
sqian854d44b2018-12-12 16:48:18 -08008432 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8433 for (Phone phone: PhoneFactory.getPhones()) {
8434 if (phone.getEmergencyNumberTracker() != null
8435 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8436 emergencyNumberListInternal.put(
8437 phone.getSubId(),
8438 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8439 }
sqian11b7a0e2018-12-05 18:48:28 -08008440 }
sqian854d44b2018-12-12 16:48:18 -08008441 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008442 } finally {
8443 Binder.restoreCallingIdentity(identity);
8444 }
sqianc5eccab2018-10-19 18:46:41 -07008445 }
8446
8447 @Override
sqian8c685422019-02-22 15:55:18 -08008448 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008449 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008450 if (!exactMatch) {
8451 TelephonyPermissions
8452 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008453 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008454 }
8455 final long identity = Binder.clearCallingIdentity();
8456 try {
sqian854d44b2018-12-12 16:48:18 -08008457 for (Phone phone: PhoneFactory.getPhones()) {
8458 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008459 && phone.getEmergencyNumberTracker()
8460 .isEmergencyNumber(number, exactMatch)) {
8461 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008462 }
sqian11b7a0e2018-12-05 18:48:28 -08008463 }
8464 return false;
8465 } finally {
8466 Binder.restoreCallingIdentity(identity);
8467 }
8468 }
8469
sqianf4ca7ed2019-01-15 18:32:07 -08008470 /**
8471 * Update emergency number list for test mode.
8472 */
8473 @Override
8474 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8475 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8476 "updateEmergencyNumberListTestMode");
8477
8478 final long identity = Binder.clearCallingIdentity();
8479 try {
8480 for (Phone phone: PhoneFactory.getPhones()) {
8481 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8482 if (tracker != null) {
8483 tracker.executeEmergencyNumberTestModeCommand(action, num);
8484 }
8485 }
8486 } finally {
8487 Binder.restoreCallingIdentity(identity);
8488 }
8489 }
8490
8491 /**
8492 * Get the full emergency number list for test mode.
8493 */
8494 @Override
8495 public List<String> getEmergencyNumberListTestMode() {
8496 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8497 "getEmergencyNumberListTestMode");
8498
8499 final long identity = Binder.clearCallingIdentity();
8500 try {
8501 Set<String> emergencyNumbers = new HashSet<>();
8502 for (Phone phone: PhoneFactory.getPhones()) {
8503 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8504 if (tracker != null) {
8505 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8506 emergencyNumbers.add(num.getNumber());
8507 }
8508 }
8509 }
8510 return new ArrayList<>(emergencyNumbers);
8511 } finally {
8512 Binder.restoreCallingIdentity(identity);
8513 }
8514 }
8515
chen xud6b45bd2018-10-30 22:27:10 -07008516 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008517 public int getEmergencyNumberDbVersion(int subId) {
8518 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8519
8520 final long identity = Binder.clearCallingIdentity();
8521 try {
8522 final Phone phone = getPhone(subId);
8523 if (phone == null) {
8524 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8525 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8526 }
8527 return phone.getEmergencyNumberDbVersion();
8528 } finally {
8529 Binder.restoreCallingIdentity(identity);
8530 }
8531 }
8532
8533 @Override
8534 public void notifyOtaEmergencyNumberDbInstalled() {
8535 enforceModifyPermission();
8536
8537 final long identity = Binder.clearCallingIdentity();
8538 try {
8539 for (Phone phone: PhoneFactory.getPhones()) {
8540 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8541 if (tracker != null) {
8542 tracker.updateOtaEmergencyNumberDatabase();
8543 }
8544 }
8545 } finally {
8546 Binder.restoreCallingIdentity(identity);
8547 }
8548 }
8549
8550 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008551 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008552 enforceActiveEmergencySessionPermission();
8553
8554 final long identity = Binder.clearCallingIdentity();
8555 try {
8556 for (Phone phone: PhoneFactory.getPhones()) {
8557 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8558 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008559 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8560 }
8561 }
8562 } finally {
8563 Binder.restoreCallingIdentity(identity);
8564 }
8565 }
8566
8567 @Override
8568 public void resetOtaEmergencyNumberDbFilePath() {
8569 enforceActiveEmergencySessionPermission();
8570
8571 final long identity = Binder.clearCallingIdentity();
8572 try {
8573 for (Phone phone: PhoneFactory.getPhones()) {
8574 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8575 if (tracker != null) {
8576 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008577 }
8578 }
8579 } finally {
8580 Binder.restoreCallingIdentity(identity);
8581 }
8582 }
8583
8584 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008585 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8586 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8587 Phone phone = getPhone(subId);
8588 if (phone == null) {
8589 return null;
8590 }
8591 final long identity = Binder.clearCallingIdentity();
8592 try {
8593 UiccProfile profile = UiccController.getInstance()
8594 .getUiccProfileForPhone(phone.getPhoneId());
8595 if (profile != null) {
8596 return profile.getCertsFromCarrierPrivilegeAccessRules();
8597 }
8598 } finally {
8599 Binder.restoreCallingIdentity(identity);
8600 }
8601 return null;
8602 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008603
8604 /**
8605 * Enable or disable a modem stack.
8606 */
8607 @Override
8608 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8609 enforceModifyPermission();
8610
8611 final long identity = Binder.clearCallingIdentity();
8612 try {
8613 Phone phone = PhoneFactory.getPhone(slotIndex);
8614 if (phone == null) {
8615 return false;
8616 } else {
8617 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8618 }
8619 } finally {
8620 Binder.restoreCallingIdentity(identity);
8621 }
8622 }
Michelecea4cf22018-12-21 15:00:11 -08008623
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008624 /**
8625 * Whether a modem stack is enabled or not.
8626 */
8627 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008628 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8629 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008630 Phone phone = PhoneFactory.getPhone(slotIndex);
8631 if (phone == null) return false;
8632
8633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008634 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8635 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008636 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8637 }
8638
8639 final long identity = Binder.clearCallingIdentity();
8640 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008641 try {
8642 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8643 } catch (NoSuchElementException ex) {
8644 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8645 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008646 } finally {
8647 Binder.restoreCallingIdentity(identity);
8648 }
8649 }
8650
Michelecea4cf22018-12-21 15:00:11 -08008651 @Override
Michele0ea7d782019-03-19 14:58:42 -07008652 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008653 enforceModifyPermission();
8654
8655 final long identity = Binder.clearCallingIdentity();
8656 try {
8657 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008658 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008659 .commit();
8660 } finally {
8661 Binder.restoreCallingIdentity(identity);
8662 }
8663 }
8664
8665 @Override
Michele0ea7d782019-03-19 14:58:42 -07008666 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008667 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008668 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008669 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8670 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008671 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008672 }
Michelecea4cf22018-12-21 15:00:11 -08008673
8674 final long identity = Binder.clearCallingIdentity();
8675 try {
Michele0ea7d782019-03-19 14:58:42 -07008676 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008677 } finally {
8678 Binder.restoreCallingIdentity(identity);
8679 }
8680 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008681
Michele0ea7d782019-03-19 14:58:42 -07008682 @TelephonyManager.IsMultiSimSupportedResult
8683 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008684 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8685 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8686 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008687 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8688 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008689 }
8690 // Check if the hardware supports multisim functionality. If usage of multisim is not
8691 // supported by the modem, indicate that it is restricted.
8692 PhoneCapability staticCapability =
8693 mPhoneConfigurationManager.getStaticPhoneCapability();
8694 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008695 loge("isMultiSimSupportedInternal: no static configuration available");
8696 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008697 }
Sarah Chin7caee492020-02-18 20:49:02 +00008698 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008699 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8700 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008701 }
8702 // Check if support of multiple SIMs is restricted by carrier
8703 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008704 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008705 }
8706
Michele0ea7d782019-03-19 14:58:42 -07008707 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008708 }
8709
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008710 /**
8711 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008712 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8713 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8714 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008715 * @param numOfSims number of active sims we want to switch to
8716 */
8717 @Override
8718 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008719 if (numOfSims == 1) {
8720 enforceModifyPermission();
8721 } else {
8722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8723 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8724 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008725 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008726
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008727 try {
Michele30b57b22019-03-01 12:01:14 -08008728 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008729 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008730 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8731 return;
8732 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008733 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8734 } finally {
8735 Binder.restoreCallingIdentity(identity);
8736 }
8737 }
8738
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008739 @Override
8740 public boolean isApplicationOnUicc(int subId, int appType) {
8741 enforceReadPrivilegedPermission("isApplicationOnUicc");
8742 Phone phone = getPhone(subId);
8743 if (phone == null) {
8744 return false;
8745 }
8746 final long identity = Binder.clearCallingIdentity();
8747 try {
8748 UiccCard uiccCard = phone.getUiccCard();
8749 if (uiccCard == null) {
8750 return false;
8751 }
8752 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8753 if (uiccProfile == null) {
8754 return false;
8755 }
8756 if (TelephonyManager.APPTYPE_SIM <= appType
8757 && appType <= TelephonyManager.APPTYPE_ISIM) {
8758 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8759 }
8760 return false;
8761 } finally {
8762 Binder.restoreCallingIdentity(identity);
8763 }
8764 }
8765
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008766 /**
chen xub4baa772019-04-03 10:23:41 -07008767 * Get whether making changes to modem configurations will trigger reboot.
8768 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008769 */
8770 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008771 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8772 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008773 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008774 mApp, subId, callingPackage, callingFeatureId,
8775 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008776 return false;
8777 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008778 final long identity = Binder.clearCallingIdentity();
8779 try {
8780 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8781 } finally {
8782 Binder.restoreCallingIdentity(identity);
8783 }
8784 }
8785
Nathan Harold29f5f052019-02-15 13:41:57 -08008786 private void updateModemStateMetrics() {
8787 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8788 // TODO: check the state for each modem if the api is ready.
8789 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8790 }
8791
Pengquan Meng3889a572019-01-23 11:16:29 -08008792 @Override
8793 public int[] getSlotsMapping() {
8794 enforceReadPrivilegedPermission("getSlotsMapping");
8795
8796 final long identity = Binder.clearCallingIdentity();
8797 try {
8798 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8799 // All logical slots should have a mapping to a physical slot.
8800 int[] logicalSlotsMapping = new int[phoneCount];
8801 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8802 for (int i = 0; i < slotInfos.length; i++) {
8803 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8804 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8805 }
8806 }
8807 return logicalSlotsMapping;
8808 } finally {
8809 Binder.restoreCallingIdentity(identity);
8810 }
8811 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008812
8813 /**
8814 * Get the IRadio HAL Version
8815 */
8816 @Override
8817 public int getRadioHalVersion() {
8818 Phone phone = getDefaultPhone();
8819 if (phone == null) return -1;
8820 HalVersion hv = phone.getHalVersion();
8821 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8822 return hv.major * 100 + hv.minor;
8823 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008824
8825 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008826 * Get the current calling package name.
8827 * @return the current calling package name
8828 */
8829 @Override
8830 public String getCurrentPackageName() {
8831 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8832 }
8833
8834 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008835 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8836 * corresponding network requests on a subId.
8837 *
8838 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008839 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008840 * 2) APN is un-metered for this subscription, or
8841 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07008842 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008843 *
8844 * @return whether data is allowed for a apn type.
8845 *
8846 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008847 */
8848 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008849 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008850 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8851 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008852
8853 // Now that all security checks passes, perform the operation as ourselves.
8854 final long identity = Binder.clearCallingIdentity();
8855 try {
8856 Phone phone = getPhone(subId);
8857 if (phone == null) return false;
8858
Jack Yu41407ee2019-05-13 16:54:09 -07008859 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008860 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8861 } finally {
8862 Binder.restoreCallingIdentity(identity);
8863 }
8864 }
8865
8866 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008867 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008868 enforceReadPrivilegedPermission("isApnMetered");
8869
8870 // Now that all security checks passes, perform the operation as ourselves.
8871 final long identity = Binder.clearCallingIdentity();
8872 try {
8873 Phone phone = getPhone(subId);
8874 if (phone == null) return true; // By default return true.
8875
Jack Yu41407ee2019-05-13 16:54:09 -07008876 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008877 } finally {
8878 Binder.restoreCallingIdentity(identity);
8879 }
8880 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008881
8882 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008883 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8884 int subscriptionId, IBooleanConsumer resultCallback) {
8885 enforceModifyPermission();
8886 long token = Binder.clearCallingIdentity();
8887 try {
8888 Phone phone = getPhone(subscriptionId);
8889 if (phone == null) {
8890 try {
8891 if (resultCallback != null) {
8892 resultCallback.accept(false);
8893 }
8894 } catch (RemoteException e) {
8895 // ignore
8896 }
8897 return;
8898 }
8899 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8900 Pair.create(specifiers, (x) -> {
8901 try {
8902 if (resultCallback != null) {
8903 resultCallback.accept(x);
8904 }
8905 } catch (RemoteException e) {
8906 // ignore
8907 }
8908 });
8909 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8910 } finally {
8911 Binder.restoreCallingIdentity(token);
8912 }
8913 }
8914
8915 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08008916 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8917 TelephonyPermissions
8918 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8919 mApp, subId, "getSystemSelectionChannels");
8920 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8921 final long identity = Binder.clearCallingIdentity();
8922 try {
8923 List<RadioAccessSpecifier> specifiers =
8924 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8925 null, subId, workSource);
8926 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8927 return specifiers;
8928 } finally {
8929 Binder.restoreCallingIdentity(identity);
8930 }
8931 }
8932
8933 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008934 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008935 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008936 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8937 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8938 if (iccRecords == null) {
8939 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8940 return false;
8941 }
8942 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8943 }
8944
8945 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008946 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8947 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008948 if (callingPackage == null) {
8949 callingPackage = getCurrentPackageName();
8950 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008951 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8952 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008953 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8954 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008955 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8956 }
8957 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8958 Intent intent = new Intent();
8959 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8960 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8961 // Bring up choose default SMS subscription dialog right now
8962 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8963 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8964 mApp.startActivity(intent);
8965 }
chen xud5ca2d52019-05-28 15:20:57 -07008966
8967 @Override
8968 public String getMmsUAProfUrl(int subId) {
8969 //TODO investigate if this API should require proper permission check in R b/133791609
8970 final long identity = Binder.clearCallingIdentity();
8971 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008972 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8973 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8974 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8975 return carrierUAProfUrl;
8976 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008977 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8978 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008979 } finally {
8980 Binder.restoreCallingIdentity(identity);
8981 }
8982 }
8983
8984 @Override
8985 public String getMmsUserAgent(int subId) {
8986 //TODO investigate if this API should require proper permission check in R b/133791609
8987 final long identity = Binder.clearCallingIdentity();
8988 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008989 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8990 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8991 if (!TextUtils.isEmpty(carrierUserAgent)) {
8992 return carrierUserAgent;
8993 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008994 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8995 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008996 } finally {
8997 Binder.restoreCallingIdentity(identity);
8998 }
8999 }
Jack Yub07d4972019-05-28 16:12:25 -07009000
9001 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009002 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9003 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009004
Jack Yub07d4972019-05-28 16:12:25 -07009005 final long identity = Binder.clearCallingIdentity();
9006 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009007 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009008 if (phone == null) return false;
9009
Hall Liua62f5da2020-09-25 10:42:19 -07009010 switch (policy) {
9011 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9012 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9013 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9014 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9015 default:
9016 throw new IllegalArgumentException(policy + " is not a valid policy");
9017 }
Jack Yub07d4972019-05-28 16:12:25 -07009018 } finally {
9019 Binder.restoreCallingIdentity(identity);
9020 }
9021 }
9022
9023 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009024 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9025 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009026 enforceModifyPermission();
9027
changbettyd5c246e2019-12-24 15:40:37 +08009028 final long identity = Binder.clearCallingIdentity();
9029 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009030 Phone phone = getPhone(subscriptionId);
9031 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009032
Hall Liua62f5da2020-09-25 10:42:19 -07009033 switch (policy) {
9034 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9035 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9036 break;
9037 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9038 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9039 break;
9040 default:
9041 throw new IllegalArgumentException(policy + " is not a valid policy");
9042 }
changbettyd5c246e2019-12-24 15:40:37 +08009043 } finally {
9044 Binder.restoreCallingIdentity(identity);
9045 }
9046 }
9047
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009048 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009049 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009050 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9051 * otherwise.
9052 */
9053 @Override
9054 public void setCepEnabled(boolean isCepEnabled) {
9055 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9056
9057 final long identity = Binder.clearCallingIdentity();
9058 try {
9059 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9060 for (Phone phone : PhoneFactory.getPhones()) {
9061 Phone defaultPhone = phone.getImsPhone();
9062 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9063 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9064 ImsPhoneCallTracker imsPhoneCallTracker =
9065 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9066 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9067 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9068 + imsPhone.getMsisdn());
9069 }
9070 }
9071 } finally {
9072 Binder.restoreCallingIdentity(identity);
9073 }
9074 }
allenwtsu46dcc572020-01-08 18:24:03 +08009075
9076 /**
9077 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9078 *
9079 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9080 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9081 * before being read.
9082 */
9083 @Override
9084 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9085 isCompressed) {
9086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9087 mApp, subId, "notifyRcsAutoConfigurationReceived");
9088 try {
9089 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9090 if (configBinder == null) {
9091 Rlog.e(LOG_TAG, "null result for getImsConfig");
9092 } else {
9093 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
9094 }
9095 } catch (RemoteException e) {
9096 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
9097 }
9098 }
zoey chene02881a2019-12-30 16:11:23 +08009099
9100 @Override
9101 public boolean isIccLockEnabled(int subId) {
9102 enforceReadPrivilegedPermission("isIccLockEnabled");
9103
9104 // Now that all security checks passes, perform the operation as ourselves.
9105 final long identity = Binder.clearCallingIdentity();
9106 try {
9107 Phone phone = getPhone(subId);
9108 if (phone != null && phone.getIccCard() != null) {
9109 return phone.getIccCard().getIccLockEnabled();
9110 } else {
9111 return false;
9112 }
9113 } finally {
9114 Binder.restoreCallingIdentity(identity);
9115 }
9116 }
9117
9118 /**
9119 * Set the ICC pin lock enabled or disabled.
9120 *
9121 * @return an integer representing the status of IccLock enabled or disabled in the following
9122 * three cases:
9123 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9124 * successfully.
9125 * - Positive number and zero for remaining password attempts.
9126 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9127 *
9128 */
9129 @Override
9130 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9131 enforceModifyPermission();
9132
9133 Phone phone = getPhone(subId);
9134 if (phone == null) {
9135 return 0;
9136 }
9137 // Now that all security checks passes, perform the operation as ourselves.
9138 final long identity = Binder.clearCallingIdentity();
9139 try {
9140 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9141 new Pair<Boolean, String>(enabled, password), phone, null);
9142 return attemptsRemaining;
9143
9144 } catch (Exception e) {
9145 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9146 } finally {
9147 Binder.restoreCallingIdentity(identity);
9148 }
9149 return 0;
9150 }
9151
9152 /**
9153 * Change the ICC password used in ICC pin lock.
9154 *
9155 * @return an integer representing the status of IccLock changed in the following three cases:
9156 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9157 * - Positive number and zero for remaining password attempts.
9158 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9159 *
9160 */
9161 @Override
9162 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9163 enforceModifyPermission();
9164
9165 Phone phone = getPhone(subId);
9166 if (phone == null) {
9167 return 0;
9168 }
9169 // Now that all security checks passes, perform the operation as ourselves.
9170 final long identity = Binder.clearCallingIdentity();
9171 try {
9172 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9173 new Pair<String, String>(oldPassword, newPassword), phone, null);
9174 return attemptsRemaining;
9175
9176 } catch (Exception e) {
9177 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9178 } finally {
9179 Binder.restoreCallingIdentity(identity);
9180 }
9181 return 0;
9182 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009183
9184 /**
9185 * Request for receiving user activity notification
9186 */
9187 @Override
9188 public void requestUserActivityNotification() {
9189 if (!mNotifyUserActivity.get()
9190 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9191 mNotifyUserActivity.set(true);
9192 }
9193 }
9194
9195 /**
9196 * Called when userActivity is signalled in the power manager.
9197 * This is safe to call from any thread, with any window manager locks held or not.
9198 */
9199 @Override
9200 public void userActivity() {
9201 // ***************************************
9202 // * Inherited from PhoneWindowManager *
9203 // ***************************************
9204 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9205 // WITH ITS LOCKS HELD.
9206 //
9207 // This code must be VERY careful about the locks
9208 // it acquires.
9209 // In fact, the current code acquires way too many,
9210 // and probably has lurking deadlocks.
9211
9212 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9213 throw new SecurityException("Only the OS may call notifyUserActivity()");
9214 }
9215
9216 if (mNotifyUserActivity.getAndSet(false)) {
9217 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9218 USER_ACTIVITY_NOTIFICATION_DELAY);
9219 }
9220 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009221
9222 @Override
9223 public boolean canConnectTo5GInDsdsMode() {
9224 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9225 }
Jack Yud10cdd42020-09-28 20:28:01 -07009226
9227 @Override
9228 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9229 String callingFeatureId) {
9230 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9231 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9232 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9233 }
9234
9235 Phone phone = getPhone(subId);
9236 if (phone == null) {
9237 throw new RuntimeException("phone is not available");
9238 }
9239 // Now that all security checks passes, perform the operation as ourselves.
9240 final long identity = Binder.clearCallingIdentity();
9241 try {
9242 return phone.getEquivalentHomePlmns();
9243 } finally {
9244 Binder.restoreCallingIdentity(identity);
9245 }
9246 }
Daniel Bright59e67312020-11-13 11:49:37 -08009247
9248 @Override
9249 public boolean isRadioInterfaceCapabilitySupported(
9250 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9251 RadioInterfaceCapabilities radioInterfaceCapabilities =
9252 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9253 if (radioInterfaceCapabilities == null) {
9254 throw new RuntimeException("radio interface capabilities are not available");
9255 } else {
9256 return radioInterfaceCapabilities.isSupported(capability);
9257 }
9258 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009259
Hui Wang641e81c2020-10-12 12:14:23 -07009260 @Override
9261 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9262 UaSecurityProtocolIdentifier securityProtocol,
9263 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9264 throws RemoteException {
9265 enforceModifyPermission();
9266 if (DBG) {
9267 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9268 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9269 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9270 }
9271
9272 if (!SubscriptionManager.isValidSubscriptionId(subId)
9273 || appType < TelephonyManager.APPTYPE_UNKNOWN
9274 || appType > TelephonyManager.APPTYPE_ISIM
9275 || nafUrl == null || securityProtocol == null || callback == null) {
9276 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9277 if (callback != null) {
9278 try {
9279 callback.onAuthenticationFailure(
9280 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9281 } catch (RemoteException exception) {
9282 log("Fail to notify onAuthenticationFailure due to " + exception);
9283 }
9284 return;
9285 }
9286 }
9287
9288 final long token = Binder.clearCallingIdentity();
9289 try {
9290 getGbaManager(subId).bootstrapAuthenticationRequest(
9291 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9292 forceBootStrapping, callback));
9293 } finally {
9294 Binder.restoreCallingIdentity(token);
9295 }
9296 }
9297
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009298 /**
9299 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9300 * requested radio power state will actually be set. See {@link
9301 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9302 *
9303 * @param subId the subscription ID of the phone requesting to set the radio power state.
9304 * @param enable {@code true} if trying to turn radio on.
9305 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9306 * false}.
9307 */
9308 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9309 Phone phone = getPhone(subId);
9310 if (phone != null) {
9311 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9312 return true;
9313 }
9314 return false;
9315 }
9316
9317 private int handleDataThrottlingRequest(int subId,
9318 DataThrottlingRequest dataThrottlingRequest) {
9319 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9320 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9321 if (!setRadioPowerForThermal(subId, true)) {
9322 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9323 }
9324
9325 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9326
9327 int thermalMitigationResult =
9328 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9329 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9330 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9331 }
9332 return thermalMitigationResult;
9333 }
9334
9335 /**
9336 * Thermal mitigation request to control functionalities at modem.
9337 *
9338 * @param subId the id of the subscription.
9339 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9340 *
9341 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9342 */
9343 @Override
9344 @ThermalMitigationResult
9345 public int sendThermalMitigationRequest(
9346 int subId,
9347 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9348 enforceModifyPermission();
9349
9350 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9351 final long identity = Binder.clearCallingIdentity();
9352
9353 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9354 try {
9355 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9356 switch (thermalMitigationAction) {
9357 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9358 thermalMitigationResult =
9359 handleDataThrottlingRequest(subId,
9360 thermalMitigationRequest.getDataThrottlingRequest());
9361 break;
9362 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9363 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9364 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9365 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9366 }
9367
9368 // Ensure that radio is on. If not able to power on due to phone being
9369 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9370 if (!setRadioPowerForThermal(subId, true)) {
9371 thermalMitigationResult =
9372 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9373 break;
9374 }
9375
9376 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9377 false);
9378 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9379 break;
9380 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9381 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9382 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9383 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9384 }
9385
9386 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9387 if (registry != null) {
9388 TelephonyConnectionService service =
9389 registry.getTelephonyConnectionService();
9390 Phone phone = getPhone(subId);
9391 if (phone == null) {
9392 thermalMitigationResult =
9393 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9394 break;
9395 }
9396
9397 if (PhoneConstantConversions.convertCallState(phone.getState())
9398 != TelephonyManager.CALL_STATE_IDLE
9399 || phone.isInEmergencySmsMode() || phone.isInEcm()
9400 || (service != null && service.isEmergencyCallPending())) {
9401 String errorMessage = "Phone state is not valid. call state = "
9402 + PhoneConstantConversions.convertCallState(phone.getState())
9403 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9404 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9405 errorMessage += service == null
9406 ? " TelephonyConnectionService is null"
9407 : " isEmergencyCallPending = "
9408 + service.isEmergencyCallPending();
9409 Log.e(LOG_TAG, errorMessage);
9410 thermalMitigationResult =
9411 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9412 break;
9413 }
9414 } else {
9415 thermalMitigationResult =
9416 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9417 break;
9418 }
9419
9420 // Turn radio off. If not able to power off due to phone being unavailable,
9421 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9422 if (!setRadioPowerForThermal(subId, false)) {
9423 thermalMitigationResult =
9424 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9425 break;
9426 }
9427 thermalMitigationResult =
9428 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9429 break;
9430 default:
9431 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9432 + "not exist. Requested action: " + thermalMitigationAction);
9433 }
9434 } catch (IllegalArgumentException e) {
9435 throw e;
9436 } catch (Exception e) {
9437 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9438 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9439 } finally {
9440 Binder.restoreCallingIdentity(identity);
9441 }
9442
9443 if (DBG) {
9444 log("thermalMitigationRequest returning with thermalMitigationResult: "
9445 + thermalMitigationResult);
9446 }
9447
9448 return thermalMitigationResult;
9449 }
Hui Wang641e81c2020-10-12 12:14:23 -07009450
9451 /**
9452 * Set the GbaService Package Name that Telephony will bind to.
9453 *
9454 * @param subId The sim that the GbaService is associated with.
9455 * @param packageName The name of the package to be replaced with.
9456 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9457 */
9458 @Override
9459 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9460 enforceModifyPermission();
9461
9462 final long identity = Binder.clearCallingIdentity();
9463 try {
9464 return getGbaManager(subId).overrideServicePackage(packageName);
9465 } finally {
9466 Binder.restoreCallingIdentity(identity);
9467 }
9468 }
9469
9470 /**
9471 * Return the package name of the currently bound GbaService.
9472 *
9473 * @param subId The sim that the GbaService is associated with.
9474 * @return the package name of the GbaService configuration, null if GBA is not supported.
9475 */
9476 @Override
9477 public String getBoundGbaService(int subId) {
9478 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9479
9480 final long identity = Binder.clearCallingIdentity();
9481 try {
9482 return getGbaManager(subId).getServicePackage();
9483 } finally {
9484 Binder.restoreCallingIdentity(identity);
9485 }
9486 }
9487
9488 /**
9489 * Set the release time for telephony to unbind GbaService.
9490 *
9491 * @param subId The sim that the GbaService is associated with.
9492 * @param interval The release time to unbind GbaService by millisecond.
9493 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9494 */
9495 @Override
9496 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9497 enforceModifyPermission();
9498
9499 final long identity = Binder.clearCallingIdentity();
9500 try {
9501 return getGbaManager(subId).overrideReleaseTime(interval);
9502 } finally {
9503 Binder.restoreCallingIdentity(identity);
9504 }
9505 }
9506
9507 /**
9508 * Return the release time for telephony to unbind GbaService.
9509 *
9510 * @param subId The sim that the GbaService is associated with.
9511 * @return The release time to unbind GbaService by millisecond.
9512 */
9513 @Override
9514 public int getGbaReleaseTime(int subId) {
9515 enforceReadPrivilegedPermission("getGbaReleaseTime");
9516
9517 final long identity = Binder.clearCallingIdentity();
9518 try {
9519 return getGbaManager(subId).getReleaseTime();
9520 } finally {
9521 Binder.restoreCallingIdentity(identity);
9522 }
9523 }
9524
9525 private GbaManager getGbaManager(int subId) {
9526 GbaManager instance = GbaManager.getInstance(subId);
9527 if (instance == null) {
9528 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9529 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9530 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9531 }
9532 return instance;
9533 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009534}