blob: ca295343c658c5de969a004c480183ac53d65432 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700313
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800314 // Parameters of select command.
315 private static final int SELECT_COMMAND = 0xA4;
316 private static final int SELECT_P1 = 0x04;
317 private static final int SELECT_P2 = 0;
318 private static final int SELECT_P3 = 0x10;
319
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700320 /** The singleton instance. */
321 private static PhoneInterfaceManager sInstance;
322
Wink Saville3ab207e2014-11-20 13:07:20 -0800323 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800324 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800325 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700326 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800327 private AppOpsManager mAppOps;
328 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800329 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800330 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700331 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332
Peter Wangdafb9ac2020-01-15 14:13:38 -0800333 /** User Activity */
334 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800335 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
336
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700337 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
338
Derek Tan97ebb422014-09-05 16:55:38 -0700339 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
340 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800341 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800342 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700343
Michelecea4cf22018-12-21 15:00:11 -0800344 // String to store multi SIM allowed
345 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
346
Derek Tan740e1672017-06-27 14:56:27 -0700347 // The AID of ISD-R.
348 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
349
yinxub1bed742017-04-17 11:45:04 -0700350 private NetworkScanRequestTracker mNetworkScanRequestTracker;
351
David Kelly5e06a7f2018-03-12 14:10:59 +0000352 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
353 private static final int MANUFACTURER_CODE_LENGTH = 8;
354
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800355 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
356
Derek Tan89e89d42014-07-08 17:00:10 -0700357 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700358 * Experiment flag to enable erase modem config on reset network, default value is false
359 */
360 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
361 "reset_network_erase_modem_config_enabled";
362
363 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700364 * A request object to use for transmitting data to an ICC.
365 */
366 private static final class IccAPDUArgument {
367 public int channel, cla, command, p1, p2, p3;
368 public String data;
369
370 public IccAPDUArgument(int channel, int cla, int command,
371 int p1, int p2, int p3, String data) {
372 this.channel = channel;
373 this.cla = cla;
374 this.command = command;
375 this.p1 = p1;
376 this.p2 = p2;
377 this.p3 = p3;
378 this.data = data;
379 }
380 }
381
382 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700383 * A request object to use for transmitting data to an ICC.
384 */
385 private static final class ManualNetworkSelectionArgument {
386 public OperatorInfo operatorInfo;
387 public boolean persistSelection;
388
389 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
390 this.operatorInfo = operatorInfo;
391 this.persistSelection = persistSelection;
392 }
393 }
394
395 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
397 * request after sending. The main thread will notify the request when it is complete.
398 */
399 private static final class MainThreadRequest {
400 /** The argument to use for the request */
401 public Object argument;
402 /** The result of the request that is run on the main thread */
403 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800404 // The subscriber id that this request applies to. Defaults to
405 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
406 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407
Nathan Harold92bed182018-10-12 18:16:49 -0700408 // In cases where subId is unavailable, the caller needs to specify the phone.
409 public Phone phone;
410
vagdeviaf9a5b92018-08-15 16:01:53 -0700411 public WorkSource workSource;
412
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 public MainThreadRequest(Object argument) {
414 this.argument = argument;
415 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800416
Nathan Harold92bed182018-10-12 18:16:49 -0700417 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
418 this.argument = argument;
419 if (phone != null) {
420 this.phone = phone;
421 }
422 this.workSource = workSource;
423 }
424
vagdeviaf9a5b92018-08-15 16:01:53 -0700425 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800426 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800427 if (subId != null) {
428 this.subId = subId;
429 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700430 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800431 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432 }
433
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800434 private static final class IncomingThirdPartyCallArgs {
435 public final ComponentName component;
436 public final String callId;
437 public final String callerDisplayName;
438
439 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
440 String callerDisplayName) {
441 this.component = component;
442 this.callId = callId;
443 this.callerDisplayName = callerDisplayName;
444 }
445 }
446
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700447 /**
448 * A handler that processes messages on the main thread in the phone process. Since many
449 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
450 * inbound binder threads to the main thread in the phone process. The Binder thread
451 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
452 * on, which will be notified when the operation completes and will contain the result of the
453 * request.
454 *
455 * <p>If a MainThreadRequest object is provided in the msg.obj field,
456 * note that request.result must be set to something non-null for the calling thread to
457 * unblock.
458 */
459 private final class MainThreadHandler extends Handler {
460 @Override
461 public void handleMessage(Message msg) {
462 MainThreadRequest request;
463 Message onCompleted;
464 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800465 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700466 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800467 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468
469 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700470 case CMD_HANDLE_USSD_REQUEST: {
471 request = (MainThreadRequest) msg.obj;
472 final Phone phone = getPhoneFromRequest(request);
473 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
474 String ussdRequest = ussdObject.first;
475 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700476
Pengquan Menga1bb6272018-09-06 09:59:22 -0700477 if (!isUssdApiAllowed(request.subId)) {
478 // Carrier does not support use of this API, return failure.
479 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
480 UssdResponse response = new UssdResponse(ussdRequest, null);
481 Bundle returnData = new Bundle();
482 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
483 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700484
Pengquan Menga1bb6272018-09-06 09:59:22 -0700485 request.result = true;
486 notifyRequester(request);
487 return;
488 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700489
Pengquan Menga1bb6272018-09-06 09:59:22 -0700490 try {
491 request.result = phone != null
492 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
493 } catch (CallStateException cse) {
494 request.result = false;
495 }
496 // Wake up the requesting thread
497 notifyRequester(request);
498 break;
pkanwar32d516d2016-10-14 19:37:38 -0700499 }
500
Yorke Lee716f67e2015-06-17 15:39:16 -0700501 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700502 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700503 final Phone phone = getPhoneFromRequest(request);
504 request.result = phone != null ?
505 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
506 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700507 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700508 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700511
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700512 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700513 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700514 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800515 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700516 if (uiccCard == null) {
517 loge("iccTransmitApduLogicalChannel: No UICC");
518 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700519 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700520 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700521 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
522 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700523 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 iccArgument.channel, iccArgument.cla, iccArgument.command,
525 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700526 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700527 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700528 break;
529
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700531 ar = (AsyncResult) msg.obj;
532 request = (MainThreadRequest) ar.userObj;
533 if (ar.exception == null && ar.result != null) {
534 request.result = ar.result;
535 } else {
536 request.result = new IccIoResult(0x6F, 0, (byte[])null);
537 if (ar.result == null) {
538 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800539 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700540 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800541 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700542 } else {
543 loge("iccTransmitApduLogicalChannel: Unknown exception");
544 }
545 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700546 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700547 break;
548
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700549 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
550 request = (MainThreadRequest) msg.obj;
551 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800552 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700553 if (uiccCard == null) {
554 loge("iccTransmitApduBasicChannel: No UICC");
555 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 } else {
558 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
559 request);
560 uiccCard.iccTransmitApduBasicChannel(
561 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
562 iccArgument.p3, iccArgument.data, onCompleted);
563 }
564 break;
565
566 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
567 ar = (AsyncResult) msg.obj;
568 request = (MainThreadRequest) ar.userObj;
569 if (ar.exception == null && ar.result != null) {
570 request.result = ar.result;
571 } else {
572 request.result = new IccIoResult(0x6F, 0, (byte[])null);
573 if (ar.result == null) {
574 loge("iccTransmitApduBasicChannel: Empty response");
575 } else if (ar.exception instanceof CommandException) {
576 loge("iccTransmitApduBasicChannel: CommandException: " +
577 ar.exception);
578 } else {
579 loge("iccTransmitApduBasicChannel: Unknown exception");
580 }
581 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700582 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700583 break;
584
585 case CMD_EXCHANGE_SIM_IO:
586 request = (MainThreadRequest) msg.obj;
587 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800588 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 if (uiccCard == null) {
590 loge("iccExchangeSimIO: No UICC");
591 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700593 } else {
594 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
595 request);
596 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
597 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
598 iccArgument.data, onCompleted);
599 }
600 break;
601
602 case EVENT_EXCHANGE_SIM_IO_DONE:
603 ar = (AsyncResult) msg.obj;
604 request = (MainThreadRequest) ar.userObj;
605 if (ar.exception == null && ar.result != null) {
606 request.result = ar.result;
607 } else {
608 request.result = new IccIoResult(0x6f, 0, (byte[])null);
609 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700610 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 break;
612
Derek Tan4d5e5c12014-02-04 11:54:58 -0800613 case CMD_SEND_ENVELOPE:
614 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800615 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700616 if (uiccCard == null) {
617 loge("sendEnvelopeWithStatus: No UICC");
618 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700620 } else {
621 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
622 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
623 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800624 break;
625
626 case EVENT_SEND_ENVELOPE_DONE:
627 ar = (AsyncResult) msg.obj;
628 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700629 if (ar.exception == null && ar.result != null) {
630 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800631 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700632 request.result = new IccIoResult(0x6F, 0, (byte[])null);
633 if (ar.result == null) {
634 loge("sendEnvelopeWithStatus: Empty response");
635 } else if (ar.exception instanceof CommandException) {
636 loge("sendEnvelopeWithStatus: CommandException: " +
637 ar.exception);
638 } else {
639 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
640 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800641 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700642 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800643 break;
644
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 case CMD_OPEN_CHANNEL:
646 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800647 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800648 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700649 if (uiccCard == null) {
650 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800651 request.result = new IccOpenLogicalChannelResponse(-1,
652 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700653 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700654 } else {
655 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800656 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
657 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700658 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 break;
660
661 case EVENT_OPEN_CHANNEL_DONE:
662 ar = (AsyncResult) msg.obj;
663 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700664 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700666 int[] result = (int[]) ar.result;
667 int channelId = result[0];
668 byte[] selectResponse = null;
669 if (result.length > 1) {
670 selectResponse = new byte[result.length - 1];
671 for (int i = 1; i < result.length; ++i) {
672 selectResponse[i - 1] = (byte) result[i];
673 }
674 }
675 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700676 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 if (ar.result == null) {
679 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700681 if (ar.exception != null) {
682 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
683 }
684
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700685 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700686 if (ar.exception instanceof CommandException) {
687 CommandException.Error error =
688 ((CommandException) (ar.exception)).getCommandError();
689 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700690 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700691 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700692 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700693 }
694 }
695 openChannelResp = new IccOpenLogicalChannelResponse(
696 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700698 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700699 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700700 break;
701
702 case CMD_CLOSE_CHANNEL:
703 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800704 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700705 if (uiccCard == null) {
706 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900707 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700708 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700709 } else {
710 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
711 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
712 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 break;
714
715 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800716 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
717 break;
718
719 case CMD_NV_READ_ITEM:
720 request = (MainThreadRequest) msg.obj;
721 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800722 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
723 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800724 break;
725
726 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700727 ar = (AsyncResult) msg.obj;
728 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800729 if (ar.exception == null && ar.result != null) {
730 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700731 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800732 request.result = "";
733 if (ar.result == null) {
734 loge("nvReadItem: Empty response");
735 } else if (ar.exception instanceof CommandException) {
736 loge("nvReadItem: CommandException: " +
737 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700738 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800739 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 }
741 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700742 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700743 break;
744
Jake Hambye994d462014-02-03 13:10:13 -0800745 case CMD_NV_WRITE_ITEM:
746 request = (MainThreadRequest) msg.obj;
747 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
748 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800749 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700750 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800751 break;
752
753 case EVENT_NV_WRITE_ITEM_DONE:
754 handleNullReturnEvent(msg, "nvWriteItem");
755 break;
756
757 case CMD_NV_WRITE_CDMA_PRL:
758 request = (MainThreadRequest) msg.obj;
759 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800760 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800761 break;
762
763 case EVENT_NV_WRITE_CDMA_PRL_DONE:
764 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
765 break;
766
chen xu6dac5ab2018-10-26 17:39:23 -0700767 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800768 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700769 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800770 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800771 break;
772
chen xu6dac5ab2018-10-26 17:39:23 -0700773 case EVENT_RESET_MODEM_CONFIG_DONE:
774 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800775 break;
776
Sooraj Sasindran37444802020-08-11 10:40:43 -0700777 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
778 request = (MainThreadRequest) msg.obj;
779 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
780 request);
781 Phone phone = getPhoneFromRequest(request);
782 if (phone != null) {
783 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
784 } else {
785 loge("isNRDualConnectivityEnabled: No phone object");
786 request.result = false;
787 notifyRequester(request);
788 }
789 break;
790 }
791
792 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
793 ar = (AsyncResult) msg.obj;
794 request = (MainThreadRequest) ar.userObj;
795 if (ar.exception == null && ar.result != null) {
796 request.result = ar.result;
797 } else {
798 // request.result must be set to something non-null
799 // for the calling thread to unblock
800 if (request.result != null) {
801 request.result = ar.result;
802 } else {
803 request.result = false;
804 }
805 if (ar.result == null) {
806 loge("isNRDualConnectivityEnabled: Empty response");
807 } else if (ar.exception instanceof CommandException) {
808 loge("isNRDualConnectivityEnabled: CommandException: "
809 + ar.exception);
810 } else {
811 loge("isNRDualConnectivityEnabled: Unknown exception");
812 }
813 }
814 notifyRequester(request);
815 break;
816
817 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
818 request = (MainThreadRequest) msg.obj;
819 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
820 Phone phone = getPhoneFromRequest(request);
821 if (phone != null) {
822 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
823 request.workSource);
824 } else {
825 loge("enableNrDualConnectivity: No phone object");
826 request.result =
827 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
828 notifyRequester(request);
829 }
830 break;
831 }
832
833 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
834 ar = (AsyncResult) msg.obj;
835 request = (MainThreadRequest) ar.userObj;
836 if (ar.exception == null) {
837 request.result =
838 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
839 } else {
840 request.result =
841 TelephonyManager
842 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
843 if (ar.exception instanceof CommandException) {
844 CommandException.Error error =
845 ((CommandException) (ar.exception)).getCommandError();
846 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
847 request.result =
848 TelephonyManager
849 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
850 }
851 loge("enableNrDualConnectivity" + ": CommandException: "
852 + ar.exception);
853 } else {
854 loge("enableNrDualConnectivity" + ": Unknown exception");
855 }
856 }
857 notifyRequester(request);
858 break;
859 }
860
Jake Hamby7c27be32014-03-03 13:25:59 -0800861 case CMD_GET_PREFERRED_NETWORK_TYPE:
862 request = (MainThreadRequest) msg.obj;
863 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700864 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800865 break;
866
867 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
868 ar = (AsyncResult) msg.obj;
869 request = (MainThreadRequest) ar.userObj;
870 if (ar.exception == null && ar.result != null) {
871 request.result = ar.result; // Integer
872 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530873 // request.result must be set to something non-null
874 // for the calling thread to unblock
875 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800876 if (ar.result == null) {
877 loge("getPreferredNetworkType: Empty response");
878 } else if (ar.exception instanceof CommandException) {
879 loge("getPreferredNetworkType: CommandException: " +
880 ar.exception);
881 } else {
882 loge("getPreferredNetworkType: Unknown exception");
883 }
884 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700885 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800886 break;
887
888 case CMD_SET_PREFERRED_NETWORK_TYPE:
889 request = (MainThreadRequest) msg.obj;
890 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
891 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700892 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800893 break;
894
895 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
896 handleNullReturnEvent(msg, "setPreferredNetworkType");
897 break;
898
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000899 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
900 request = (MainThreadRequest)msg.obj;
901 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800902 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000903 break;
904
905 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
906 ar = (AsyncResult)msg.obj;
907 request = (MainThreadRequest)ar.userObj;
908 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700909 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000910 break;
911
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800912 case CMD_SET_VOICEMAIL_NUMBER:
913 request = (MainThreadRequest) msg.obj;
914 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
915 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800916 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
917 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800918 break;
919
920 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
921 handleNullReturnEvent(msg, "setVoicemailNumber");
922 break;
923
Stuart Scott54788802015-03-30 13:18:01 -0700924 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
925 request = (MainThreadRequest) msg.obj;
926 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
927 request);
928 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
929 break;
930
931 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
932 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
933 break;
934
Shishir Agrawal302c8692015-06-19 13:49:39 -0700935 case CMD_PERFORM_NETWORK_SCAN:
936 request = (MainThreadRequest) msg.obj;
937 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
938 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
939 break;
940
Hall Liu27d24262020-09-18 19:04:59 -0700941 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800942 request = (MainThreadRequest) msg.obj;
943 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700944 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
945 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
946 request.argument;
947 int callForwardingReason = args.first;
948 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800949 break;
Hall Liu27d24262020-09-18 19:04:59 -0700950 }
951 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800952 ar = (AsyncResult) msg.obj;
953 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700954 TelephonyManager.CallForwardingInfoCallback callback =
955 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
956 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800957 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700958 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800959 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
960 for (CallForwardInfo callForwardInfo : callForwardInfos) {
961 // Service Class is a bit mask per 3gpp 27.007. Search for
962 // any service for voice call.
963 if ((callForwardInfo.serviceClass
964 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700965 callForwardingInfo = new CallForwardingInfo(true,
966 callForwardInfo.reason,
967 callForwardInfo.number,
968 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800969 break;
970 }
971 }
972 // Didn't find a call forward info for voice call.
973 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700974 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
975 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -0800976 }
Hall Liu27d24262020-09-18 19:04:59 -0700977 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -0800978 } else {
979 if (ar.result == null) {
980 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
981 }
982 if (ar.exception != null) {
983 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
984 }
Hall Liu940c4ca2020-09-29 17:10:18 -0700985 int errorCode = TelephonyManager
986 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -0800987 if (ar.exception instanceof CommandException) {
988 CommandException.Error error =
989 ((CommandException) (ar.exception)).getCommandError();
990 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700991 errorCode = TelephonyManager
992 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -0800993 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700994 errorCode = TelephonyManager
995 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -0800996 }
997 }
Hall Liu27d24262020-09-18 19:04:59 -0700998 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -0800999 }
Shuo Qian4a594052020-01-23 11:59:30 -08001000 break;
Hall Liu27d24262020-09-18 19:04:59 -07001001 }
Shuo Qian4a594052020-01-23 11:59:30 -08001002
Hall Liu27d24262020-09-18 19:04:59 -07001003 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001004 request = (MainThreadRequest) msg.obj;
1005 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001006 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001007 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001008 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1009 request.argument).first;
1010 request.phone.setCallForwardingOption(
1011 callForwardingInfoToSet.isEnabled()
1012 ? CommandsInterface.CF_ACTION_ENABLE
1013 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001014 callForwardingInfoToSet.getReason(),
1015 callForwardingInfoToSet.getNumber(),
1016 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1017 break;
Hall Liu27d24262020-09-18 19:04:59 -07001018 }
Shuo Qian4a594052020-01-23 11:59:30 -08001019
Hall Liu27d24262020-09-18 19:04:59 -07001020 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001021 ar = (AsyncResult) msg.obj;
1022 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001023 Consumer<Integer> callback =
1024 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1025 request.argument).second;
1026 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001027 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001028 int errorCode = TelephonyManager.CallForwardingInfoCallback
1029 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001030 if (ar.exception instanceof CommandException) {
1031 CommandException.Error error =
1032 ((CommandException) (ar.exception)).getCommandError();
1033 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001034 errorCode = TelephonyManager.CallForwardingInfoCallback
1035 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001036 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001037 errorCode = TelephonyManager.CallForwardingInfoCallback
1038 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001039 }
1040 }
1041 callback.accept(errorCode);
1042 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001043 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001044 }
Shuo Qian4a594052020-01-23 11:59:30 -08001045 break;
Hall Liu27d24262020-09-18 19:04:59 -07001046 }
Shuo Qian4a594052020-01-23 11:59:30 -08001047
Hall Liu27d24262020-09-18 19:04:59 -07001048 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001049 request = (MainThreadRequest) msg.obj;
1050 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1051 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1052 break;
Hall Liu27d24262020-09-18 19:04:59 -07001053 }
Shuo Qian4a594052020-01-23 11:59:30 -08001054
Hall Liu27d24262020-09-18 19:04:59 -07001055 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001056 ar = (AsyncResult) msg.obj;
1057 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001058 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001059 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1060 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001061 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001062 // Service Class is a bit mask per 3gpp 27.007.
1063 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001064 if (callForwardResults.length > 1
1065 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001066 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001067 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001068 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1069 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001070 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001071 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001072 }
1073 } else {
1074 if (ar.result == null) {
1075 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1076 }
1077 if (ar.exception != null) {
1078 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1079 }
1080 if (ar.exception instanceof CommandException) {
1081 CommandException.Error error =
1082 ((CommandException) (ar.exception)).getCommandError();
1083 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1084 callForwardingStatus =
1085 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1086 }
1087 }
1088 }
Hall Liu27d24262020-09-18 19:04:59 -07001089 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001090 break;
Hall Liu27d24262020-09-18 19:04:59 -07001091 }
Shuo Qian4a594052020-01-23 11:59:30 -08001092
Hall Liu27d24262020-09-18 19:04:59 -07001093 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001094 request = (MainThreadRequest) msg.obj;
1095 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001096 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1097 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001098 break;
Hall Liu27d24262020-09-18 19:04:59 -07001099 }
Shuo Qian4a594052020-01-23 11:59:30 -08001100
Hall Liu27d24262020-09-18 19:04:59 -07001101 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001102 ar = (AsyncResult) msg.obj;
1103 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001104 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1105 Consumer<Integer> callback =
1106 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1107 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001108 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001109 if (ar.exception instanceof CommandException) {
1110 CommandException.Error error =
1111 ((CommandException) (ar.exception)).getCommandError();
1112 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1113 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1114 } else {
1115 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1116 }
1117 } else {
1118 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1119 }
1120 } else {
1121 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1122 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001123 }
Shuo Qian4a594052020-01-23 11:59:30 -08001124 break;
Hall Liu27d24262020-09-18 19:04:59 -07001125 }
Shuo Qian4a594052020-01-23 11:59:30 -08001126
Shishir Agrawal302c8692015-06-19 13:49:39 -07001127 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1128 ar = (AsyncResult) msg.obj;
1129 request = (MainThreadRequest) ar.userObj;
1130 CellNetworkScanResult cellScanResult;
1131 if (ar.exception == null && ar.result != null) {
1132 cellScanResult = new CellNetworkScanResult(
1133 CellNetworkScanResult.STATUS_SUCCESS,
1134 (List<OperatorInfo>) ar.result);
1135 } else {
1136 if (ar.result == null) {
1137 loge("getCellNetworkScanResults: Empty response");
1138 }
1139 if (ar.exception != null) {
1140 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1141 }
1142 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1143 if (ar.exception instanceof CommandException) {
1144 CommandException.Error error =
1145 ((CommandException) (ar.exception)).getCommandError();
1146 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1147 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1148 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1149 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1150 }
1151 }
1152 cellScanResult = new CellNetworkScanResult(errorCode, null);
1153 }
1154 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001155 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001156 break;
1157
1158 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1159 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001160 ManualNetworkSelectionArgument selArg =
1161 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001162 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1163 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001164 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1165 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001166 break;
1167
1168 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001169 ar = (AsyncResult) msg.obj;
1170 request = (MainThreadRequest) ar.userObj;
1171 if (ar.exception == null) {
1172 request.result = true;
1173 } else {
1174 request.result = false;
1175 loge("setNetworkSelectionModeManual " + ar.exception);
1176 }
1177 notifyRequester(request);
1178 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001179 break;
1180
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001181 case CMD_GET_MODEM_ACTIVITY_INFO:
1182 request = (MainThreadRequest) msg.obj;
1183 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001184 if (defaultPhone != null) {
1185 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001186 } else {
1187 ResultReceiver result = (ResultReceiver) request.argument;
1188 Bundle bundle = new Bundle();
1189 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001190 new ModemActivityInfo(0, 0, 0,
1191 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001192 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001193 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001194 break;
1195
Hall Liud0f208c2020-10-14 16:54:44 -07001196 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001197 ar = (AsyncResult) msg.obj;
1198 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001199 ResultReceiver result = (ResultReceiver) request.argument;
1200
Hall Liud0f208c2020-10-14 16:54:44 -07001201 ModemActivityInfo ret = null;
1202 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001203 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001204 // Update the last modem activity info and the result of the request.
1205 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1206 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001207 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001208 int[] txTimeMs = info.getTransmitTimeMillis();
1209 int[] lastModemTxTimeMs = mLastModemActivityInfo
1210 .getTransmitTimeMillis();
1211 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1212 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1213 }
Hall Liu49656c02020-10-09 19:00:11 -07001214 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001215 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1216 + mLastModemActivityInfo.getSleepTimeMillis());
1217 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1218 + mLastModemActivityInfo.getIdleTimeMillis());
1219 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1220 mLastModemActivityInfo.setReceiveTimeMillis(
1221 info.getReceiveTimeMillis()
1222 + mLastModemActivityInfo.getReceiveTimeMillis());
1223 }
Hall Liu49656c02020-10-09 19:00:11 -07001224 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001225 mLastModemActivityInfo.getSleepTimeMillis(),
1226 mLastModemActivityInfo.getIdleTimeMillis(),
1227 mLastModemActivityInfo.getTransmitTimeMillis(),
1228 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001229 } else {
1230 if (ar.result == null) {
1231 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001232 error = TelephonyManager.ModemActivityInfoException
1233 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001234 } else if (ar.exception instanceof CommandException) {
1235 loge("queryModemActivityInfo: CommandException: " +
1236 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001237 error = TelephonyManager.ModemActivityInfoException
1238 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001239 } else {
1240 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001241 error = TelephonyManager.ModemActivityInfoException
1242 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001243 }
1244 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001245 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001246 if (ret != null) {
1247 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1248 } else {
1249 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1250 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001251 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001252 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001253 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001254 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001255
Meng Wang1a7c35a2016-05-05 20:56:15 -07001256 case CMD_SET_ALLOWED_CARRIERS:
1257 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001258 CarrierRestrictionRules argument =
1259 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001260 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001261 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001262 break;
1263
1264 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1265 ar = (AsyncResult) msg.obj;
1266 request = (MainThreadRequest) ar.userObj;
1267 if (ar.exception == null && ar.result != null) {
1268 request.result = ar.result;
1269 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001270 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1271 if (ar.exception instanceof CommandException) {
1272 loge("setAllowedCarriers: CommandException: " + ar.exception);
1273 CommandException.Error error =
1274 ((CommandException) (ar.exception)).getCommandError();
1275 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1276 request.result =
1277 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1278 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001279 } else {
1280 loge("setAllowedCarriers: Unknown exception");
1281 }
1282 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001283 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001284 break;
1285
1286 case CMD_GET_ALLOWED_CARRIERS:
1287 request = (MainThreadRequest) msg.obj;
1288 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001289 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001290 break;
1291
1292 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1293 ar = (AsyncResult) msg.obj;
1294 request = (MainThreadRequest) ar.userObj;
1295 if (ar.exception == null && ar.result != null) {
1296 request.result = ar.result;
1297 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001298 request.result = new IllegalStateException(
1299 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001300 if (ar.result == null) {
1301 loge("getAllowedCarriers: Empty response");
1302 } else if (ar.exception instanceof CommandException) {
1303 loge("getAllowedCarriers: CommandException: " +
1304 ar.exception);
1305 } else {
1306 loge("getAllowedCarriers: Unknown exception");
1307 }
1308 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001309 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001310 break;
1311
Nathan Haroldb3014052017-01-25 15:57:32 -08001312 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1313 ar = (AsyncResult) msg.obj;
1314 request = (MainThreadRequest) ar.userObj;
1315 if (ar.exception == null && ar.result != null) {
1316 request.result = ar.result;
1317 } else {
1318 request.result = new IllegalArgumentException(
1319 "Failed to retrieve Forbidden Plmns");
1320 if (ar.result == null) {
1321 loge("getForbiddenPlmns: Empty response");
1322 } else {
1323 loge("getForbiddenPlmns: Unknown exception");
1324 }
1325 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001326 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001327 break;
1328
1329 case CMD_GET_FORBIDDEN_PLMNS:
1330 request = (MainThreadRequest) msg.obj;
1331 uiccCard = getUiccCardFromRequest(request);
1332 if (uiccCard == null) {
1333 loge("getForbiddenPlmns() UiccCard is null");
1334 request.result = new IllegalArgumentException(
1335 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001336 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001337 break;
1338 }
1339 Integer appType = (Integer) request.argument;
1340 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1341 if (uiccApp == null) {
1342 loge("getForbiddenPlmns() no app with specified type -- "
1343 + appType);
1344 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001345 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001346 break;
1347 } else {
1348 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1349 + " specified type -- " + appType);
1350 }
1351 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1352 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1353 onCompleted);
1354 break;
1355
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001356 case CMD_SWITCH_SLOTS:
1357 request = (MainThreadRequest) msg.obj;
1358 int[] physicalSlots = (int[]) request.argument;
1359 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1360 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1361 break;
1362
1363 case EVENT_SWITCH_SLOTS_DONE:
1364 ar = (AsyncResult) msg.obj;
1365 request = (MainThreadRequest) ar.userObj;
1366 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001367 notifyRequester(request);
1368 break;
1369 case CMD_GET_NETWORK_SELECTION_MODE:
1370 request = (MainThreadRequest) msg.obj;
1371 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1372 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1373 break;
1374
1375 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1376 ar = (AsyncResult) msg.obj;
1377 request = (MainThreadRequest) ar.userObj;
1378 if (ar.exception != null) {
1379 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1380 } else {
1381 int mode = ((int[]) ar.result)[0];
1382 if (mode == 0) {
1383 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1384 } else {
1385 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1386 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001387 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001388 notifyRequester(request);
1389 break;
1390 case CMD_GET_CDMA_ROAMING_MODE:
1391 request = (MainThreadRequest) msg.obj;
1392 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1393 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1394 break;
1395 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1396 ar = (AsyncResult) msg.obj;
1397 request = (MainThreadRequest) ar.userObj;
1398 if (ar.exception != null) {
1399 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1400 } else {
1401 request.result = ((int[]) ar.result)[0];
1402 }
1403 notifyRequester(request);
1404 break;
1405 case CMD_SET_CDMA_ROAMING_MODE:
1406 request = (MainThreadRequest) msg.obj;
1407 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1408 int mode = (int) request.argument;
1409 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1410 break;
1411 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1412 ar = (AsyncResult) msg.obj;
1413 request = (MainThreadRequest) ar.userObj;
1414 request.result = ar.exception == null;
1415 notifyRequester(request);
1416 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001417 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1418 request = (MainThreadRequest) msg.obj;
1419 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1420 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1421 break;
1422 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1423 ar = (AsyncResult) msg.obj;
1424 request = (MainThreadRequest) ar.userObj;
1425 if (ar.exception != null) {
1426 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1427 } else {
1428 request.result = ((int[]) ar.result)[0];
1429 }
1430 notifyRequester(request);
1431 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001432 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1433 request = (MainThreadRequest) msg.obj;
1434 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1435 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001436 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1437 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001438 break;
1439 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1440 ar = (AsyncResult) msg.obj;
1441 request = (MainThreadRequest) ar.userObj;
1442 request.result = ar.exception == null;
1443 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001444 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001445 case CMD_GET_ALL_CELL_INFO:
1446 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001447 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001448 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001449 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001450 case EVENT_GET_ALL_CELL_INFO_DONE:
1451 ar = (AsyncResult) msg.obj;
1452 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001453 // If a timeout occurs, the response will be null
1454 request.result = (ar.exception == null && ar.result != null)
1455 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001456 synchronized (request) {
1457 request.notifyAll();
1458 }
1459 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001460 case CMD_REQUEST_CELL_INFO_UPDATE:
1461 request = (MainThreadRequest) msg.obj;
1462 request.phone.requestCellInfoUpdate(request.workSource,
1463 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1464 break;
1465 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1466 ar = (AsyncResult) msg.obj;
1467 request = (MainThreadRequest) ar.userObj;
1468 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1469 try {
1470 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001471 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001472 cb.onError(
1473 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1474 ar.exception.getClass().getName(),
1475 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001476 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001477 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001478 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001479 } else {
1480 // use the result as returned
1481 cb.onCellInfo((List<CellInfo>) ar.result);
1482 }
1483 } catch (RemoteException re) {
1484 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1485 }
1486 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001487 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001488 request = (MainThreadRequest) msg.obj;
1489 WorkSource ws = (WorkSource) request.argument;
1490 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001491 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001492 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001493 }
1494 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001495 ar = (AsyncResult) msg.obj;
1496 request = (MainThreadRequest) ar.userObj;
1497 if (ar.exception == null) {
1498 request.result = ar.result;
1499 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001500 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001501 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001502 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001503 }
1504
1505 synchronized (request) {
1506 request.notifyAll();
1507 }
1508 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001509 }
chen xu6dac5ab2018-10-26 17:39:23 -07001510 case CMD_MODEM_REBOOT:
1511 request = (MainThreadRequest) msg.obj;
1512 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001513 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001514 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001515 case EVENT_CMD_MODEM_REBOOT_DONE:
1516 handleNullReturnEvent(msg, "rebootModem");
1517 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001518 case CMD_REQUEST_ENABLE_MODEM:
1519 request = (MainThreadRequest) msg.obj;
1520 boolean enable = (boolean) request.argument;
1521 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001522 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001523 PhoneConfigurationManager.getInstance()
1524 .enablePhone(request.phone, enable, onCompleted);
1525 break;
1526 case EVENT_ENABLE_MODEM_DONE:
1527 ar = (AsyncResult) msg.obj;
1528 request = (MainThreadRequest) ar.userObj;
1529 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001530 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001531 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001532 if ((boolean) request.result) {
1533 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1534 updateModemStateMetrics();
1535 } else {
1536 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1537 + ar.exception);
1538 }
1539 notifyRequester(request);
1540 break;
1541 case CMD_GET_MODEM_STATUS:
1542 request = (MainThreadRequest) msg.obj;
1543 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1544 PhoneConfigurationManager.getInstance()
1545 .getPhoneStatusFromModem(request.phone, onCompleted);
1546 break;
1547 case EVENT_GET_MODEM_STATUS_DONE:
1548 ar = (AsyncResult) msg.obj;
1549 request = (MainThreadRequest) ar.userObj;
1550 int id = request.phone.getPhoneId();
1551 if (ar.exception == null && ar.result != null) {
1552 request.result = ar.result;
1553 //update the cache as modem status has changed
1554 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1555 (boolean) request.result);
1556 } else {
1557 // Return true if modem status cannot be retrieved. For most cases,
1558 // modem status is on. And for older version modems, GET_MODEM_STATUS
1559 // and disable modem are not supported. Modem is always on.
1560 // TODO: this should be fixed in R to support a third
1561 // status UNKNOWN b/131631629
1562 request.result = true;
1563 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1564 + ar.exception);
1565 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001566 notifyRequester(request);
1567 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001568 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1569 request = (MainThreadRequest) msg.obj;
1570 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1571 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1572 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1573 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1574 break;
1575 }
1576 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1577 ar = (AsyncResult) msg.obj;
1578 request = (MainThreadRequest) ar.userObj;
1579 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1580 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1581 args.second.accept(ar.exception == null);
1582 notifyRequester(request);
1583 break;
1584 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001585 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1586 request = (MainThreadRequest) msg.obj;
1587 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1588 Phone phone = getPhoneFromRequest(request);
1589 if (phone != null) {
1590 phone.getSystemSelectionChannels(onCompleted);
1591 } else {
1592 loge("getSystemSelectionChannels: No phone object");
1593 request.result = new ArrayList<RadioAccessSpecifier>();
1594 notifyRequester(request);
1595 }
1596 break;
1597 }
1598 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1599 ar = (AsyncResult) msg.obj;
1600 request = (MainThreadRequest) ar.userObj;
1601 if (ar.exception == null && ar.result != null) {
1602 request.result = ar.result;
1603 } else {
1604 request.result = new IllegalArgumentException(
1605 "Failed to retrieve system selection channels");
1606 if (ar.result == null) {
1607 loge("getSystemSelectionChannels: Empty response");
1608 } else {
1609 loge("getSystemSelectionChannels: Unknown exception");
1610 }
1611 }
1612 notifyRequester(request);
1613 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001614 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1615 ar = (AsyncResult) msg.obj;
1616 request = (MainThreadRequest) ar.userObj;
1617 if (ar.exception == null && ar.result != null) {
1618 request.result = ar.result;
1619 } else {
1620 request.result = -1;
1621 loge("Failed to set Forbidden Plmns");
1622 if (ar.result == null) {
1623 loge("setForbidenPlmns: Empty response");
1624 } else if (ar.exception != null) {
1625 loge("setForbiddenPlmns: Exception: " + ar.exception);
1626 request.result = -1;
1627 } else {
1628 loge("setForbiddenPlmns: Unknown exception");
1629 }
1630 }
1631 notifyRequester(request);
1632 break;
1633 case CMD_SET_FORBIDDEN_PLMNS:
1634 request = (MainThreadRequest) msg.obj;
1635 uiccCard = getUiccCardFromRequest(request);
1636 if (uiccCard == null) {
1637 loge("setForbiddenPlmns: UiccCard is null");
1638 request.result = -1;
1639 notifyRequester(request);
1640 break;
1641 }
1642 Pair<Integer, List<String>> setFplmnsArgs =
1643 (Pair<Integer, List<String>>) request.argument;
1644 appType = setFplmnsArgs.first;
1645 List<String> fplmns = setFplmnsArgs.second;
1646 uiccApp = uiccCard.getApplicationByType(appType);
1647 if (uiccApp == null) {
1648 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1649 request.result = -1;
1650 loge("Failed to get UICC App");
1651 notifyRequester(request);
1652 } else {
1653 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1654 ((SIMRecords) uiccApp.getIccRecords())
1655 .setForbiddenPlmns(onCompleted, fplmns);
1656 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001657 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001658 case CMD_ERASE_MODEM_CONFIG:
1659 request = (MainThreadRequest) msg.obj;
1660 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1661 defaultPhone.eraseModemConfig(onCompleted);
1662 break;
1663 case EVENT_ERASE_MODEM_CONFIG_DONE:
1664 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001665 break;
zoey chene02881a2019-12-30 16:11:23 +08001666
1667 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1668 request = (MainThreadRequest) msg.obj;
1669 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1670 Pair<String, String> changed = (Pair<String, String>) request.argument;
1671 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1672 changed.first, changed.second, onCompleted);
1673 break;
1674 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1675 ar = (AsyncResult) msg.obj;
1676 request = (MainThreadRequest) ar.userObj;
1677 if (ar.exception == null) {
1678 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1679 } else {
1680 request.result = msg.arg1;
1681 }
1682 notifyRequester(request);
1683 break;
1684
1685 case CMD_SET_ICC_LOCK_ENABLED:
1686 request = (MainThreadRequest) msg.obj;
1687 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1688 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1689 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1690 enabled.first, enabled.second, onCompleted);
1691 break;
1692 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1693 ar = (AsyncResult) msg.obj;
1694 request = (MainThreadRequest) ar.userObj;
1695 if (ar.exception == null) {
1696 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1697 } else {
1698 request.result = msg.arg1;
1699 }
1700 notifyRequester(request);
1701 break;
1702
Peter Wangdafb9ac2020-01-15 14:13:38 -08001703 case MSG_NOTIFY_USER_ACTIVITY:
1704 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001705 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001706 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1707 getDefaultPhone().getContext().sendBroadcastAsUser(
1708 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1709 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001710
1711 case CMD_SET_DATA_THROTTLING: {
1712 request = (MainThreadRequest) msg.obj;
1713 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1714 DataThrottlingRequest dataThrottlingRequest =
1715 (DataThrottlingRequest) request.argument;
1716 Phone phone = getPhoneFromRequest(request);
1717 if (phone != null) {
1718 phone.setDataThrottling(onCompleted,
1719 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1720 dataThrottlingRequest.getCompletionDurationMillis());
1721 } else {
1722 loge("setDataThrottling: No phone object");
1723 request.result =
1724 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1725 notifyRequester(request);
1726 }
1727
1728 break;
1729 }
1730 case EVENT_SET_DATA_THROTTLING_DONE:
1731 ar = (AsyncResult) msg.obj;
1732 request = (MainThreadRequest) ar.userObj;
1733
1734 if (ar.exception == null) {
1735 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1736 } else if (ar.exception instanceof CommandException) {
1737 loge("setDataThrottling: CommandException: " + ar.exception);
1738 CommandException.Error error =
1739 ((CommandException) (ar.exception)).getCommandError();
1740
1741 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1742 request.result = TelephonyManager
1743 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1744 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1745 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1746 } else {
1747 request.result =
1748 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1749 }
1750 } else {
1751 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1752 }
1753 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1754 notifyRequester(request);
1755 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 default:
1757 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1758 break;
1759 }
1760 }
Jake Hambye994d462014-02-03 13:10:13 -08001761
Pengquan Menga1bb6272018-09-06 09:59:22 -07001762 private void notifyRequester(MainThreadRequest request) {
1763 synchronized (request) {
1764 request.notifyAll();
1765 }
1766 }
1767
Jake Hambye994d462014-02-03 13:10:13 -08001768 private void handleNullReturnEvent(Message msg, String command) {
1769 AsyncResult ar = (AsyncResult) msg.obj;
1770 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1771 if (ar.exception == null) {
1772 request.result = true;
1773 } else {
1774 request.result = false;
1775 if (ar.exception instanceof CommandException) {
1776 loge(command + ": CommandException: " + ar.exception);
1777 } else {
1778 loge(command + ": Unknown exception");
1779 }
1780 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001781 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001782 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001783 }
1784
1785 /**
1786 * Posts the specified command to be executed on the main thread,
1787 * waits for the request to complete, and returns the result.
1788 * @see #sendRequestAsync
1789 */
1790 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001791 return sendRequest(
1792 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001793 }
1794
1795 /**
1796 * Posts the specified command to be executed on the main thread,
1797 * waits for the request to complete, and returns the result.
1798 * @see #sendRequestAsync
1799 */
1800 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1801 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001802 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001803 }
1804
1805 /**
1806 * Posts the specified command to be executed on the main thread,
1807 * waits for the request to complete, and returns the result.
1808 * @see #sendRequestAsync
1809 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001810 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001811 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001812 }
1813
1814 /**
1815 * Posts the specified command to be executed on the main thread,
1816 * waits for the request to complete, and returns the result.
1817 * @see #sendRequestAsync
1818 */
Nathan Harold92bed182018-10-12 18:16:49 -07001819 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1820 return sendRequest(command, argument, subId, null, workSource);
1821 }
1822
1823 /**
1824 * Posts the specified command to be executed on the main thread,
1825 * waits for the request to complete, and returns the result.
1826 * @see #sendRequestAsync
1827 */
1828 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1829 return sendRequest(
1830 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1831 }
1832
1833 /**
1834 * Posts the specified command to be executed on the main thread,
1835 * waits for the request to complete, and returns the result.
1836 * @see #sendRequestAsync
1837 */
1838 private Object sendRequest(
1839 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1841 throw new RuntimeException("This method will deadlock if called from the main thread.");
1842 }
1843
Nathan Harold92bed182018-10-12 18:16:49 -07001844 MainThreadRequest request = null;
1845 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1846 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1847 } else if (phone != null) {
1848 request = new MainThreadRequest(argument, phone, workSource);
1849 } else {
1850 request = new MainThreadRequest(argument, subId, workSource);
1851 }
1852
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001853 Message msg = mMainThreadHandler.obtainMessage(command, request);
1854 msg.sendToTarget();
1855
1856 // Wait for the request to complete
1857 synchronized (request) {
1858 while (request.result == null) {
1859 try {
1860 request.wait();
1861 } catch (InterruptedException e) {
1862 // Do nothing, go back and wait until the request is complete
1863 }
1864 }
1865 }
1866 return request.result;
1867 }
1868
1869 /**
1870 * Asynchronous ("fire and forget") version of sendRequest():
1871 * Posts the specified command to be executed on the main thread, and
1872 * returns immediately.
1873 * @see #sendRequest
1874 */
1875 private void sendRequestAsync(int command) {
1876 mMainThreadHandler.sendEmptyMessage(command);
1877 }
1878
1879 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001880 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001881 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001882 */
1883 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001884 sendRequestAsync(command, argument, null, null);
1885 }
1886
1887 /**
1888 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1889 * @see {@link #sendRequest(int,Object)}
1890 */
1891 private void sendRequestAsync(
1892 int command, Object argument, Phone phone, WorkSource workSource) {
1893 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001894 Message msg = mMainThreadHandler.obtainMessage(command, request);
1895 msg.sendToTarget();
1896 }
1897
1898 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899 * Initialize the singleton PhoneInterfaceManager instance.
1900 * This is only done once, at startup, from PhoneApp.onCreate().
1901 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001902 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 synchronized (PhoneInterfaceManager.class) {
1904 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001905 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001906 } else {
1907 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1908 }
1909 return sInstance;
1910 }
1911 }
1912
1913 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001914 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001917 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001918 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001919 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1920 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001921 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001922 mTelephonySharedPreferences =
1923 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001924 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001925 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001926 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001927
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001928 publish();
1929 }
1930
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001931 private Phone getDefaultPhone() {
1932 Phone thePhone = getPhone(getDefaultSubscription());
1933 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1934 }
1935
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 private void publish() {
1937 if (DBG) log("publish: " + this);
1938
Peter Wangc035ce42020-01-08 21:00:22 -08001939 TelephonyFrameworkInitializer
1940 .getTelephonyServiceManager()
1941 .getTelephonyServiceRegisterer()
1942 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 }
1944
Stuart Scott584921c2015-01-15 17:10:34 -08001945 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001946 if (request.phone != null) {
1947 return request.phone;
1948 } else {
1949 return getPhoneFromSubId(request.subId);
1950 }
1951 }
1952
1953 private Phone getPhoneFromSubId(int subId) {
1954 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1955 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001956 }
1957
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001958 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1959 Phone phone = getPhoneFromRequest(request);
1960 return phone == null ? null :
1961 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1962 }
1963
Wink Saville36469e72014-06-11 15:17:00 -07001964 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001965 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001966 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968
Naina Nallurid63128d2019-09-17 14:10:30 -07001969 private void sendEraseModemConfig(Phone phone) {
1970 if (phone != null) {
1971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1972 mApp, phone.getSubId(), "eraseModemConfig");
1973 final long identity = Binder.clearCallingIdentity();
1974 try {
1975 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1976 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1977 } finally {
1978 Binder.restoreCallingIdentity(identity);
1979 }
1980 }
1981 }
1982
Peter Wang44b186e2020-01-13 23:33:09 -08001983 private boolean isImsAvailableOnDevice() {
1984 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1985 if (pm == null) {
1986 // For some reason package manger is not available.. This will fail internally anyway,
1987 // so do not throw error and allow.
1988 return true;
1989 }
1990 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1991 }
1992
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001993 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001994 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001995 }
1996
Wink Savilleb564aae2014-10-23 10:18:09 -07001997 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001998 if (DBG) log("dial: " + number);
1999 // No permission check needed here: This is just a wrapper around the
2000 // ACTION_DIAL intent, which is available to any app since it puts up
2001 // the UI before it does anything.
2002
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002003 final long identity = Binder.clearCallingIdentity();
2004 try {
2005 String url = createTelUrl(number);
2006 if (url == null) {
2007 return;
2008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002010 // PENDING: should we just silently fail if phone is offhook or ringing?
2011 PhoneConstants.State state = mCM.getState(subId);
2012 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2013 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2014 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2015 mApp.startActivity(intent);
2016 }
2017 } finally {
2018 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002019 }
2020 }
2021
2022 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002023 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002024 }
2025
Wink Savilleb564aae2014-10-23 10:18:09 -07002026 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002027 if (DBG) log("call: " + number);
2028
2029 // This is just a wrapper around the ACTION_CALL intent, but we still
2030 // need to do a permission check since we're calling startActivity()
2031 // from the context of the phone app.
2032 enforceCallPermission();
2033
Jordan Liu1617b712019-07-10 15:06:26 -07002034 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002035 != AppOpsManager.MODE_ALLOWED) {
2036 return;
2037 }
2038
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002039 final long identity = Binder.clearCallingIdentity();
2040 try {
2041 String url = createTelUrl(number);
2042 if (url == null) {
2043 return;
2044 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002046 boolean isValid = false;
2047 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2048 if (slist != null) {
2049 for (SubscriptionInfo subInfoRecord : slist) {
2050 if (subInfoRecord.getSubscriptionId() == subId) {
2051 isValid = true;
2052 break;
2053 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002054 }
Wink Saville08874612014-08-31 19:19:58 -07002055 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002056 if (!isValid) {
2057 return;
2058 }
Wink Saville08874612014-08-31 19:19:58 -07002059
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002060 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2061 intent.putExtra(SUBSCRIPTION_KEY, subId);
2062 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2063 mApp.startActivity(intent);
2064 } finally {
2065 Binder.restoreCallingIdentity(identity);
2066 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002067 }
2068
Wink Savilleb564aae2014-10-23 10:18:09 -07002069 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002070 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002071 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2072 }
2073
Wink Savilleb564aae2014-10-23 10:18:09 -07002074 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002075 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002076 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2077 }
2078
Wink Savilleb564aae2014-10-23 10:18:09 -07002079 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002080 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002081
2082 final long identity = Binder.clearCallingIdentity();
2083 try {
2084 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2085 checkSimPin.start();
2086 return checkSimPin.unlockSim(null, pin);
2087 } finally {
2088 Binder.restoreCallingIdentity(identity);
2089 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 }
2091
Wink Savilleb564aae2014-10-23 10:18:09 -07002092 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002094
2095 final long identity = Binder.clearCallingIdentity();
2096 try {
2097 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2098 checkSimPuk.start();
2099 return checkSimPuk.unlockSim(puk, pin);
2100 } finally {
2101 Binder.restoreCallingIdentity(identity);
2102 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002103 }
2104
2105 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002106 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 * a synchronous one.
2108 */
2109 private static class UnlockSim extends Thread {
2110
2111 private final IccCard mSimCard;
2112
2113 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002114 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2115 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002116
2117 // For replies from SimCard interface
2118 private Handler mHandler;
2119
2120 // For async handler to identify request type
2121 private static final int SUPPLY_PIN_COMPLETE = 100;
2122
2123 public UnlockSim(IccCard simCard) {
2124 mSimCard = simCard;
2125 }
2126
2127 @Override
2128 public void run() {
2129 Looper.prepare();
2130 synchronized (UnlockSim.this) {
2131 mHandler = new Handler() {
2132 @Override
2133 public void handleMessage(Message msg) {
2134 AsyncResult ar = (AsyncResult) msg.obj;
2135 switch (msg.what) {
2136 case SUPPLY_PIN_COMPLETE:
2137 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2138 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002139 mRetryCount = msg.arg1;
2140 if (ar.exception != null) {
2141 if (ar.exception instanceof CommandException &&
2142 ((CommandException)(ar.exception)).getCommandError()
2143 == CommandException.Error.PASSWORD_INCORRECT) {
2144 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002145 } //When UiccCardApp dispose,handle message and return exception
2146 else if (ar.exception instanceof CommandException &&
2147 ((CommandException) (ar.exception)).getCommandError()
2148 == CommandException.Error.ABORTED) {
2149 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002150 } else {
2151 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2152 }
2153 } else {
2154 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2155 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 mDone = true;
2157 UnlockSim.this.notifyAll();
2158 }
2159 break;
2160 }
2161 }
2162 };
2163 UnlockSim.this.notifyAll();
2164 }
2165 Looper.loop();
2166 }
2167
2168 /*
2169 * Use PIN or PUK to unlock SIM card
2170 *
2171 * If PUK is null, unlock SIM card with PIN
2172 *
2173 * If PUK is not null, unlock SIM card with PUK and set PIN code
2174 */
Wink Saville9de0f752013-10-22 19:04:03 -07002175 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002176
2177 while (mHandler == null) {
2178 try {
2179 wait();
2180 } catch (InterruptedException e) {
2181 Thread.currentThread().interrupt();
2182 }
2183 }
2184 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2185
2186 if (puk == null) {
2187 mSimCard.supplyPin(pin, callback);
2188 } else {
2189 mSimCard.supplyPuk(puk, pin, callback);
2190 }
2191
2192 while (!mDone) {
2193 try {
2194 Log.d(LOG_TAG, "wait for done");
2195 wait();
2196 } catch (InterruptedException e) {
2197 // Restore the interrupted status
2198 Thread.currentThread().interrupt();
2199 }
2200 }
2201 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002202 int[] resultArray = new int[2];
2203 resultArray[0] = mResult;
2204 resultArray[1] = mRetryCount;
2205 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002206 }
2207 }
2208
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002209 /**
2210 * This method has been removed due to privacy and stability concerns.
2211 */
2212 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002213 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002214 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2215 return;
Wink Saville36469e72014-06-11 15:17:00 -07002216 }
2217
Nathan Harold1f889d82020-06-04 17:05:26 -07002218 @Override
2219 public void updateServiceLocationWithPackageName(String callingPackage) {
2220 mApp.getSystemService(AppOpsManager.class)
2221 .checkPackage(Binder.getCallingUid(), callingPackage);
2222
2223 final int targetSdk = getTargetSdk(callingPackage);
2224 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2225 // Callers targeting S have no business invoking this method.
2226 return;
2227 }
2228
2229 LocationAccessPolicy.LocationPermissionResult locationResult =
2230 LocationAccessPolicy.checkLocationPermission(mApp,
2231 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2232 .setCallingPackage(callingPackage)
2233 .setCallingFeatureId(null)
2234 .setCallingPid(Binder.getCallingPid())
2235 .setCallingUid(Binder.getCallingUid())
2236 .setMethod("updateServiceLocation")
2237 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2238 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2239 .build());
2240 // Apps that lack location permission have no business calling this method;
2241 // however, because no permission was declared in the public API, denials must
2242 // all be "soft".
2243 switch (locationResult) {
2244 case DENIED_HARD: /* fall through */
2245 case DENIED_SOFT:
2246 return;
2247 }
2248
2249 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002250 final long identity = Binder.clearCallingIdentity();
2251 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002252 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002253 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002254 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002255 }
2256 } finally {
2257 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 }
2260
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002261 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002262 @Override
2263 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002264 return isRadioOnWithFeature(callingPackage, null);
2265 }
2266
2267
2268 @Override
2269 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2270 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2271 callingFeatureId);
2272 }
2273
2274 @Deprecated
2275 @Override
2276 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2277 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002278 }
2279
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002280 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002281 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2282 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002283 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002284 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002285 return false;
2286 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002287
2288 final long identity = Binder.clearCallingIdentity();
2289 try {
2290 return isRadioOnForSubscriber(subId);
2291 } finally {
2292 Binder.restoreCallingIdentity(identity);
2293 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002294 }
2295
2296 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002297 final long identity = Binder.clearCallingIdentity();
2298 try {
2299 final Phone phone = getPhone(subId);
2300 if (phone != null) {
2301 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2302 } else {
2303 return false;
2304 }
2305 } finally {
2306 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002307 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 }
2309
2310 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002311 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 }
Wink Saville36469e72014-06-11 15:17:00 -07002313
Wink Savilleb564aae2014-10-23 10:18:09 -07002314 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002316
2317 final long identity = Binder.clearCallingIdentity();
2318 try {
2319 final Phone phone = getPhone(subId);
2320 if (phone != null) {
2321 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2322 }
2323 } finally {
2324 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002325 }
Wink Saville36469e72014-06-11 15:17:00 -07002326 }
2327
2328 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002329 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002330 }
2331
Wink Savilleb564aae2014-10-23 10:18:09 -07002332 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002333 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002334
2335 final long identity = Binder.clearCallingIdentity();
2336 try {
2337 final Phone phone = getPhone(subId);
2338 if (phone == null) {
2339 return false;
2340 }
2341 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2342 toggleRadioOnOffForSubscriber(subId);
2343 }
2344 return true;
2345 } finally {
2346 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002347 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348 }
Wink Saville36469e72014-06-11 15:17:00 -07002349
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002350 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002351 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002352 /*
2353 * If any of the Radios are available, it will need to be
2354 * shutdown. So return true if any Radio is available.
2355 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002356 final long identity = Binder.clearCallingIdentity();
2357 try {
2358 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2359 Phone phone = PhoneFactory.getPhone(i);
2360 if (phone != null && phone.isRadioAvailable()) return true;
2361 }
2362 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2363 return false;
2364 } finally {
2365 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002366 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002367 }
2368
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002369 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002370 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002371 enforceModifyPermission();
2372
2373 final long identity = Binder.clearCallingIdentity();
2374 try {
2375 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2376 logv("Shutting down Phone " + i);
2377 shutdownRadioUsingPhoneId(i);
2378 }
2379 } finally {
2380 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002381 }
2382 }
2383
2384 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002385 Phone phone = PhoneFactory.getPhone(phoneId);
2386 if (phone != null && phone.isRadioAvailable()) {
2387 phone.shutdownRadio();
2388 }
2389 }
2390
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002392 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002393
2394 final long identity = Binder.clearCallingIdentity();
2395 try {
2396 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2397 if (defaultPhone != null) {
2398 defaultPhone.setRadioPower(turnOn);
2399 return true;
2400 } else {
2401 loge("There's no default phone.");
2402 return false;
2403 }
2404 } finally {
2405 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002406 }
Wink Saville36469e72014-06-11 15:17:00 -07002407 }
2408
Wink Savilleb564aae2014-10-23 10:18:09 -07002409 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002411
2412 final long identity = Binder.clearCallingIdentity();
2413 try {
2414 final Phone phone = getPhone(subId);
2415 if (phone != null) {
2416 phone.setRadioPower(turnOn);
2417 return true;
2418 } else {
2419 return false;
2420 }
2421 } finally {
2422 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 }
2425
Wink Saville36469e72014-06-11 15:17:00 -07002426 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002427 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428 public boolean enableDataConnectivity() {
2429 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002430
2431 final long identity = Binder.clearCallingIdentity();
2432 try {
2433 int subId = mSubscriptionController.getDefaultDataSubId();
2434 final Phone phone = getPhone(subId);
2435 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002436 phone.getDataEnabledSettings().setDataEnabled(
2437 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002438 return true;
2439 } else {
2440 return false;
2441 }
2442 } finally {
2443 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 }
2446
Wink Saville36469e72014-06-11 15:17:00 -07002447 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002448 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 public boolean disableDataConnectivity() {
2450 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002451
2452 final long identity = Binder.clearCallingIdentity();
2453 try {
2454 int subId = mSubscriptionController.getDefaultDataSubId();
2455 final Phone phone = getPhone(subId);
2456 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002457 phone.getDataEnabledSettings().setDataEnabled(
2458 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002459 return true;
2460 } else {
2461 return false;
2462 }
2463 } finally {
2464 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002465 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 }
2467
Sanket Padawe356d7632015-06-22 14:03:32 -07002468 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002469 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002470 final long identity = Binder.clearCallingIdentity();
2471 try {
2472 final Phone phone = getPhone(subId);
2473 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002474 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002475 } else {
2476 return false;
2477 }
2478 } finally {
2479 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002480 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 }
2482
2483 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002484 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002485 }
2486
pkanwarae03a6b2016-11-06 20:37:09 -08002487 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002488 enforceCallPermission();
2489
2490 final long identity = Binder.clearCallingIdentity();
2491 try {
2492 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2493 return;
2494 }
2495 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2496 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2497 } finally {
2498 Binder.restoreCallingIdentity(identity);
2499 }
pkanwar32d516d2016-10-14 19:37:38 -07002500 };
2501
Wink Savilleb564aae2014-10-23 10:18:09 -07002502 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002503 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002504
2505 final long identity = Binder.clearCallingIdentity();
2506 try {
2507 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2508 return false;
2509 }
2510 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2511 } finally {
2512 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002513 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002514 }
2515
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002517 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002518 }
2519
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002520 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002521 final long identity = Binder.clearCallingIdentity();
2522 try {
2523 Phone phone = PhoneFactory.getPhone(slotIndex);
2524 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2525 PhoneConstantConversions.convertCallState(phone.getState());
2526 } finally {
2527 Binder.restoreCallingIdentity(identity);
2528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002529 }
2530
Sanket Padawe356d7632015-06-22 14:03:32 -07002531 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002532 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002533 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2534 }
2535
2536 @Override
2537 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002538 final long identity = Binder.clearCallingIdentity();
2539 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002540 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002541 if (phone != null) {
2542 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2543 } else {
2544 return PhoneConstantConversions.convertDataState(
2545 PhoneConstants.DataState.DISCONNECTED);
2546 }
2547 } finally {
2548 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002550 }
2551
Sanket Padawe356d7632015-06-22 14:03:32 -07002552 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002553 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002554 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2555 }
2556
2557 @Override
2558 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002559 final long identity = Binder.clearCallingIdentity();
2560 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002561 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562 if (phone != null) {
2563 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2564 } else {
2565 return TelephonyManager.DATA_ACTIVITY_NONE;
2566 }
2567 } finally {
2568 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002570 }
2571
2572 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002573 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002574 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002575 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002576
2577 LocationAccessPolicy.LocationPermissionResult locationResult =
2578 LocationAccessPolicy.checkLocationPermission(mApp,
2579 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2580 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002581 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002582 .setCallingPid(Binder.getCallingPid())
2583 .setCallingUid(Binder.getCallingUid())
2584 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002585 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002586 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2587 .build());
2588 switch (locationResult) {
2589 case DENIED_HARD:
2590 throw new SecurityException("Not allowed to access cell location");
2591 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002592 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2593 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002594 }
2595
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002596 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597 final long identity = Binder.clearCallingIdentity();
2598 try {
2599 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002600 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002601 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 } finally {
2603 Binder.restoreCallingIdentity(identity);
2604 }
Svetoslav64fad262015-04-14 14:35:21 -07002605 }
2606
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002607 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002608 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002609 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2610 // registered cell info, so return a NULL country instead.
2611 final long identity = Binder.clearCallingIdentity();
2612 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002613 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2614 // Get default phone in this case.
2615 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2616 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002617 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002618 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002619 if (phone == null) return "";
2620 ServiceStateTracker sst = phone.getServiceStateTracker();
2621 if (sst == null) return "";
2622 LocaleTracker lt = sst.getLocaleTracker();
2623 if (lt == null) return "";
2624 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2625 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2626 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002627 } finally {
2628 Binder.restoreCallingIdentity(identity);
2629 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002630 }
2631
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002632 /**
2633 * This method was removed due to potential issues caused by performing partial
2634 * updates of service state, and lack of a credible use case.
2635 *
2636 * This has the ability to break the telephony implementation by disabling notification of
2637 * changes in device connectivity. DO NOT USE THIS!
2638 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002639 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002640 public void enableLocationUpdates() {
2641 mApp.enforceCallingOrSelfPermission(
2642 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002643 }
2644
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002645 /**
2646 * This method was removed due to potential issues caused by performing partial
2647 * updates of service state, and lack of a credible use case.
2648 *
2649 * This has the ability to break the telephony implementation by disabling notification of
2650 * changes in device connectivity. DO NOT USE THIS!
2651 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002652 @Override
2653 public void disableLocationUpdates() {
2654 mApp.enforceCallingOrSelfPermission(
2655 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002656 }
2657
Nathan Harold31d7ff32018-10-15 20:20:30 -07002658 /**
2659 * Returns the target SDK version number for a given package name.
2660 *
Nathan Haroldec184742019-07-10 17:04:16 -07002661 * This call MUST be invoked before clearing the calling UID.
2662 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002663 * @return target SDK if the package is found or INT_MAX.
2664 */
2665 private int getTargetSdk(String packageName) {
2666 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002667 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002668 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002669 if (ai != null) return ai.targetSdkVersion;
2670 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002671 loge("Failed to get package info for pkg="
2672 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002673 }
2674 return Integer.MAX_VALUE;
2675 }
2676
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002677 @Override
2678 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002679 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2680 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002681 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002682 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2683 throw new SecurityException(
2684 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2685 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002686
Jordan Liu1617b712019-07-10 15:06:26 -07002687 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002688 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2689 return null;
2690 }
Svetoslav64fad262015-04-14 14:35:21 -07002691
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002692 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002694 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002695 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002696
Nathan Haroldf180aac2018-06-01 18:43:55 -07002697 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2698 for (CellInfo ci : info) {
2699 if (ci instanceof CellInfoGsm) {
2700 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2701 } else if (ci instanceof CellInfoWcdma) {
2702 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2703 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002704 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002705 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002706 }
2707
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002708 private List<CellInfo> getCachedCellInfo() {
2709 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2710 for (Phone phone : PhoneFactory.getPhones()) {
2711 List<CellInfo> info = phone.getAllCellInfo();
2712 if (info != null) cellInfos.addAll(info);
2713 }
2714 return cellInfos;
2715 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716
2717 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002718 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002719 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002720 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002721
2722 LocationAccessPolicy.LocationPermissionResult locationResult =
2723 LocationAccessPolicy.checkLocationPermission(mApp,
2724 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2725 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002726 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002727 .setCallingPid(Binder.getCallingPid())
2728 .setCallingUid(Binder.getCallingUid())
2729 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002730 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002731 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2732 .build());
2733 switch (locationResult) {
2734 case DENIED_HARD:
2735 throw new SecurityException("Not allowed to access cell info");
2736 case DENIED_SOFT:
2737 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738 }
2739
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002740 final int targetSdk = getTargetSdk(callingPackage);
2741 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2742 return getCachedCellInfo();
2743 }
2744
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002745 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002746 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002747 final long identity = Binder.clearCallingIdentity();
2748 try {
2749 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2750 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002751 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002752 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002753 if (info != null) cellInfos.addAll(info);
2754 }
2755 return cellInfos;
2756 } finally {
2757 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002758 }
2759 }
2760
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002761 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002762 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2763 String callingFeatureId) {
2764 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2765 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002766 }
2767
2768 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002769 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2770 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002771 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002772 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002773 }
2774
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002775 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2776 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002777 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002778 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002779
2780 LocationAccessPolicy.LocationPermissionResult locationResult =
2781 LocationAccessPolicy.checkLocationPermission(mApp,
2782 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2783 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002784 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002785 .setCallingPid(Binder.getCallingPid())
2786 .setCallingUid(Binder.getCallingUid())
2787 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002788 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2789 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002790 .build());
2791 switch (locationResult) {
2792 case DENIED_HARD:
Hall Liud60acc92020-05-21 17:09:35 -07002793 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2794 // Safetynet logging for b/154934934
2795 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2796 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002797 throw new SecurityException("Not allowed to access cell info");
2798 case DENIED_SOFT:
Hall Liud60acc92020-05-21 17:09:35 -07002799 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2800 // Safetynet logging for b/154934934
2801 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2802 }
Nathan Harold5320c422019-05-09 10:26:08 -07002803 try {
2804 cb.onCellInfo(new ArrayList<CellInfo>());
2805 } catch (RemoteException re) {
2806 // Drop without consequences
2807 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002808 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002809 }
2810
Nathan Harolda939a962019-05-09 10:13:47 -07002811
2812 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002813 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2814
2815 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2816 }
2817
2818 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002819 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002820 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002821 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002822
2823 final long identity = Binder.clearCallingIdentity();
2824 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002825 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826 } finally {
2827 Binder.restoreCallingIdentity(identity);
2828 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002829 }
2830
Shishir Agrawala9f32182016-04-12 12:00:16 -07002831 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002832 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002833 Phone phone = PhoneFactory.getPhone(slotIndex);
2834 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002835 return null;
2836 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002837 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002838 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002839 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002840 return null;
2841 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002842
2843 final long identity = Binder.clearCallingIdentity();
2844 try {
2845 return phone.getImei();
2846 } finally {
2847 Binder.restoreCallingIdentity(identity);
2848 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002849 }
2850
2851 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002852 public String getTypeAllocationCodeForSlot(int slotIndex) {
2853 Phone phone = PhoneFactory.getPhone(slotIndex);
2854 String tac = null;
2855 if (phone != null) {
2856 String imei = phone.getImei();
2857 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2858 }
2859 return tac;
2860 }
2861
2862 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002863 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002864 Phone phone = PhoneFactory.getPhone(slotIndex);
2865 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002866 return null;
2867 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002868
Jeff Davidson913390f2018-02-23 17:11:49 -08002869 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002870 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002871 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002872 return null;
2873 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002874
2875 final long identity = Binder.clearCallingIdentity();
2876 try {
2877 return phone.getMeid();
2878 } finally {
2879 Binder.restoreCallingIdentity(identity);
2880 }
Jack Yu2af8d712017-03-15 17:14:14 -07002881 }
2882
2883 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002884 public String getManufacturerCodeForSlot(int slotIndex) {
2885 Phone phone = PhoneFactory.getPhone(slotIndex);
2886 String manufacturerCode = null;
2887 if (phone != null) {
2888 String meid = phone.getMeid();
2889 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2890 }
2891 return manufacturerCode;
2892 }
2893
2894 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002895 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2896 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002897 Phone phone = PhoneFactory.getPhone(slotIndex);
2898 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002899 return null;
2900 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002901 int subId = phone.getSubId();
2902 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002903 mApp, subId, callingPackage, callingFeatureId,
2904 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002905 return null;
2906 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907
2908 final long identity = Binder.clearCallingIdentity();
2909 try {
2910 return phone.getDeviceSvn();
2911 } finally {
2912 Binder.restoreCallingIdentity(identity);
2913 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002914 }
2915
fionaxu43304da2017-11-27 22:51:16 -08002916 @Override
2917 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002918 final long identity = Binder.clearCallingIdentity();
2919 try {
2920 final Phone phone = getPhone(subId);
2921 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2922 } finally {
2923 Binder.restoreCallingIdentity(identity);
2924 }
fionaxu43304da2017-11-27 22:51:16 -08002925 }
2926
2927 @Override
2928 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929 final long identity = Binder.clearCallingIdentity();
2930 try {
2931 final Phone phone = getPhone(subId);
2932 return phone == null ? null : phone.getCarrierName();
2933 } finally {
2934 Binder.restoreCallingIdentity(identity);
2935 }
fionaxu43304da2017-11-27 22:51:16 -08002936 }
2937
calvinpanffe225e2018-11-01 19:43:06 +08002938 @Override
chen xu0026ca62019-03-06 15:28:50 -08002939 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002940 final long identity = Binder.clearCallingIdentity();
2941 try {
2942 final Phone phone = getPhone(subId);
2943 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002944 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002945 } finally {
2946 Binder.restoreCallingIdentity(identity);
2947 }
2948 }
2949
2950 @Override
chen xu0026ca62019-03-06 15:28:50 -08002951 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002952 final long identity = Binder.clearCallingIdentity();
2953 try {
2954 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002955 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002956 } finally {
2957 Binder.restoreCallingIdentity(identity);
2958 }
2959 }
2960
chen xu651eec72018-11-11 19:03:44 -08002961 @Override
chen xu864e11c2018-12-06 22:10:03 -08002962 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2963 if (!isSubscriptionMccMnc) {
2964 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2965 }
chen xu651eec72018-11-11 19:03:44 -08002966 final Phone phone = PhoneFactory.getPhone(slotIndex);
2967 if (phone == null) {
2968 return TelephonyManager.UNKNOWN_CARRIER_ID;
2969 }
2970 final long identity = Binder.clearCallingIdentity();
2971 try {
2972 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2973 } finally {
2974 Binder.restoreCallingIdentity(identity);
2975 }
2976 }
2977
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002978 //
2979 // Internal helper methods.
2980 //
2981
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002982 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002983 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2984 *
2985 * @throws SecurityException if the caller does not have the required permission
2986 */
2987 private void enforceModifyPermission() {
2988 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2989 }
2990
Shuo Qiancd19c462020-01-16 20:51:11 -08002991 /**
2992 * Make sure the caller is system.
2993 *
2994 * @throws SecurityException if the caller is not system.
2995 */
2996 private void enforceSystemCaller() {
2997 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2998 throw new SecurityException("Caller must be system");
2999 }
3000 }
3001
Shuo Qian3b6ee772019-11-13 17:43:31 -08003002 private void enforceActiveEmergencySessionPermission() {
3003 mApp.enforceCallingOrSelfPermission(
3004 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3005 }
3006
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003007 /**
3008 * Make sure the caller has the CALL_PHONE permission.
3009 *
3010 * @throws SecurityException if the caller does not have the required permission
3011 */
3012 private void enforceCallPermission() {
3013 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3014 }
3015
paulhu5a773602019-08-23 19:17:33 +08003016 private void enforceSettingsPermission() {
3017 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003018 }
3019
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003020 private String createTelUrl(String number) {
3021 if (TextUtils.isEmpty(number)) {
3022 return null;
3023 }
3024
Jake Hambye994d462014-02-03 13:10:13 -08003025 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003026 }
3027
Ihab Awadf9e92732013-12-05 18:02:52 -08003028 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003029 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3030 }
3031
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003032 private static void logv(String msg) {
3033 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3034 }
3035
Ihab Awadf9e92732013-12-05 18:02:52 -08003036 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003037 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3038 }
3039
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003040 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003041 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003042 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003043 }
3044
Sanket Padawe356d7632015-06-22 14:03:32 -07003045 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003046 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003047 final long identity = Binder.clearCallingIdentity();
3048 try {
3049 final Phone phone = PhoneFactory.getPhone(slotIndex);
3050 if (phone == null) {
3051 return PhoneConstants.PHONE_TYPE_NONE;
3052 } else {
3053 return phone.getPhoneType();
3054 }
3055 } finally {
3056 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003057 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003058 }
3059
3060 /**
3061 * Returns the CDMA ERI icon index to display
3062 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003063 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003064 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3065 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3066 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003067 }
3068
Sanket Padawe356d7632015-06-22 14:03:32 -07003069 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003070 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3071 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003072 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003073 mApp, subId, callingPackage, callingFeatureId,
3074 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003075 return -1;
3076 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003077
3078 final long identity = Binder.clearCallingIdentity();
3079 try {
3080 final Phone phone = getPhone(subId);
3081 if (phone != null) {
3082 return phone.getCdmaEriIconIndex();
3083 } else {
3084 return -1;
3085 }
3086 } finally {
3087 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003089 }
3090
3091 /**
3092 * Returns the CDMA ERI icon mode,
3093 * 0 - ON
3094 * 1 - FLASHING
3095 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003096 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003097 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3098 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3099 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003100 }
3101
Sanket Padawe356d7632015-06-22 14:03:32 -07003102 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003103 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3104 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003105 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003106 mApp, subId, callingPackage, callingFeatureId,
3107 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003108 return -1;
3109 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003110
3111 final long identity = Binder.clearCallingIdentity();
3112 try {
3113 final Phone phone = getPhone(subId);
3114 if (phone != null) {
3115 return phone.getCdmaEriIconMode();
3116 } else {
3117 return -1;
3118 }
3119 } finally {
3120 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003121 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003122 }
3123
3124 /**
3125 * Returns the CDMA ERI text,
3126 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003127 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003128 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3129 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3130 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003131 }
3132
Sanket Padawe356d7632015-06-22 14:03:32 -07003133 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003134 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3135 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003136 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003137 mApp, subId, callingPackage, callingFeatureId,
3138 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003139 return null;
3140 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003141
3142 final long identity = Binder.clearCallingIdentity();
3143 try {
3144 final Phone phone = getPhone(subId);
3145 if (phone != null) {
3146 return phone.getCdmaEriText();
3147 } else {
3148 return null;
3149 }
3150 } finally {
3151 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003153 }
3154
3155 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003156 * Returns the CDMA MDN.
3157 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003158 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003159 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3161 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003162
3163 final long identity = Binder.clearCallingIdentity();
3164 try {
3165 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003166 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003167 return phone.getLine1Number();
3168 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003169 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003170 return null;
3171 }
3172 } finally {
3173 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003174 }
3175 }
3176
3177 /**
3178 * Returns the CDMA MIN.
3179 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003180 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003181 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3183 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003184
3185 final long identity = Binder.clearCallingIdentity();
3186 try {
3187 final Phone phone = getPhone(subId);
3188 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3189 return phone.getCdmaMin();
3190 } else {
3191 return null;
3192 }
3193 } finally {
3194 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003195 }
3196 }
3197
Hall Liud892bec2018-11-30 14:51:45 -08003198 @Override
3199 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3200 INumberVerificationCallback callback, String callingPackage) {
3201 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3202 != PERMISSION_GRANTED) {
3203 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3204 }
3205 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3206
3207 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3208 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3209 throw new SecurityException("Calling package must be configured in the device config");
3210 }
3211
3212 if (range == null) {
3213 throw new NullPointerException("Range must be non-null");
3214 }
3215
3216 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003217 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003218
3219 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3220 }
3221
Junda Liuca05d5d2014-08-14 22:36:34 -07003222 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003223 * Returns true if CDMA provisioning needs to run.
3224 */
3225 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003226 final long identity = Binder.clearCallingIdentity();
3227 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003228 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003229 } finally {
3230 Binder.restoreCallingIdentity(identity);
3231 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003232 }
3233
3234 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003235 * Sets the voice mail number of a given subId.
3236 */
3237 @Override
3238 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003239 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3240 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003241
3242 final long identity = Binder.clearCallingIdentity();
3243 try {
3244 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3245 new Pair<String, String>(alphaTag, number), new Integer(subId));
3246 return success;
3247 } finally {
3248 Binder.restoreCallingIdentity(identity);
3249 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003250 }
3251
Ta-wei Yen87c49842016-05-13 21:19:52 -07003252 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003253 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3254 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003255 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3256 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003257 if (!TextUtils.equals(callingPackage, systemDialer)) {
3258 throw new SecurityException("caller must be system dialer");
3259 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003260
3261 final long identity = Binder.clearCallingIdentity();
3262 try {
3263 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3264 if (phoneAccountHandle == null) {
3265 return null;
3266 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003267 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003268 } finally {
3269 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003270 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003271 }
3272
3273 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003274 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3275 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003276 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003277 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003278 mApp, subId, callingPackage, callingFeatureId,
3279 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003280 return null;
3281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003282
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003283 final long identity = Binder.clearCallingIdentity();
3284 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003285 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003286 } finally {
3287 Binder.restoreCallingIdentity(identity);
3288 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003289 }
3290
3291 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003292 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3293 VisualVoicemailSmsFilterSettings settings) {
3294 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003295
3296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003299 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003300 } finally {
3301 Binder.restoreCallingIdentity(identity);
3302 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003303 }
3304
3305 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003306 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3307 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003308
3309 final long identity = Binder.clearCallingIdentity();
3310 try {
3311 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003312 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003313 } finally {
3314 Binder.restoreCallingIdentity(identity);
3315 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003316 }
3317
3318 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003319 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3320 String callingPackage, int subId) {
3321 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003322
3323 final long identity = Binder.clearCallingIdentity();
3324 try {
3325 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003326 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003327 } finally {
3328 Binder.restoreCallingIdentity(identity);
3329 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003330 }
3331
3332 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003333 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003334 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003335
3336 final long identity = Binder.clearCallingIdentity();
3337 try {
3338 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003339 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003340 } finally {
3341 Binder.restoreCallingIdentity(identity);
3342 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003343 }
3344
3345 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003346 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3347 String callingAttributionTag, int subId, String number, int port, String text,
3348 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003349 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003350 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003351 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003352 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003353 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3354 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003355 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003356
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003357 /**
fionaxu0152e512016-11-14 13:36:14 -08003358 * Sets the voice activation state of a given subId.
3359 */
3360 @Override
3361 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003362 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3363 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003364
3365 final long identity = Binder.clearCallingIdentity();
3366 try {
3367 final Phone phone = getPhone(subId);
3368 if (phone != null) {
3369 phone.setVoiceActivationState(activationState);
3370 } else {
3371 loge("setVoiceActivationState fails with invalid subId: " + subId);
3372 }
3373 } finally {
3374 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003375 }
3376 }
3377
3378 /**
3379 * Sets the data activation state of a given subId.
3380 */
3381 @Override
3382 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003383 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3384 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003385
3386 final long identity = Binder.clearCallingIdentity();
3387 try {
3388 final Phone phone = getPhone(subId);
3389 if (phone != null) {
3390 phone.setDataActivationState(activationState);
3391 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003392 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003393 }
3394 } finally {
3395 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003396 }
3397 }
3398
3399 /**
3400 * Returns the voice activation state of a given subId.
3401 */
3402 @Override
3403 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003404 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003405
fionaxu0152e512016-11-14 13:36:14 -08003406 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003407 final long identity = Binder.clearCallingIdentity();
3408 try {
3409 if (phone != null) {
3410 return phone.getVoiceActivationState();
3411 } else {
3412 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3413 }
3414 } finally {
3415 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003416 }
3417 }
3418
3419 /**
3420 * Returns the data activation state of a given subId.
3421 */
3422 @Override
3423 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003424 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003425
fionaxu0152e512016-11-14 13:36:14 -08003426 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003427 final long identity = Binder.clearCallingIdentity();
3428 try {
3429 if (phone != null) {
3430 return phone.getDataActivationState();
3431 } else {
3432 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3433 }
3434 } finally {
3435 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003436 }
3437 }
3438
3439 /**
Wink Saville36469e72014-06-11 15:17:00 -07003440 * Returns the unread count of voicemails for a subId
3441 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003442 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003443 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3444 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003445 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003446 mApp, subId, callingPackage, callingFeatureId,
3447 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003448 return 0;
3449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003450 final long identity = Binder.clearCallingIdentity();
3451 try {
3452 final Phone phone = getPhone(subId);
3453 if (phone != null) {
3454 return phone.getVoiceMessageCount();
3455 } else {
3456 return 0;
3457 }
3458 } finally {
3459 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003461 }
3462
3463 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003464 * returns true, if the device is in a state where both voice and data
3465 * are supported simultaneously. This can change based on location or network condition.
3466 */
3467 @Override
3468 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003469 final long identity = Binder.clearCallingIdentity();
3470 try {
3471 final Phone phone = getPhone(subId);
3472 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3473 } finally {
3474 Binder.restoreCallingIdentity(identity);
3475 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003476 }
3477
3478 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003479 * Send the dialer code if called from the current default dialer or the caller has
3480 * carrier privilege.
3481 * @param inputCode The dialer code to send
3482 */
3483 @Override
3484 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003485 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003486 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003487 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3488 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003489 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003490 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003491 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003492 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003493
3494 final long identity = Binder.clearCallingIdentity();
3495 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003496 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003497 } finally {
3498 Binder.restoreCallingIdentity(identity);
3499 }
fionaxu235cc5e2017-03-06 22:25:57 -08003500 }
3501
Pengquan Menga1bb6272018-09-06 09:59:22 -07003502 @Override
3503 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003504 TelephonyPermissions
3505 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3506 mApp, subId, "getNetworkSelectionMode");
3507 final long identity = Binder.clearCallingIdentity();
3508 try {
3509 if (!isActiveSubscription(subId)) {
3510 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3511 }
3512 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3513 } finally {
3514 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003515 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003516 }
3517
Brad Ebinger35c841c2018-10-01 10:40:55 -07003518 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003519 public boolean isInEmergencySmsMode() {
3520 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3521 final long identity = Binder.clearCallingIdentity();
3522 try {
3523 for (Phone phone : PhoneFactory.getPhones()) {
3524 if (phone.isInEmergencySmsMode()) {
3525 return true;
3526 }
3527 }
3528 } finally {
3529 Binder.restoreCallingIdentity(identity);
3530 }
3531 return false;
3532 }
3533
shilu366312e2019-12-17 09:28:10 -08003534 /**
3535 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3536 * @param subId The subscription to use to check the configuration.
3537 * @param c The callback that will be used to send the result.
3538 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003539 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003540 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3541 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003542 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3543 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003544
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003545 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3546 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3547 "IMS not available on device.");
3548 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003549 final long token = Binder.clearCallingIdentity();
3550 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003551 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003552 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003553 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003554 } catch (ImsException e) {
3555 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003556 } finally {
3557 Binder.restoreCallingIdentity(token);
3558 }
3559 }
3560
shilu366312e2019-12-17 09:28:10 -08003561 /**
3562 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3563 * @param subId The subscription to use to check the configuration.
3564 * @param c The callback that will be used to send the result.
3565 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003566 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003567 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003568 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3569 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003570 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3571 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3572 }
Meng Wangafbc5852019-09-19 17:37:13 -07003573 final long token = Binder.clearCallingIdentity();
3574 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003575 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003576 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3577 .removeRegistrationCallbackForSubscription(c, subId);
3578 } catch (ImsException e) {
3579 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3580 + "is inactive, ignoring unregister.");
3581 // If the subscription is no longer active, just return, since the callback
3582 // will already have been removed internally.
3583 } finally {
3584 Binder.restoreCallingIdentity(token);
3585 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003586 }
3587
Brad Ebingera34a6c22019-10-22 17:36:18 -07003588 /**
3589 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3590 */
3591 @Override
3592 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3593 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3594 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3595 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3596 "IMS not available on device.");
3597 }
3598 final long token = Binder.clearCallingIdentity();
3599 try {
3600 Phone phone = getPhone(subId);
3601 if (phone == null) {
3602 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3603 + subId + "'");
3604 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3605 }
3606 phone.getImsRegistrationState(regState -> {
3607 try {
3608 consumer.accept((regState == null)
3609 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3610 } catch (RemoteException e) {
3611 // Ignore if the remote process is no longer available to call back.
3612 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3613 }
3614 });
3615 } finally {
3616 Binder.restoreCallingIdentity(token);
3617 }
3618 }
3619
3620 /**
3621 * Get the transport type for the IMS service registration state.
3622 */
3623 @Override
3624 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003625 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3626 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003627 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3628 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3629 "IMS not available on device.");
3630 }
3631 final long token = Binder.clearCallingIdentity();
3632 try {
3633 Phone phone = getPhone(subId);
3634 if (phone == null) {
3635 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3636 + subId + "'");
3637 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3638 }
3639 phone.getImsRegistrationTech(regTech -> {
3640 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3641 int regTechConverted = (regTech == null)
3642 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3643 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3644 regTechConverted);
3645 try {
3646 consumer.accept(regTechConverted);
3647 } catch (RemoteException e) {
3648 // Ignore if the remote process is no longer available to call back.
3649 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3650 }
3651 });
3652 } finally {
3653 Binder.restoreCallingIdentity(token);
3654 }
3655 }
3656
shilu366312e2019-12-17 09:28:10 -08003657 /**
3658 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3659 * @param subId The subscription to use to check the configuration.
3660 * @param c The callback that will be used to send the result.
3661 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003662 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003663 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3664 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003665 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3666 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003667 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3668 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3669 "IMS not available on device.");
3670 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003671 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3672 final long token = Binder.clearCallingIdentity();
3673 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003674 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003675 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003676 } catch (ImsException e) {
3677 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003678 } finally {
3679 Binder.restoreCallingIdentity(token);
3680 }
3681 }
3682
shilu366312e2019-12-17 09:28:10 -08003683 /**
3684 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3685 * @param subId The subscription to use to check the configuration.
3686 * @param c The callback that will be used to send the result.
3687 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003688 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003689 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003690 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3691 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003692 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3693 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3694 }
Meng Wangafbc5852019-09-19 17:37:13 -07003695
3696 final long token = Binder.clearCallingIdentity();
3697 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003698 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003699 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003700 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003701 } catch (ImsException e) {
3702 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3703 + "is inactive, ignoring unregister.");
3704 // If the subscription is no longer active, just return, since the callback
3705 // will already have been removed internally.
3706 } finally {
3707 Binder.restoreCallingIdentity(token);
3708 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003709 }
3710
3711 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003712 public boolean isCapable(int subId, int capability, int regTech) {
3713 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003714 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3715 final long token = Binder.clearCallingIdentity();
3716 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003717 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003718 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003719 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003720 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3721 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003722 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003723 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3724 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003725 } finally {
3726 Binder.restoreCallingIdentity(token);
3727 }
3728 }
3729
3730 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003731 public boolean isAvailable(int subId, int capability, int regTech) {
3732 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003733 final long token = Binder.clearCallingIdentity();
3734 try {
3735 Phone phone = getPhone(subId);
3736 if (phone == null) return false;
3737 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003738 } catch (com.android.ims.ImsException e) {
3739 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3740 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003741 } finally {
3742 Binder.restoreCallingIdentity(token);
3743 }
3744 }
3745
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003746 /**
3747 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3748 * subscription.
3749 * @param subId The subscription to use to check the configuration.
3750 * @param callback The callback that will be used to send the result.
3751 * @param capability The MmTelFeature capability that will be used to send the result.
3752 * @param transportType The transport type of the MmTelFeature capability.
3753 */
3754 @Override
3755 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3756 int transportType) {
3757 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3758 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3759 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3760 "IMS not available on device.");
3761 }
3762 final long token = Binder.clearCallingIdentity();
3763 try {
3764 int slotId = getSlotIndex(subId);
3765 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3766 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3767 + subId + "'");
3768 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3769 }
3770 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3771 transportType, aBoolean -> {
3772 try {
3773 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3774 } catch (RemoteException e) {
3775 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3776 + "running. Ignore");
3777 }
3778 });
3779 } finally {
3780 Binder.restoreCallingIdentity(token);
3781 }
3782 }
3783
shilu366312e2019-12-17 09:28:10 -08003784 /**
3785 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3786 * @param subId The subscription to use to check the configuration.
3787 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003788 @Override
3789 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003790 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3791 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003792
Brad Ebinger35c841c2018-10-01 10:40:55 -07003793 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3794 final long token = Binder.clearCallingIdentity();
3795 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003796 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003797 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003798 } catch (ImsException e) {
3799 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003800 } finally {
3801 Binder.restoreCallingIdentity(token);
3802 }
3803 }
3804
3805 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003806 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003808 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003809 final long identity = Binder.clearCallingIdentity();
3810 try {
3811 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003812 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003813 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003814 } catch (ImsException e) {
3815 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003816 } finally {
3817 Binder.restoreCallingIdentity(identity);
3818 }
3819 }
3820
shilu366312e2019-12-17 09:28:10 -08003821 /**
3822 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3823 * @param subId The subscription to use to check the configuration.
3824 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003825 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003826 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003827 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3828 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003829 final long identity = Binder.clearCallingIdentity();
3830 try {
3831 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003832 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3833 } catch (ImsException e) {
3834 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003835 } finally {
3836 Binder.restoreCallingIdentity(identity);
3837 }
3838 }
3839
3840 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003841 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003843 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003844 final long identity = Binder.clearCallingIdentity();
3845 try {
3846 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003847 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003848 } catch (ImsException e) {
3849 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003850 } finally {
3851 Binder.restoreCallingIdentity(identity);
3852 }
3853 }
3854
shilu366312e2019-12-17 09:28:10 -08003855 /**
3856 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3857 * @param subId The subscription to use to check the configuration.
3858 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003859 @Override
3860 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003861 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3862 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003863 final long identity = Binder.clearCallingIdentity();
3864 try {
3865 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003866 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003867 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003868 } catch (ImsException e) {
3869 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003870 } finally {
3871 Binder.restoreCallingIdentity(identity);
3872 }
3873 }
3874
3875 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003876 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003878 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003879 final long identity = Binder.clearCallingIdentity();
3880 try {
3881 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003882 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003883 } catch (ImsException e) {
3884 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003885 } finally {
3886 Binder.restoreCallingIdentity(identity);
3887 }
3888 }
3889
shilu366312e2019-12-17 09:28:10 -08003890 /**
3891 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3892 * @param subId The subscription to use to check the configuration.
3893 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 @Override
3895 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003896 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3897 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003898 final long identity = Binder.clearCallingIdentity();
3899 try {
3900 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003901 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003902 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003903 } catch (ImsException e) {
3904 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003905 } finally {
3906 Binder.restoreCallingIdentity(identity);
3907 }
3908 }
3909
3910 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003911 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003913 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003914 final long identity = Binder.clearCallingIdentity();
3915 try {
3916 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003917 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003918 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003919 } catch (ImsException e) {
3920 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003921 } finally {
3922 Binder.restoreCallingIdentity(identity);
3923 }
3924 }
3925
3926 @Override
3927 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3929 "setVoWiFiNonPersistent");
3930 final long identity = Binder.clearCallingIdentity();
3931 try {
3932 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003933 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003934 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
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 int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003948 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3949 mApp, subId, "getVoWiFiModeSetting");
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)).getWfcMode(false /*isRoaming*/);
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
3963 public void setVoWiFiModeSetting(int subId, int mode) {
3964 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3965 "setVoWiFiModeSetting");
3966 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)).setWfcMode(mode, false /*isRoaming*/);
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 int getVoWiFiRoamingModeSetting(int subId) {
3980 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3981 final long identity = Binder.clearCallingIdentity();
3982 try {
3983 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003984 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003985 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003986 } catch (ImsException e) {
3987 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003988 } finally {
3989 Binder.restoreCallingIdentity(identity);
3990 }
3991 }
3992
3993 @Override
3994 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3995 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3996 "setVoWiFiRoamingModeSetting");
3997 final long identity = Binder.clearCallingIdentity();
3998 try {
3999 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004000 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004001 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004002 } catch (ImsException e) {
4003 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004004 } finally {
4005 Binder.restoreCallingIdentity(identity);
4006 }
4007 }
4008
4009 @Override
4010 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4012 "setRttCapabilityEnabled");
4013 final long identity = Binder.clearCallingIdentity();
4014 try {
4015 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004016 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4017 } catch (ImsException e) {
4018 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004019 } finally {
4020 Binder.restoreCallingIdentity(identity);
4021 }
4022 }
4023
shilu366312e2019-12-17 09:28:10 -08004024 /**
4025 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4026 * @param subId The subscription to use to check the configuration.
4027 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004028 @Override
4029 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004030 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4031 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004032 final long identity = Binder.clearCallingIdentity();
4033 try {
4034 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004035 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004036 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004037 } catch (ImsException e) {
4038 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 } finally {
4040 Binder.restoreCallingIdentity(identity);
4041 }
4042 }
4043
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004044 @Override
4045 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4046 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4047 final long identity = Binder.clearCallingIdentity();
4048 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004049 if (!isImsAvailableOnDevice()) {
4050 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4051 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004052 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004053 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004054 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004055 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004056 } catch (ImsException e) {
4057 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004058 } finally {
4059 Binder.restoreCallingIdentity(identity);
4060 }
4061 }
4062
4063 @Override
4064 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4065 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4066 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004067 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4068 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4069 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004070 try {
4071 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004072 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004073 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004074 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004075 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4076 + "is inactive, ignoring unregister.");
4077 // If the subscription is no longer active, just return, since the callback will already
4078 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004079 } finally {
4080 Binder.restoreCallingIdentity(identity);
4081 }
4082 }
4083
allenwtsu99c623b2020-01-03 18:24:23 +08004084
4085 private void checkModifyPhoneStatePermission(int subId, String message) {
4086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4087 message);
4088 }
4089
4090 private boolean isImsProvisioningRequired(int subId, int capability,
4091 boolean isMmtelCapability) {
4092 Phone phone = getPhone(subId);
4093 if (phone == null) {
4094 loge("phone instance null for subid " + subId);
4095 return false;
4096 }
4097 if (isMmtelCapability) {
4098 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4099 return false;
4100 }
4101 } else {
4102 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4103 return false;
4104 }
4105 }
4106 return true;
4107 }
4108
4109 @Override
4110 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4111 boolean isProvisioned) {
4112 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4113
4114 final long identity = Binder.clearCallingIdentity();
4115 try {
4116 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4117 if (!isImsProvisioningRequired(subId, capability, false)) {
4118 return;
4119 }
4120
4121 // this capability requires provisioning, route to the correct API.
4122 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4123 switch (capability) {
4124 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4125 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4126 ims.setEabProvisioned(isProvisioned);
4127 break;
4128 default: {
4129 throw new IllegalArgumentException("Tried to set provisioning for "
4130 + "rcs capability '" + capability + "', which does not require "
4131 + "provisioning.");
4132 }
4133 }
4134 } finally {
4135 Binder.restoreCallingIdentity(identity);
4136 }
4137
4138 }
4139
4140
4141 @Override
4142 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4143 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4144 final long identity = Binder.clearCallingIdentity();
4145 try {
4146 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4147 if (!isImsProvisioningRequired(subId, capability, false)) {
4148 return true;
4149 }
4150
4151 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4152 switch (capability) {
4153 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4154 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4155 return ims.isEabProvisionedOnDevice();
4156
4157 default: {
4158 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4159 + "capability '" + capability + "', which does not require "
4160 + "provisioning.");
4161 }
4162 }
4163
4164 } finally {
4165 Binder.restoreCallingIdentity(identity);
4166 }
4167 }
4168
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004169 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004170 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4171 boolean isProvisioned) {
4172 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4173 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4174 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4175 }
allenwtsu99c623b2020-01-03 18:24:23 +08004176 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004177 final long identity = Binder.clearCallingIdentity();
4178 try {
4179 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004180 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004181 return;
4182 }
4183
4184 // this capability requires provisioning, route to the correct API.
4185 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4186 switch (capability) {
4187 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4188 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4189 ims.setVolteProvisioned(isProvisioned);
4190 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4191 ims.setWfcProvisioned(isProvisioned);
4192 }
4193 break;
4194 }
4195 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4196 // There is currently no difference in VT provisioning type.
4197 ims.setVtProvisioned(isProvisioned);
4198 break;
4199 }
4200 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4201 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4202 // change the capability of the feature instead if needed.
4203 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4204 == isProvisioned) {
4205 // No change in provisioning.
4206 return;
4207 }
4208 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4209 try {
4210 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004211 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004212 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4213 + ", Exception" + e.getMessage());
4214 }
4215 break;
4216 }
4217 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004218 throw new IllegalArgumentException("Tried to set provisioning for "
4219 + "MmTel capability '" + capability + "', which does not require "
4220 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004221 }
4222 }
4223
4224 } finally {
4225 Binder.restoreCallingIdentity(identity);
4226 }
4227 }
4228
4229 @Override
4230 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4231 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4232 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4233 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4234 }
4235 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4236 final long identity = Binder.clearCallingIdentity();
4237 try {
4238 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004239 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004240 return true;
4241 }
4242
4243 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4244 switch (capability) {
4245 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4246 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4247 return ims.isVolteProvisionedOnDevice();
4248 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4249 return ims.isWfcProvisionedOnDevice();
4250 }
4251 // This should never happen, since we are checking tech above to make sure it
4252 // is either LTE or IWLAN.
4253 throw new IllegalArgumentException("Invalid radio technology for voice "
4254 + "capability.");
4255 }
4256 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4257 // There is currently no difference in VT provisioning type.
4258 return ims.isVtProvisionedOnDevice();
4259 }
4260 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4261 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4262 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4263 }
4264 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004265 throw new IllegalArgumentException(
4266 "Tried to get provisioning for MmTel capability '" + capability
4267 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004268 }
4269 }
4270
4271 } finally {
4272 Binder.restoreCallingIdentity(identity);
4273 }
4274 }
4275
4276 @Override
4277 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4278 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4279 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4280 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4281 }
4282 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4283 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4284 return (provisionedBits & capability) > 0;
4285 }
4286
4287 @Override
4288 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4289 boolean isProvisioned) {
4290 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4291 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4292 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4293 }
4294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4295 "setProvisioningStatusForCapability");
4296 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4297 // If the current provisioning status for capability already matches isProvisioned,
4298 // do nothing.
4299 if (((provisionedBits & capability) > 0) == isProvisioned) {
4300 return;
4301 }
4302 if (isProvisioned) {
4303 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4304 } else {
4305 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4306 }
4307 }
4308
4309 /**
4310 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4311 * technology. The bitfield should mirror the bitfield defined by
4312 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4313 */
4314 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4315 String key = getMmTelProvisioningKey(subId, tech);
4316 // Default is no capabilities are provisioned.
4317 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4318 }
4319
4320 /**
4321 * Sets the MmTel capability provisioning bitfield (defined by
4322 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4323 * technology specified.
4324 *
4325 * Note: This is a synchronous command and should not be called on UI thread.
4326 */
4327 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4328 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4329 String key = getMmTelProvisioningKey(subId, tech);
4330 editor.putInt(key, newField);
4331 editor.commit();
4332 }
4333
4334 private static String getMmTelProvisioningKey(int subId, int tech) {
4335 // resulting key is provision_ims_mmtel_{subId}_{tech}
4336 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4337 }
4338
4339 /**
4340 * Query CarrierConfig to see if the specified capability requires provisioning for the
4341 * carrier associated with the subscription id.
4342 */
4343 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4344 int capability) {
4345 CarrierConfigManager configManager = new CarrierConfigManager(context);
4346 PersistableBundle c = configManager.getConfigForSubId(subId);
4347 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004348 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004349 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4350 false);
4351 boolean requireVoiceVtProvisioning = c.getBoolean(
4352 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4353
4354 // First check to make sure that the capability requires provisioning.
4355 switch (capability) {
4356 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4357 // intentional fallthrough
4358 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4359 if (requireVoiceVtProvisioning) {
4360 // Voice and Video requires provisioning
4361 return true;
4362 }
4363 break;
4364 }
4365 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4366 if (requireUtProvisioning) {
4367 // UT requires provisioning
4368 return true;
4369 }
4370 break;
4371 }
4372 }
4373 return false;
4374 }
4375
allenwtsu99c623b2020-01-03 18:24:23 +08004376 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4377 int capability) {
4378 CarrierConfigManager configManager = new CarrierConfigManager(context);
4379 PersistableBundle c = configManager.getConfigForSubId(subId);
4380
4381 boolean requireRcsProvisioning = c.getBoolean(
4382 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4383
4384 // First check to make sure that the capability requires provisioning.
4385 switch (capability) {
4386 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4387 // intentional fallthrough
4388 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4389 if (requireRcsProvisioning) {
4390 // OPTION or PRESENCE requires provisioning
4391 return true;
4392 }
4393 break;
4394 }
4395 }
4396 return false;
4397 }
4398
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004399 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004400 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004401 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4402 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4403 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004404 enforceReadPrivilegedPermission("getImsProvisioningInt");
4405 final long identity = Binder.clearCallingIdentity();
4406 try {
4407 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004408 int slotId = getSlotIndex(subId);
4409 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4410 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4411 + subId + "' for key:" + key);
4412 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4413 }
4414 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004415 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004416 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4417 + subId + "' for key:" + key);
4418 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004419 } finally {
4420 Binder.restoreCallingIdentity(identity);
4421 }
4422 }
4423
4424 @Override
4425 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004426 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4427 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4428 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004429 enforceReadPrivilegedPermission("getImsProvisioningString");
4430 final long identity = Binder.clearCallingIdentity();
4431 try {
4432 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004433 int slotId = getSlotIndex(subId);
4434 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4435 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4436 + subId + "' for key:" + key);
4437 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4438 }
4439 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004440 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004441 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4442 + subId + "' for key:" + key);
4443 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004444 } finally {
4445 Binder.restoreCallingIdentity(identity);
4446 }
4447 }
4448
4449 @Override
4450 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004451 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4452 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4453 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4455 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004456 final long identity = Binder.clearCallingIdentity();
4457 try {
4458 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004459 int slotId = getSlotIndex(subId);
4460 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4461 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4462 + subId + "' for key:" + key);
4463 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4464 }
4465 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004466 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004467 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4468 + "' for key:" + key);
4469 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004470 } finally {
4471 Binder.restoreCallingIdentity(identity);
4472 }
4473 }
4474
4475 @Override
4476 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004477 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4478 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4479 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004480 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4481 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004482 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, "setImsProvisioningString: called with an inactive subscription id '"
4488 + subId + "' for key:" + key);
4489 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4490 }
4491 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
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, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4494 + "' for key:" + key);
4495 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004496 } finally {
4497 Binder.restoreCallingIdentity(identity);
4498 }
4499 }
4500
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004501 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004502 int slotId = SubscriptionManager.getSlotIndex(subId);
4503 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004504 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4505 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004506 }
4507 return slotId;
4508 }
4509
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004510 private int getSlotIndex(int subId) {
4511 int slotId = SubscriptionManager.getSlotIndex(subId);
4512 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4513 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4514 }
4515 return slotId;
4516 }
4517
Wink Saville36469e72014-06-11 15:17:00 -07004518 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004519 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004520 */
4521 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004522 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4523 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004524 final int targetSdk = getTargetSdk(callingPackage);
4525 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004526 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004527 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004528 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004529 mApp, subId, callingPackage, callingFeatureId,
4530 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004531 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4532 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004533
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004534 final long identity = Binder.clearCallingIdentity();
4535 try {
4536 final Phone phone = getPhone(subId);
4537 if (phone != null) {
4538 return phone.getServiceState().getDataNetworkType();
4539 } else {
4540 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4541 }
4542 } finally {
4543 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004545 }
4546
4547 /**
4548 * Returns the data network type
4549 */
4550 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004551 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4552 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4553 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004554 }
4555
4556 /**
4557 * Returns the data network type for a subId
4558 */
4559 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004560 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4561 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004562 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004563 mApp, subId, callingPackage, callingFeatureId,
4564 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004565 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4566 }
4567
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004568 final long identity = Binder.clearCallingIdentity();
4569 try {
4570 final Phone phone = getPhone(subId);
4571 if (phone != null) {
4572 return phone.getServiceState().getDataNetworkType();
4573 } else {
4574 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4575 }
4576 } finally {
4577 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004578 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004579 }
4580
4581 /**
Wink Saville36469e72014-06-11 15:17:00 -07004582 * Returns the Voice network type for a subId
4583 */
4584 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004585 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4586 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004587 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004588 mApp, subId, callingPackage, callingFeatureId,
4589 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004590 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4591 }
4592
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004593 final long identity = Binder.clearCallingIdentity();
4594 try {
4595 final Phone phone = getPhone(subId);
4596 if (phone != null) {
4597 return phone.getServiceState().getVoiceNetworkType();
4598 } else {
4599 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4600 }
4601 } finally {
4602 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004603 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004604 }
4605
4606 /**
4607 * @return true if a ICC card is present
4608 */
4609 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004610 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004611 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4612 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004613 }
4614
4615 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004616 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004617 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004618 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004619 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004620 final long identity = Binder.clearCallingIdentity();
4621 try {
4622 final Phone phone = PhoneFactory.getPhone(slotIndex);
4623 if (phone != null) {
4624 return phone.getIccCard().hasIccCard();
4625 } else {
4626 return false;
4627 }
4628 } finally {
4629 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004631 }
4632
4633 /**
4634 * Return if the current radio is LTE on CDMA. This
4635 * is a tri-state return value as for a period of time
4636 * the mode may be unknown.
4637 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004638 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004639 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004640 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004641 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004642 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004643 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4644 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4645 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004646 }
4647
Sanket Padawe356d7632015-06-22 14:03:32 -07004648 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004649 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4650 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004651 try {
4652 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4653 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004654 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4655 }
4656
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004657 final long identity = Binder.clearCallingIdentity();
4658 try {
4659 final Phone phone = getPhone(subId);
4660 if (phone == null) {
4661 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4662 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004663 return TelephonyProperties.lte_on_cdma_device()
4664 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004665 }
4666 } finally {
4667 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004668 }
Wink Saville36469e72014-06-11 15:17:00 -07004669 }
4670
Wink Saville36469e72014-06-11 15:17:00 -07004671 /**
4672 * {@hide}
4673 * Returns Default subId, 0 in the case of single standby.
4674 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004675 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004676 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004677 }
4678
Shishir Agrawala9f32182016-04-12 12:00:16 -07004679 private int getSlotForDefaultSubscription() {
4680 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4681 }
4682
Wink Savilleb564aae2014-10-23 10:18:09 -07004683 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004684 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004685 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004686
Pengquan Menge92a50d2018-09-21 15:54:48 -07004687 private boolean isActiveSubscription(int subId) {
4688 return mSubscriptionController.isActiveSubId(subId);
4689 }
4690
Ihab Awadf2177b72013-11-25 13:33:23 -08004691 /**
4692 * @see android.telephony.TelephonyManager.WifiCallingChoices
4693 */
4694 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004695 final long identity = Binder.clearCallingIdentity();
4696 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004697 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004698 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4699 getWhenToMakeWifiCallsDefaultPreference());
4700 } finally {
4701 Binder.restoreCallingIdentity(identity);
4702 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004703 }
4704
4705 /**
4706 * @see android.telephony.TelephonyManager.WifiCallingChoices
4707 */
4708 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004709 final long identity = Binder.clearCallingIdentity();
4710 try {
4711 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004712 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004713 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4714 } finally {
4715 Binder.restoreCallingIdentity(identity);
4716 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004717 }
4718
Sailesh Nepald1e68152013-12-12 19:08:02 -08004719 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004720 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004721 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004722 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004723
Jordan Liu4c733742019-02-28 12:03:40 -08004724 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4725 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4726 if (phoneId == -1) {
4727 throw new IllegalArgumentException("Given slot index: " + slotIndex
4728 + " does not correspond to an active phone");
4729 }
4730 return PhoneFactory.getPhone(phoneId);
4731 }
4732
Shishir Agrawal566b7612013-10-28 14:41:00 -07004733 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004734 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4735 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4737 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004738 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004739 if (DBG) {
4740 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4741 }
4742 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4743 p2);
4744 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004745
Jordan Liu4c733742019-02-28 12:03:40 -08004746
4747 @Override
4748 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4749 int slotIndex, String callingPackage, String aid, int p2) {
4750 enforceModifyPermission();
4751 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4752 if (DBG) {
4753 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4754 }
4755 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4756 callingPackage, aid, p2);
4757 }
4758
4759 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4760 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004761 final long identity = Binder.clearCallingIdentity();
4762 try {
4763 if (TextUtils.equals(ISDR_AID, aid)) {
4764 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004765 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4766 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004767 if (bestComponent == null
4768 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4769 loge("The calling package is not allowed to access ISD-R.");
4770 throw new SecurityException(
4771 "The calling package is not allowed to access ISD-R.");
4772 }
Derek Tan740e1672017-06-27 14:56:27 -07004773 }
Derek Tan740e1672017-06-27 14:56:27 -07004774
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004775 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004776 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4777 null /* workSource */);
4778 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004779 return response;
4780 } finally {
4781 Binder.restoreCallingIdentity(identity);
4782 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004783 }
4784
4785 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004786 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4788 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004789 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4790 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4791 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004792
Jordan Liu4c733742019-02-28 12:03:40 -08004793 @Override
4794 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4795 enforceModifyPermission();
4796 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4797 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4798 channel);
4799 }
4800
4801 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004802 final long identity = Binder.clearCallingIdentity();
4803 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004804 if (channel < 0) {
4805 return false;
4806 }
Jordan Liu4c733742019-02-28 12:03:40 -08004807 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4808 null /* workSource */);
4809 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004810 return success;
4811 } finally {
4812 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004813 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004814 }
4815
4816 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004817 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004818 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4820 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004821 if (DBG) {
4822 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4823 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4824 + p3 + " data=" + data);
4825 }
4826 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4827 command, p1, p2, p3, data);
4828 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004829
Jordan Liu4c733742019-02-28 12:03:40 -08004830 @Override
4831 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4832 int command, int p1, int p2, int p3, String data) {
4833 enforceModifyPermission();
4834 if (DBG) {
4835 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4836 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4837 + p3 + " data=" + data);
4838 }
4839 return iccTransmitApduLogicalChannelWithPermission(
4840 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4841 data);
4842 }
4843
4844 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4845 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004846 final long identity = Binder.clearCallingIdentity();
4847 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004848 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004849 return "";
4850 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004851
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004852 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004853 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4854 null /* workSource */);
4855 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004856
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004857 // Append the returned status code to the end of the response payload.
4858 String s = Integer.toHexString(
4859 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4860 if (response.payload != null) {
4861 s = IccUtils.bytesToHexString(response.payload) + s;
4862 }
4863 return s;
4864 } finally {
4865 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004866 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004867 }
Jake Hambye994d462014-02-03 13:10:13 -08004868
Evan Charltonc66da362014-05-16 14:06:40 -07004869 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004870 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4871 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4873 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004874 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004875 if (DBG) {
4876 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4877 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4878 }
4879 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4880 cla, command, p1, p2, p3, data);
4881 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004882
Jordan Liu4c733742019-02-28 12:03:40 -08004883 @Override
4884 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4885 int command, int p1, int p2, int p3, String data) {
4886 enforceModifyPermission();
4887 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4888 if (DBG) {
4889 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4890 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4891 + " data=" + data);
4892 }
4893
4894 return iccTransmitApduBasicChannelWithPermission(
4895 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4896 p2, p3, data);
4897 }
4898
4899 // open APDU basic channel assuming the caller has sufficient permissions
4900 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4901 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004902 final long identity = Binder.clearCallingIdentity();
4903 try {
4904 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4905 && TextUtils.equals(ISDR_AID, data)) {
4906 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004907 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4908 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004909 if (bestComponent == null
4910 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4911 loge("The calling package is not allowed to select ISD-R.");
4912 throw new SecurityException(
4913 "The calling package is not allowed to select ISD-R.");
4914 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004915 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004916
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004917 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004918 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4919 null /* workSource */);
4920 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004921
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004922 // Append the returned status code to the end of the response payload.
4923 String s = Integer.toHexString(
4924 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4925 if (response.payload != null) {
4926 s = IccUtils.bytesToHexString(response.payload) + s;
4927 }
4928 return s;
4929 } finally {
4930 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004931 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004932 }
4933
4934 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004935 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004936 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4938 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004940 final long identity = Binder.clearCallingIdentity();
4941 try {
4942 if (DBG) {
4943 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4944 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4945 }
4946
4947 IccIoResult response =
4948 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4949 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4950 subId);
4951
4952 if (DBG) {
4953 log("Exchange SIM_IO [R]" + response);
4954 }
4955
4956 byte[] result = null;
4957 int length = 2;
4958 if (response.payload != null) {
4959 length = 2 + response.payload.length;
4960 result = new byte[length];
4961 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4962 } else {
4963 result = new byte[length];
4964 }
4965
4966 result[length - 1] = (byte) response.sw2;
4967 result[length - 2] = (byte) response.sw1;
4968 return result;
4969 } finally {
4970 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004971 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004972 }
4973
Nathan Haroldb3014052017-01-25 15:57:32 -08004974 /**
4975 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4976 * on a particular subscription
4977 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004978 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4979 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004980 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004981 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004982 return null;
4983 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004984
4985 final long identity = Binder.clearCallingIdentity();
4986 try {
4987 if (appType != TelephonyManager.APPTYPE_USIM
4988 && appType != TelephonyManager.APPTYPE_SIM) {
4989 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4990 return null;
4991 }
4992 Object response = sendRequest(
4993 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4994 if (response instanceof String[]) {
4995 return (String[]) response;
4996 }
yincheng zhao2737e882019-09-06 17:06:54 -07004997 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004998 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004999 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005000 } finally {
5001 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005002 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005003 }
5004
yincheng zhao2737e882019-09-06 17:06:54 -07005005 /**
5006 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5007 * subscription.
5008 *
5009 * @param subId the id of the subscription.
5010 * @param appType the uicc app type, must be USIM or SIM.
5011 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5012 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005013 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005014 * @return number of fplmns that is successfully written to the SIM.
5015 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005016 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5017 String callingFeatureId) {
5018 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5019 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005020 if (DBG) logv("no permissions for setForbiddenplmns");
5021 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5022 }
5023 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5024 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5025 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5026 }
5027 if (fplmns == null) {
5028 throw new IllegalArgumentException("Fplmn List provided is null");
5029 }
5030 for (String fplmn : fplmns) {
5031 if (!CellIdentity.isValidPlmn(fplmn)) {
5032 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5033 }
5034 }
5035 final long identity = Binder.clearCallingIdentity();
5036 try {
5037 Object response = sendRequest(
5038 CMD_SET_FORBIDDEN_PLMNS,
5039 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5040 subId);
5041 return (int) response;
5042 } finally {
5043 Binder.restoreCallingIdentity(identity);
5044 }
5045 }
5046
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005047 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005048 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5050 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052 final long identity = Binder.clearCallingIdentity();
5053 try {
5054 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5055 if (response.payload == null) {
5056 return "";
5057 }
Evan Charltonc66da362014-05-16 14:06:40 -07005058
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005059 // Append the returned status code to the end of the response payload.
5060 String s = Integer.toHexString(
5061 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5062 s = IccUtils.bytesToHexString(response.payload) + s;
5063 return s;
5064 } finally {
5065 Binder.restoreCallingIdentity(identity);
5066 }
Evan Charltonc66da362014-05-16 14:06:40 -07005067 }
5068
Jake Hambye994d462014-02-03 13:10:13 -08005069 /**
5070 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5071 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5072 *
5073 * @param itemID the ID of the item to read
5074 * @return the NV item as a String, or null on error.
5075 */
5076 @Override
5077 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005078 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5080 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081
5082 final long identity = Binder.clearCallingIdentity();
5083 try {
5084 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005085 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005086 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5087 return value;
5088 } finally {
5089 Binder.restoreCallingIdentity(identity);
5090 }
Jake Hambye994d462014-02-03 13:10:13 -08005091 }
5092
5093 /**
5094 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5095 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5096 *
5097 * @param itemID the ID of the item to read
5098 * @param itemValue the value to write, as a String
5099 * @return true on success; false on any failure
5100 */
5101 @Override
5102 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005103 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005104 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5105 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005106
5107 final long identity = Binder.clearCallingIdentity();
5108 try {
5109 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5110 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005111 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005112 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5113 return success;
5114 } finally {
5115 Binder.restoreCallingIdentity(identity);
5116 }
Jake Hambye994d462014-02-03 13:10:13 -08005117 }
5118
5119 /**
5120 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5121 * Used for device configuration by some CDMA operators.
5122 *
5123 * @param preferredRoamingList byte array containing the new PRL
5124 * @return true on success; false on any failure
5125 */
5126 @Override
5127 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5129 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005130
5131 final long identity = Binder.clearCallingIdentity();
5132 try {
5133 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5134 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5135 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5136 return success;
5137 } finally {
5138 Binder.restoreCallingIdentity(identity);
5139 }
Jake Hambye994d462014-02-03 13:10:13 -08005140 }
5141
5142 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005143 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005144 * Used for device configuration by some CDMA operators.
5145 *
chen xu6dac5ab2018-10-26 17:39:23 -07005146 * @param slotIndex - device slot.
5147 *
Jake Hambye994d462014-02-03 13:10:13 -08005148 * @return true on success; false on any failure
5149 */
5150 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005151 public boolean resetModemConfig(int slotIndex) {
5152 Phone phone = PhoneFactory.getPhone(slotIndex);
5153 if (phone != null) {
5154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5155 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005156
chen xu6dac5ab2018-10-26 17:39:23 -07005157 final long identity = Binder.clearCallingIdentity();
5158 try {
5159 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5160 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5161 return success;
5162 } finally {
5163 Binder.restoreCallingIdentity(identity);
5164 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005165 }
chen xu6dac5ab2018-10-26 17:39:23 -07005166 return false;
5167 }
5168
5169 /**
5170 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5171 *
5172 * @param slotIndex - device slot.
5173 *
5174 * @return true on success; false on any failure
5175 */
5176 @Override
5177 public boolean rebootModem(int slotIndex) {
5178 Phone phone = PhoneFactory.getPhone(slotIndex);
5179 if (phone != null) {
5180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5181 mApp, phone.getSubId(), "rebootModem");
5182
5183 final long identity = Binder.clearCallingIdentity();
5184 try {
5185 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5186 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5187 return success;
5188 } finally {
5189 Binder.restoreCallingIdentity(identity);
5190 }
5191 }
5192 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005193 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005194
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005195 public String[] getPcscfAddress(String apnType, String callingPackage,
5196 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005197 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005198 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5199 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005200 return new String[0];
5201 }
5202
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005203 final long identity = Binder.clearCallingIdentity();
5204 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005205 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005206 } finally {
5207 Binder.restoreCallingIdentity(identity);
5208 }
Wink Saville36469e72014-06-11 15:17:00 -07005209 }
5210
Brad Ebinger51f743a2017-01-23 13:50:20 -08005211 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005212 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5213 * {@link #disableIms(int)}.
5214 * @param slotIndex device slot.
5215 */
5216 public void resetIms(int slotIndex) {
5217 enforceModifyPermission();
5218
5219 final long identity = Binder.clearCallingIdentity();
5220 try {
5221 if (mImsResolver == null) {
5222 // may happen if the does not support IMS.
5223 return;
5224 }
5225 mImsResolver.disableIms(slotIndex);
5226 mImsResolver.enableIms(slotIndex);
5227 } finally {
5228 Binder.restoreCallingIdentity(identity);
5229 }
5230 }
5231
5232 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005233 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5234 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005235 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005236 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005237 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238
5239 final long identity = Binder.clearCallingIdentity();
5240 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005241 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005242 // may happen if the device does not support IMS.
5243 return;
5244 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005245 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246 } finally {
5247 Binder.restoreCallingIdentity(identity);
5248 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005249 }
5250
5251 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005252 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5253 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005254 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005255 public void disableIms(int slotId) {
5256 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257
5258 final long identity = Binder.clearCallingIdentity();
5259 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005260 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005261 // may happen if the device does not support IMS.
5262 return;
5263 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005264 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005265 } finally {
5266 Binder.restoreCallingIdentity(identity);
5267 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005268 }
5269
5270 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005271 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5272 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005273 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005274 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005275 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005276 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005277
5278 final long identity = Binder.clearCallingIdentity();
5279 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005280 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005281 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5282 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005283 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005284 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005285 } finally {
5286 Binder.restoreCallingIdentity(identity);
5287 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005288 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005289 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005290 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5291 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005292 @Override
5293 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005294 enforceModifyPermission();
5295
5296 final long identity = Binder.clearCallingIdentity();
5297 try {
5298 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005299 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005300 } finally {
5301 Binder.restoreCallingIdentity(identity);
5302 }
5303 }
5304
5305 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005306 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005307 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005308 */
5309 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5310 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311
5312 final long identity = Binder.clearCallingIdentity();
5313 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005314 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005315 // may happen if the device does not support IMS.
5316 return null;
5317 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005318 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319 } finally {
5320 Binder.restoreCallingIdentity(identity);
5321 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005322 }
5323
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005324 /**
5325 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005326 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005327 */
5328 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5329 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005330
5331 final long identity = Binder.clearCallingIdentity();
5332 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005333 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005334 // may happen if the device does not support IMS.
5335 return null;
5336 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005337 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 } finally {
5339 Binder.restoreCallingIdentity(identity);
5340 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005341 }
5342
Brad Ebinger884c07b2018-02-15 16:17:40 -08005343 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005344 * Sets the ImsService Package Name that Telephony will bind to.
5345 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005346 * @param slotIndex the slot ID that the ImsService should bind for.
5347 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005348 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005349 * @param featureTypes An integer array of feature types associated with a packageName.
5350 * @param packageName The name of the package that the current configuration will be replaced
5351 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005352 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005353 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005354 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5355 int[] featureTypes, String packageName) {
5356 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5357 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5359 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005360 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005361
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005362 final long identity = Binder.clearCallingIdentity();
5363 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005364 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005365 // may happen if the device does not support IMS.
5366 return false;
5367 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005368 Map<Integer, String> featureConfig = new HashMap<>();
5369 for (int featureType : featureTypes) {
5370 featureConfig.put(featureType, packageName);
5371 }
5372 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5373 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005374 } finally {
5375 Binder.restoreCallingIdentity(identity);
5376 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005377 }
5378
5379 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005380 * Clears any carrier ImsService overrides for the slot index specified that were previously
5381 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5382 *
5383 * This should only be used for testing.
5384 *
5385 * @param slotIndex the slot ID that the ImsService should bind for.
5386 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5387 */
5388 @Override
5389 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5390 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5391 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5392 "clearCarrierImsServiceOverride");
5393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5394 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5395 "clearCarrierImsServiceOverride");
5396
5397 final long identity = Binder.clearCallingIdentity();
5398 try {
5399 if (mImsResolver == null) {
5400 // may happen if the device does not support IMS.
5401 return false;
5402 }
5403 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5404 } finally {
5405 Binder.restoreCallingIdentity(identity);
5406 }
5407 }
5408
5409 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005410 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005411 *
5412 * @param slotId The slot that the ImsService is associated with.
5413 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5414 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005415 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005416 * @return the package name of the ImsService configuration.
5417 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005418 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5419 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005420 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005421 TelephonyPermissions
5422 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5423 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5424 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005425
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426 final long identity = Binder.clearCallingIdentity();
5427 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005428 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005429 // may happen if the device does not support IMS.
5430 return "";
5431 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005432 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005433 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5434 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005435 } finally {
5436 Binder.restoreCallingIdentity(identity);
5437 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005438 }
5439
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005440 /**
5441 * Get the MmTelFeature state associated with the requested subscription id.
5442 * @param subId The subscription that the MmTelFeature is associated with.
5443 * @param callback A callback with an integer containing the
5444 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5445 */
5446 @Override
5447 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5448 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5449 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5450 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5451 "IMS not available on device.");
5452 }
5453 final long token = Binder.clearCallingIdentity();
5454 try {
5455 int slotId = getSlotIndex(subId);
5456 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5457 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5458 + subId + "'");
5459 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5460 }
5461 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5462 try {
5463 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5464 } catch (RemoteException e) {
5465 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5466 + "Ignore");
5467 }
5468 });
5469 } finally {
5470 Binder.restoreCallingIdentity(token);
5471 }
5472 }
5473
Wink Saville36469e72014-06-11 15:17:00 -07005474 public void setImsRegistrationState(boolean registered) {
5475 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476
5477 final long identity = Binder.clearCallingIdentity();
5478 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005479 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005480 } finally {
5481 Binder.restoreCallingIdentity(identity);
5482 }
Wink Saville36469e72014-06-11 15:17:00 -07005483 }
5484
5485 /**
Stuart Scott54788802015-03-30 13:18:01 -07005486 * Set the network selection mode to automatic.
5487 *
5488 */
5489 @Override
5490 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5492 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005493
5494 final long identity = Binder.clearCallingIdentity();
5495 try {
shilufc958392020-01-20 11:36:01 -08005496 if (!isActiveSubscription(subId)) {
5497 return;
5498 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005499 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5500 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5501 } finally {
5502 Binder.restoreCallingIdentity(identity);
5503 }
Stuart Scott54788802015-03-30 13:18:01 -07005504 }
5505
Jack Yud10cdd42020-09-28 20:28:01 -07005506 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005507 * Ask the radio to connect to the input network and change selection mode to manual.
5508 *
5509 * @param subId the id of the subscription.
5510 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5511 * the operator to attach to.
5512 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5513 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5514 * normal network selection next time.
5515 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005516 */
5517 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005518 public boolean setNetworkSelectionModeManual(
5519 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5521 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005522
5523 if (!isActiveSubscription(subId)) {
5524 return false;
5525 }
5526
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527 final long identity = Binder.clearCallingIdentity();
5528 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005529 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005531 if (DBG) {
5532 log("setNetworkSelectionModeManual: subId: " + subId
5533 + " operator: " + operatorInfo);
5534 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005535 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5536 } finally {
5537 Binder.restoreCallingIdentity(identity);
5538 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005539 }
shilu84f6e8b2019-12-19 13:58:01 -08005540 /**
5541 * Get the manual network selection
5542 *
5543 * @param subId the id of the subscription.
5544 *
5545 * @return the previously saved user selected PLMN
5546 */
5547 @Override
5548 public String getManualNetworkSelectionPlmn(int subId) {
5549 TelephonyPermissions
5550 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5551 mApp, subId, "getManualNetworkSelectionPlmn");
5552
5553 final long identity = Binder.clearCallingIdentity();
5554 try {
5555 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005556 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005557 }
5558
5559 final Phone phone = getPhone(subId);
5560 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005561 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005562 }
5563 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5564 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5565 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5566 } finally {
5567 Binder.restoreCallingIdentity(identity);
5568 }
5569 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005570
5571 /**
5572 * Scans for available networks.
5573 */
5574 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005575 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5576 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005577 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5578 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005579 LocationAccessPolicy.LocationPermissionResult locationResult =
5580 LocationAccessPolicy.checkLocationPermission(mApp,
5581 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5582 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005583 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005584 .setCallingPid(Binder.getCallingPid())
5585 .setCallingUid(Binder.getCallingUid())
5586 .setMethod("getCellNetworkScanResults")
5587 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005588 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5589 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005590 .build());
5591 switch (locationResult) {
5592 case DENIED_HARD:
5593 throw new SecurityException("Not allowed to access scan results -- location");
5594 case DENIED_SOFT:
5595 return null;
5596 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005597
Pengquan Menga1bb6272018-09-06 09:59:22 -07005598 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599 try {
5600 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005601 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005602 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603 } finally {
5604 Binder.restoreCallingIdentity(identity);
5605 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005606 }
5607
5608 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005609 * Get the call forwarding info, given the call forwarding reason.
5610 */
5611 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005612 public void getCallForwarding(int subId, int callForwardingReason,
5613 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005614 enforceReadPrivilegedPermission("getCallForwarding");
5615 long identity = Binder.clearCallingIdentity();
5616 try {
5617 if (DBG) {
5618 log("getCallForwarding: subId " + subId
5619 + " callForwardingReason" + callForwardingReason);
5620 }
Hall Liu27d24262020-09-18 19:04:59 -07005621
5622 Phone phone = getPhone(subId);
5623 if (phone == null) {
5624 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005625 callback.onError(
5626 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005627 } catch (RemoteException e) {
5628 // ignore
5629 }
5630 return;
5631 }
5632
5633 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5634 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5635 @Override
5636 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5637 try {
5638 callback.onCallForwardingInfoAvailable(info);
5639 } catch (RemoteException e) {
5640 // ignore
5641 }
5642 }
5643
5644 @Override
5645 public void onError(int error) {
5646 try {
5647 callback.onError(error);
5648 } catch (RemoteException e) {
5649 // ignore
5650 }
5651 }
5652 });
5653 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005654 } finally {
5655 Binder.restoreCallingIdentity(identity);
5656 }
5657 }
5658
5659 /**
5660 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5661 * reason, the number to forward, and the timeout before the forwarding is attempted.
5662 */
5663 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005664 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5665 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005666 enforceModifyPermission();
5667 long identity = Binder.clearCallingIdentity();
5668 try {
5669 if (DBG) {
5670 log("setCallForwarding: subId " + subId
5671 + " callForwardingInfo" + callForwardingInfo);
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.accept(
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<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5686 FunctionalUtils.ignoreRemoteException(callback::accept));
5687
5688 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005689 } finally {
5690 Binder.restoreCallingIdentity(identity);
5691 }
5692 }
5693
5694 /**
Hall Liu27d24262020-09-18 19:04:59 -07005695 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005696 */
5697 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005698 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005699 enforceReadPrivilegedPermission("getCallForwarding");
5700 long identity = Binder.clearCallingIdentity();
5701 try {
Hall Liu27d24262020-09-18 19:04:59 -07005702
5703 Phone phone = getPhone(subId);
5704 if (phone == null) {
5705 try {
5706 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5707 } catch (RemoteException e) {
5708 // ignore
5709 }
5710 return;
5711 }
5712
5713 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5714
Shuo Qian4a594052020-01-23 11:59:30 -08005715 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005716 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005717 } finally {
5718 Binder.restoreCallingIdentity(identity);
5719 }
5720 }
5721
5722 /**
Hall Liu27d24262020-09-18 19:04:59 -07005723 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005724 */
5725 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005726 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005727 enforceModifyPermission();
5728 long identity = Binder.clearCallingIdentity();
5729 try {
Hall Liu27d24262020-09-18 19:04:59 -07005730 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5731
5732 Phone phone = getPhone(subId);
5733 if (phone == null) {
5734 try {
5735 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5736 } catch (RemoteException e) {
5737 // ignore
5738 }
5739 return;
5740 }
5741
5742 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5743 FunctionalUtils.ignoreRemoteException(callback::accept));
5744
5745 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005746 } finally {
5747 Binder.restoreCallingIdentity(identity);
5748 }
5749 }
5750
5751 /**
yinxub1bed742017-04-17 11:45:04 -07005752 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005753 *
yinxub1bed742017-04-17 11:45:04 -07005754 * @param subId id of the subscription
5755 * @param request contains the radio access networks with bands/channels to scan
5756 * @param messenger callback messenger for scan results or errors
5757 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005758 * @return the id of the requested scan which can be used to stop the scan.
5759 */
5760 @Override
5761 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005762 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005763 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5764 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005765 LocationAccessPolicy.LocationPermissionResult locationResult =
5766 LocationAccessPolicy.checkLocationPermission(mApp,
5767 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5768 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005769 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005770 .setCallingPid(Binder.getCallingPid())
5771 .setCallingUid(Binder.getCallingUid())
5772 .setMethod("requestNetworkScan")
5773 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005774 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5775 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005776 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005777 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005778 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5779 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005780 if (e != null) {
5781 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5782 throw e;
5783 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005784 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005785 return TelephonyScanManager.INVALID_SCAN_ID;
5786 }
5787 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005788 }
Hall Liu912dfd32019-04-25 14:02:26 -07005789 int callingUid = Binder.getCallingUid();
5790 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005791 final long identity = Binder.clearCallingIdentity();
5792 try {
5793 return mNetworkScanRequestTracker.startNetworkScan(
5794 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005795 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005796 } finally {
5797 Binder.restoreCallingIdentity(identity);
5798 }
yinxu504e1392017-04-12 16:03:22 -07005799 }
5800
Hall Liub2ac8ef2019-02-28 15:56:23 -08005801 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005802 NetworkScanRequest request, int subId, String callingPackage) {
5803 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005804 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5805 boolean hasNetworkScanPermission =
5806 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5807 == PERMISSION_GRANTED;
5808
5809 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5810 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5811 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005812 }
5813
5814 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5815 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005816 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5817 return new SecurityException("Specific channels must not be"
5818 + " scanned without location access.");
5819 }
5820 }
5821 }
5822
Hall Liub2ac8ef2019-02-28 15:56:23 -08005823 return null;
5824 }
5825
yinxu504e1392017-04-12 16:03:22 -07005826 /**
5827 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005828 *
5829 * @param subId id of the subscription
5830 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005831 */
5832 @Override
5833 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5835 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005836
Hall Liu912dfd32019-04-25 14:02:26 -07005837 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005838 final long identity = Binder.clearCallingIdentity();
5839 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005840 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005841 } finally {
5842 Binder.restoreCallingIdentity(identity);
5843 }
yinxu504e1392017-04-12 16:03:22 -07005844 }
5845
5846 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005847 * Get the calculated preferred network type.
5848 * Used for debugging incorrect network type.
5849 *
5850 * @return the preferred network type, defined in RILConstants.java.
5851 */
5852 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005853 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005854 final Phone defaultPhone = getDefaultPhone();
5855 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005856 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005857 return RILConstants.PREFERRED_NETWORK_MODE;
5858 }
5859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860 final long identity = Binder.clearCallingIdentity();
5861 try {
5862 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005863 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005864 } finally {
5865 Binder.restoreCallingIdentity(identity);
5866 }
Junda Liu84d15a22014-07-02 11:21:04 -07005867 }
5868
5869 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005870 * Get the preferred network type.
5871 * Used for device configuration by some CDMA operators.
5872 *
5873 * @return the preferred network type, defined in RILConstants.java.
5874 */
5875 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005876 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005877 TelephonyPermissions
5878 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5879 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005880
5881 final long identity = Binder.clearCallingIdentity();
5882 try {
5883 if (DBG) log("getPreferredNetworkType");
5884 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5885 int networkType = (result != null ? result[0] : -1);
5886 if (DBG) log("getPreferredNetworkType: " + networkType);
5887 return networkType;
5888 } finally {
5889 Binder.restoreCallingIdentity(identity);
5890 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005891 }
5892
5893 /**
5894 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005895 *
5896 * @param networkType the preferred network type, defined in RILConstants.java.
5897 * @return true on success; false on any failure.
5898 */
5899 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005900 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5902 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005903
5904 final long identity = Binder.clearCallingIdentity();
5905 try {
calvinpan8ed33732020-03-12 14:17:55 +08005906 Boolean success = (Boolean) sendRequest(
5907 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005908
5909 if (success) {
5910 Settings.Global.putInt(mApp.getContentResolver(),
5911 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5912 }
calvinpan8ed33732020-03-12 14:17:55 +08005913 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5914 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915 } finally {
5916 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005917 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005918 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005919
5920 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005921 * Get the allowed network types that store in the telephony provider.
5922 *
5923 * @param subId the id of the subscription.
5924 * @return allowedNetworkTypes the allowed network types.
5925 */
5926 @Override
5927 public long getAllowedNetworkTypes(int subId) {
5928 TelephonyPermissions
5929 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5930 mApp, subId, "getAllowedNetworkTypes");
5931
5932 final long identity = Binder.clearCallingIdentity();
5933 try {
5934 return SubscriptionManager.getLongSubscriptionProperty(
5935 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5936 } finally {
5937 Binder.restoreCallingIdentity(identity);
5938 }
5939 }
5940
5941 /**
5942 * Set the allowed network types.
5943 *
5944 * @param subId the id of the subscription.
5945 * @param allowedNetworkTypes the allowed network types.
5946 * @return true on success; false on any failure.
5947 */
5948 @Override
5949 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5951 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005952
calvinpan8ed33732020-03-12 14:17:55 +08005953 SubscriptionManager.setSubscriptionProperty(subId,
5954 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5955 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005956
calvinpan8ed33732020-03-12 14:17:55 +08005957 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5958 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5959 RILConstants.PREFERRED_NETWORK_MODE);
5960 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005961 }
5962
5963 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005964 * Get the allowed network types for certain reason.
5965 *
5966 * @param subId the id of the subscription.
5967 * @param reason the reason the allowed network type change is taking place
5968 * @return the allowed network types.
5969 */
5970 @Override
5971 public long getAllowedNetworkTypesForReason(int subId,
5972 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5973 TelephonyPermissions
5974 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5975 mApp, subId, "getAllowedNetworkTypesForReason");
5976 final long identity = Binder.clearCallingIdentity();
5977 try {
5978 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5979 } finally {
5980 Binder.restoreCallingIdentity(identity);
5981 }
5982 }
5983
5984 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07005985 * Enable/Disable E-UTRA-NR Dual Connectivity
5986 * @param subId subscription id of the sim card
5987 * @param nrDualConnectivityState expected NR dual connectivity state
5988 * This can be passed following states
5989 * <ol>
5990 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
5991 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
5992 * <li>Disable NR dual connectivity and force secondary cell to be released
5993 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
5994 * </ol>
5995 * @return operation result.
5996 */
5997 @Override
5998 public int setNrDualConnectivityState(int subId,
5999 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6001 mApp, subId, "enableNRDualConnectivity");
6002 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6003 final long identity = Binder.clearCallingIdentity();
6004 try {
6005 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6006 nrDualConnectivityState, subId,
6007 workSource);
6008 if (DBG) log("enableNRDualConnectivity result: " + result);
6009 return result;
6010 } finally {
6011 Binder.restoreCallingIdentity(identity);
6012 }
6013 }
6014
6015 /**
6016 * Is E-UTRA-NR Dual Connectivity enabled
6017 * @return true if dual connectivity is enabled else false
6018 */
6019 @Override
6020 public boolean isNrDualConnectivityEnabled(int subId) {
6021 TelephonyPermissions
6022 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6023 mApp, subId, "isNRDualConnectivityEnabled");
6024 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6025 final long identity = Binder.clearCallingIdentity();
6026 try {
6027 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6028 null, subId, workSource);
6029 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6030 return isEnabled;
6031 } finally {
6032 Binder.restoreCallingIdentity(identity);
6033 }
6034 }
6035
6036 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07006037 * get carrier bandwidth per primary and secondary carrier
6038 * @param subId subscription id of the sim card
6039 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6040 */
6041 @Override
6042 public CarrierBandwidth getCarrierBandwidth(int subId) {
6043 TelephonyPermissions
6044 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6045 mApp, subId, "isNRDualConnectivityEnabled");
6046 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6047 final long identity = Binder.clearCallingIdentity();
6048 try {
6049 CarrierBandwidth carrierBandwidth =
6050 getPhoneFromSubId(subId).getCarrierBandwidth();
6051 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6052 return carrierBandwidth;
6053 } finally {
6054 Binder.restoreCallingIdentity(identity);
6055 }
6056 }
6057
6058 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006059 * Get the effective allowed network types on the device.
6060 * This API will return an intersection of allowed network types for all reasons,
6061 * including the configuration done through setAllowedNetworkTypes
6062 *
6063 * @param subId the id of the subscription.
6064 * @return the allowed network types
6065 */
6066 @Override
6067 public long getEffectiveAllowedNetworkTypes(int subId) {
6068 TelephonyPermissions
6069 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6070 mApp, subId, "getEffectiveAllowedNetworkTypes");
6071 final long identity = Binder.clearCallingIdentity();
6072 try {
6073 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6074 } finally {
6075 Binder.restoreCallingIdentity(identity);
6076 }
6077 }
6078
6079 /**
6080 * Set the allowed network types of the device and
6081 * provide the reason triggering the allowed network change.
6082 *
6083 * @param subId the id of the subscription.
6084 * @param reason the reason the allowed network type change is taking place
6085 * @param allowedNetworkTypes the allowed network types.
6086 * @return true on success; false on any failure.
6087 */
6088 @Override
6089 public boolean setAllowedNetworkTypesForReason(int subId,
6090 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6092 mApp, subId, "setAllowedNetworkTypesForReason");
6093 final long identity = Binder.clearCallingIdentity();
6094 try {
6095 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6096 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6097 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6098 RILConstants.PREFERRED_NETWORK_MODE);
6099 return setPreferredNetworkType(subId, preferredNetworkMode);
6100 } finally {
6101 Binder.restoreCallingIdentity(identity);
6102 }
6103 }
6104
6105 /**
Miaoa84611c2019-03-15 09:21:10 +08006106 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006107 *
Miaoa84611c2019-03-15 09:21:10 +08006108 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006109 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006110 * @hide
6111 */
6112 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006113 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006114 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006116 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117 try {
Miaoa84611c2019-03-15 09:21:10 +08006118 if (phone != null) {
6119 return phone.hasMatchedTetherApnSetting();
6120 } else {
6121 return false;
6122 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006123 } finally {
6124 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006125 }
Junda Liu475951f2014-11-07 16:45:03 -08006126 }
6127
6128 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006129 * Enable or disable always reporting signal strength changes from radio.
6130 *
6131 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6132 */
6133 @Override
6134 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6135 enforceModifyPermission();
6136 enforceSystemCaller();
6137
6138 final long identity = Binder.clearCallingIdentity();
6139 final Phone phone = getPhone(subId);
6140 try {
6141 if (phone != null) {
6142 if (DBG) {
6143 log("setAlwaysReportSignalStrength: subId=" + subId
6144 + " isEnable=" + isEnable);
6145 }
6146 phone.setAlwaysReportSignalStrength(isEnable);
6147 } else {
6148 loge("setAlwaysReportSignalStrength: no phone found for subId="
6149 + subId);
6150 }
6151 } finally {
6152 Binder.restoreCallingIdentity(identity);
6153 }
6154 }
6155
6156 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006157 * Get the user enabled state of Mobile Data.
6158 *
6159 * TODO: remove and use isUserDataEnabled.
6160 * This can't be removed now because some vendor codes
6161 * calls through ITelephony directly while they should
6162 * use TelephonyManager.
6163 *
6164 * @return true on enabled
6165 */
6166 @Override
6167 public boolean getDataEnabled(int subId) {
6168 return isUserDataEnabled(subId);
6169 }
6170
6171 /**
6172 * Get whether mobile data is enabled per user setting.
6173 *
6174 * There are other factors deciding whether mobile data is actually enabled, but they are
6175 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006176 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006177 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006178 *
6179 * @return {@code true} if data is enabled else {@code false}
6180 */
6181 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006182 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006183 try {
6184 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6185 null);
6186 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6188 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006189 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006190
6191 final long identity = Binder.clearCallingIdentity();
6192 try {
6193 int phoneId = mSubscriptionController.getPhoneId(subId);
6194 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6195 Phone phone = PhoneFactory.getPhone(phoneId);
6196 if (phone != null) {
6197 boolean retVal = phone.isUserDataEnabled();
6198 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6199 return retVal;
6200 } else {
6201 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6202 return false;
6203 }
6204 } finally {
6205 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006206 }
6207 }
6208
6209 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006210 * Checks if the device is capable of mobile data by considering whether whether the
6211 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6212 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006213 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006214 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006215 */
6216 @Override
6217 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006218 try {
6219 try {
6220 mApp.enforceCallingOrSelfPermission(
6221 android.Manifest.permission.ACCESS_NETWORK_STATE,
6222 null);
6223 } catch (Exception e) {
6224 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6225 "isDataEnabled");
6226 }
6227 } catch (Exception e) {
6228 enforceReadPrivilegedPermission("isDataEnabled");
6229 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006230
6231 final long identity = Binder.clearCallingIdentity();
6232 try {
6233 int phoneId = mSubscriptionController.getPhoneId(subId);
6234 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6235 Phone phone = PhoneFactory.getPhone(phoneId);
6236 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006237 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006238 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6239 return retVal;
6240 } else {
6241 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6242 return false;
6243 }
6244 } finally {
6245 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006246 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006247 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006248
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006249 /**
6250 * Check if data is enabled for a specific reason
6251 * @param subId Subscription index
6252 * @param reason the reason the data enable change is taking place
6253 * @return {@code true} if the overall data is enabled; {@code false} if not.
6254 */
6255 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006256 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006257 @TelephonyManager.DataEnabledReason int reason) {
6258 try {
6259 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6260 null);
6261 } catch (Exception e) {
6262 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006263 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006264 }
6265
6266
6267 final long identity = Binder.clearCallingIdentity();
6268 try {
6269 int phoneId = mSubscriptionController.getPhoneId(subId);
6270 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006271 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006272 + " reason=" + reason);
6273 }
6274 Phone phone = PhoneFactory.getPhone(phoneId);
6275 if (phone != null) {
6276 boolean retVal;
6277 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6278 retVal = phone.isUserDataEnabled();
6279 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006280 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006281 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006282 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006283 return retVal;
6284 } else {
6285 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006286 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006287 + subId + " retVal=false");
6288 }
6289 return false;
6290 }
6291 } finally {
6292 Binder.restoreCallingIdentity(identity);
6293 }
6294 }
6295
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006296 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006297 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006298 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6299 // Skip the check if it's one of these special uids
6300 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6301 }
6302
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006303 //load access rules from carrier configs, and check those as well: b/139133814
6304 SubscriptionController subController = SubscriptionController.getInstance();
6305 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6306 || subController == null) return privilegeFromSim;
6307
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006308 PackageManager pkgMgr = phone.getContext().getPackageManager();
6309 String[] packages = pkgMgr.getPackagesForUid(uid);
6310
6311 final long identity = Binder.clearCallingIdentity();
6312 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006313 int subId = phone.getSubId();
6314 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6315 // A test override is in place for the privileges for this subId, so don't try to
6316 // read the subscription privileges.
6317 return privilegeFromSim;
6318 }
6319 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006320 SubscriptionManager subManager = (SubscriptionManager)
6321 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6322 for (String pkg : packages) {
6323 if (subManager.canManageSubscription(subInfo, pkg)) {
6324 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6325 }
6326 }
6327 return privilegeFromSim;
6328 } finally {
6329 Binder.restoreCallingIdentity(identity);
6330 }
6331 }
6332
6333 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6334 String pkgName) {
6335 //load access rules from carrier configs, and check those as well: b/139133814
6336 SubscriptionController subController = SubscriptionController.getInstance();
6337 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6338 || subController == null) return privilegeFromSim;
6339
6340 final long identity = Binder.clearCallingIdentity();
6341 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006342 int subId = phone.getSubId();
6343 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6344 // A test override is in place for the privileges for this subId, so don't try to
6345 // read the subscription privileges.
6346 return privilegeFromSim;
6347 }
6348 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006349 SubscriptionManager subManager = (SubscriptionManager)
6350 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6351 return subManager.canManageSubscription(subInfo, pkgName)
6352 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6353 } finally {
6354 Binder.restoreCallingIdentity(identity);
6355 }
6356 }
6357
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006358 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006359 public int getCarrierPrivilegeStatus(int subId) {
6360 final Phone phone = getPhone(subId);
6361 if (phone == null) {
6362 loge("getCarrierPrivilegeStatus: Invalid subId");
6363 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6364 }
6365 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006366 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006367 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006368 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6369 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006370
6371 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6372 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006373 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006374 }
Junda Liu29340342014-07-10 15:23:27 -07006375
6376 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006377 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006378 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006379 final Phone phone = getPhone(subId);
6380 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006381 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006382 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6383 }
6384 UiccProfile profile =
6385 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6386 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006387 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006388 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6389 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006390 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006391 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006392 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006393 }
6394
6395 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006396 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6397 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006398 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006399 }
6400
6401 int phoneId = SubscriptionManager.getPhoneId(subId);
6402 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006403 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006404 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006405 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6406 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006407 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6408 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6409 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006410 }
6411
6412 @Override
6413 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006414 if (TextUtils.isEmpty(pkgName))
6415 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006416 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6417 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6418 UiccCard card = UiccController.getInstance().getUiccCard(i);
6419 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006420 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006421 continue;
6422 }
6423
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006424 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6425 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6426 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006427 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6428 break;
6429 }
6430 }
6431
6432 return result;
Junda Liu29340342014-07-10 15:23:27 -07006433 }
Derek Tan89e89d42014-07-08 17:00:10 -07006434
6435 @Override
Junda Liue64de782015-04-16 17:19:16 -07006436 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6437 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6438 loge("phoneId " + phoneId + " is not valid.");
6439 return null;
6440 }
6441 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006442 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006443 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006444 return null ;
6445 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006446 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006447 }
6448
Amith Yamasani6e118872016-02-19 12:53:51 -08006449 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006450 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006451 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006452 List<String> privilegedPackages = new ArrayList<>();
6453 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006454 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6455 // has UICC in that slot.
6456 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006457 if (card.hasCarrierPrivilegeRules()) {
6458 if (packages == null) {
6459 // Only check packages in user 0 for now
6460 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006461 PackageManager.MATCH_DISABLED_COMPONENTS
6462 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006463 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006464 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006465 }
6466 for (int p = packages.size() - 1; p >= 0; p--) {
6467 PackageInfo pkgInfo = packages.get(p);
6468 if (pkgInfo != null && pkgInfo.packageName != null
6469 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006470 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006471 privilegedPackages.add(pkgInfo.packageName);
6472 }
6473 }
6474 }
6475 }
6476 return privilegedPackages;
6477 }
6478
chen xuf7e9fe82019-05-09 19:31:02 -07006479 @Override
6480 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006481 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6482
6483 final long identity = Binder.clearCallingIdentity();
6484
chen xuf7e9fe82019-05-09 19:31:02 -07006485 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006486 try {
6487 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6488 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6489 }
6490 } finally {
6491 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006492 }
6493 return privilegedPackages;
6494 }
6495
Wink Savilleb564aae2014-10-23 10:18:09 -07006496 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006497 final Phone phone = getPhone(subId);
6498 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006499 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006500 return null;
6501 }
6502 String iccId = card.getIccId();
6503 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006504 return null;
6505 }
6506 return iccId;
6507 }
6508
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006509 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006510 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6511 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006512 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006513 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006514
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006515 final long identity = Binder.clearCallingIdentity();
6516 try {
6517 final String iccId = getIccId(subId);
6518 final Phone phone = getPhone(subId);
6519 if (phone == null) {
6520 return false;
6521 }
6522 final String subscriberId = phone.getSubscriberId();
6523
6524 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006525 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006526 + subscriberId + " to " + number);
6527 }
6528
6529 if (TextUtils.isEmpty(iccId)) {
6530 return false;
6531 }
6532
6533 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6534
6535 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6536 if (alphaTag == null) {
6537 editor.remove(alphaTagPrefKey);
6538 } else {
6539 editor.putString(alphaTagPrefKey, alphaTag);
6540 }
6541
6542 // Record both the line number and IMSI for this ICCID, since we need to
6543 // track all merged IMSIs based on line number
6544 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6545 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6546 if (number == null) {
6547 editor.remove(numberPrefKey);
6548 editor.remove(subscriberPrefKey);
6549 } else {
6550 editor.putString(numberPrefKey, number);
6551 editor.putString(subscriberPrefKey, subscriberId);
6552 }
6553
6554 editor.commit();
6555 return true;
6556 } finally {
6557 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006558 }
Derek Tan7226c842014-07-02 17:42:23 -07006559 }
6560
6561 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006562 public String getLine1NumberForDisplay(int subId, String callingPackage,
6563 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006564 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006565 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006566 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006567 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006568 return null;
6569 }
Derek Tan97ebb422014-09-05 16:55:38 -07006570
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006571 final long identity = Binder.clearCallingIdentity();
6572 try {
6573 String iccId = getIccId(subId);
6574 if (iccId != null) {
6575 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6576 if (DBG_MERGE) {
6577 log("getLine1NumberForDisplay returning "
6578 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6579 }
6580 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006581 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6583 return null;
6584 } finally {
6585 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006586 }
Derek Tan7226c842014-07-02 17:42:23 -07006587 }
6588
6589 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006590 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6591 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006592 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006593 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006594 return null;
6595 }
Derek Tan97ebb422014-09-05 16:55:38 -07006596
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006597 final long identity = Binder.clearCallingIdentity();
6598 try {
6599 String iccId = getIccId(subId);
6600 if (iccId != null) {
6601 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6602 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6603 }
6604 return null;
6605 } finally {
6606 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006607 }
Derek Tan7226c842014-07-02 17:42:23 -07006608 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006609
6610 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006611 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6612 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006613 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6614 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006615 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006616 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006617 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006618 return null;
6619 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006620
Jordan Liub49b04b2019-05-06 14:45:15 -07006621 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6622 // the process, where TelephonyManager was instantiated.
6623 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006624 final long identity = Binder.clearCallingIdentity();
6625 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006626 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006627 final TelephonyManager tele = TelephonyManager.from(context);
6628 final SubscriptionManager sub = SubscriptionManager.from(context);
6629
6630 // Figure out what subscribers are currently active
6631 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006632
Jordan Liub49b04b2019-05-06 14:45:15 -07006633 // Only consider subs which match the current subId
6634 // This logic can be simplified. See b/131189269 for progress.
6635 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006636 activeSubscriberIds.add(tele.getSubscriberId(subId));
6637 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006638
6639 // First pass, find a number override for an active subscriber
6640 String mergeNumber = null;
6641 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6642 for (String key : prefs.keySet()) {
6643 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6644 final String subscriberId = (String) prefs.get(key);
6645 if (activeSubscriberIds.contains(subscriberId)) {
6646 final String iccId = key.substring(
6647 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6648 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6649 mergeNumber = (String) prefs.get(numberKey);
6650 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006651 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006652 + " for active subscriber " + subscriberId);
6653 }
6654 if (!TextUtils.isEmpty(mergeNumber)) {
6655 break;
6656 }
6657 }
6658 }
6659 }
6660
6661 // Shortcut when no active merged subscribers
6662 if (TextUtils.isEmpty(mergeNumber)) {
6663 return null;
6664 }
6665
6666 // Second pass, find all subscribers under that line override
6667 final ArraySet<String> result = new ArraySet<>();
6668 for (String key : prefs.keySet()) {
6669 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6670 final String number = (String) prefs.get(key);
6671 if (mergeNumber.equals(number)) {
6672 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6673 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6674 final String subscriberId = (String) prefs.get(subscriberKey);
6675 if (!TextUtils.isEmpty(subscriberId)) {
6676 result.add(subscriberId);
6677 }
6678 }
6679 }
6680 }
6681
6682 final String[] resultArray = result.toArray(new String[result.size()]);
6683 Arrays.sort(resultArray);
6684 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006685 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006686 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6687 }
6688 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006689 } finally {
6690 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006691 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006692 }
6693
6694 @Override
zoey chen38003472019-12-13 17:16:31 +08006695 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6696 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006697
6698 final long identity = Binder.clearCallingIdentity();
6699 try {
6700 final TelephonyManager telephonyManager = mApp.getSystemService(
6701 TelephonyManager.class);
6702 String subscriberId = telephonyManager.getSubscriberId(subId);
6703 if (subscriberId == null) {
6704 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006705 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006706 + subId);
6707 }
6708 return null;
6709 }
6710
6711 final SubscriptionInfo info = SubscriptionController.getInstance()
6712 .getSubscriptionInfo(subId);
6713 final ParcelUuid groupUuid = info.getGroupUuid();
6714 // If it doesn't belong to any group, return just subscriberId of itself.
6715 if (groupUuid == null) {
6716 return new String[]{subscriberId};
6717 }
6718
6719 // Get all subscriberIds from the group.
6720 final List<String> mergedSubscriberIds = new ArrayList<>();
6721 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006722 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006723 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006724 for (SubscriptionInfo subInfo : groupInfos) {
6725 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6726 if (subscriberId != null) {
6727 mergedSubscriberIds.add(subscriberId);
6728 }
6729 }
6730
6731 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6732 } finally {
6733 Binder.restoreCallingIdentity(identity);
6734
6735 }
6736 }
6737
6738 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006739 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006740 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006741 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006742
6743 final long identity = Binder.clearCallingIdentity();
6744 try {
6745 final Phone phone = getPhone(subId);
6746 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6747 } finally {
6748 Binder.restoreCallingIdentity(identity);
6749 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006750 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006751
6752 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006753 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006754 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6755 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006756 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6757 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758
6759 final long identity = Binder.clearCallingIdentity();
6760 try {
6761 final Phone phone = getPhone(subId);
6762 if (phone == null) {
6763 return false;
6764 }
6765 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6766 cdmaNonRoamingList);
6767 } finally {
6768 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006769 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006770 }
6771
6772 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006773 @Deprecated
6774 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6775 enforceModifyPermission();
6776
6777 int returnValue = 0;
6778 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006779 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006780 if(result.exception == null) {
6781 if (result.result != null) {
6782 byte[] responseData = (byte[])(result.result);
6783 if(responseData.length > oemResp.length) {
6784 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6785 responseData.length + "bytes. Buffer Size is " +
6786 oemResp.length + "bytes.");
6787 }
6788 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6789 returnValue = responseData.length;
6790 }
6791 } else {
6792 CommandException ex = (CommandException) result.exception;
6793 returnValue = ex.getCommandError().ordinal();
6794 if(returnValue > 0) returnValue *= -1;
6795 }
6796 } catch (RuntimeException e) {
6797 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6798 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6799 if(returnValue > 0) returnValue *= -1;
6800 }
6801
6802 return returnValue;
6803 }
6804
6805 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006806 public void setRadioCapability(RadioAccessFamily[] rafs) {
6807 try {
6808 ProxyController.getInstance().setRadioCapability(rafs);
6809 } catch (RuntimeException e) {
6810 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6811 }
6812 }
6813
6814 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006815 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006816 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006817 try {
6818 TelephonyPermissions
6819 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6820 mApp, phone.getSubId(), "getRadioAccessFamily");
6821 } catch (SecurityException e) {
6822 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6823 throw e;
6824 }
chen xub97461a2018-10-26 14:17:57 -07006825 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006826 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006827 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006828 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006829 final long identity = Binder.clearCallingIdentity();
6830 try {
chen xub97461a2018-10-26 14:17:57 -07006831 TelephonyPermissions
6832 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6833 mApp, phone.getSubId(), "getRadioAccessFamily");
6834 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006835 } finally {
6836 Binder.restoreCallingIdentity(identity);
6837 }
chen xub97461a2018-10-26 14:17:57 -07006838 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006839 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006840
6841 @Override
6842 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006843 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006844 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006845
6846 final long identity = Binder.clearCallingIdentity();
6847 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006848 ImsManager.getInstance(defaultPhone.getContext(),
6849 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006850 } finally {
6851 Binder.restoreCallingIdentity(identity);
6852 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006853 }
6854
6855 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006856 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006857 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006858 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6859 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006860 return false;
6861 }
Svet Ganovb320e182015-04-16 12:30:10 -07006862
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006863 final long identity = Binder.clearCallingIdentity();
6864 try {
6865 // Check the user preference and the system-level IMS setting. Even if the user has
6866 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6867 // In the long run, we may instead need to check if there exists a connection service
6868 // which can support video calling.
6869 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006870 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006871 return imsManager.isVtEnabledByPlatform()
6872 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6873 && imsManager.isVtEnabledByUser();
6874 } finally {
6875 Binder.restoreCallingIdentity(identity);
6876 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006877 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006878
Andrew Leea1239f22015-03-02 17:44:07 -08006879 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006880 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6881 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006882 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006883 mApp, subId, callingPackage, callingFeatureId,
6884 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006885 return false;
6886 }
6887
6888 final long identity = Binder.clearCallingIdentity();
6889 try {
6890 CarrierConfigManager configManager =
6891 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006892 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006893 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6894 } finally {
6895 Binder.restoreCallingIdentity(identity);
6896 }
Andrew Leea1239f22015-03-02 17:44:07 -08006897 }
6898
6899 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006900 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006901 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006902 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006903 return false;
6904 }
6905
6906 final long identity = Binder.clearCallingIdentity();
6907 try {
6908 CarrierConfigManager configManager =
6909 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006910 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006911 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6912 } finally {
6913 Binder.restoreCallingIdentity(identity);
6914 }
Andrew Leea1239f22015-03-02 17:44:07 -08006915 }
6916
Andrew Lee9431b832015-03-09 18:46:45 -07006917 @Override
6918 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006919 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006920 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006921 }
6922
6923 @Override
6924 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006925 final long identity = Binder.clearCallingIdentity();
6926 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006927 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006928 } finally {
6929 Binder.restoreCallingIdentity(identity);
6930 }
Andrew Lee9431b832015-03-09 18:46:45 -07006931 }
6932
Hall Liuf6668912018-10-31 17:05:23 -07006933 /**
6934 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6935 * support for the feature and device firmware support.
6936 *
6937 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6938 */
6939 @Override
6940 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006941 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006942 final Phone phone = getPhone(subscriptionId);
6943 if (phone == null) {
6944 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6945 return false;
6946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006947 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006948 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006949 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6950 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006951 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006952 return isCarrierSupported && isDeviceSupported;
6953 } finally {
6954 Binder.restoreCallingIdentity(identity);
6955 }
Hall Liu98187582018-01-22 19:15:32 -08006956 }
6957
Hall Liuf6668912018-10-31 17:05:23 -07006958 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006959 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6960 * RTT setting, will return true if the device and carrier both support RTT.
6961 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006962 */
6963 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006964 final long identity = Binder.clearCallingIdentity();
6965 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006966 boolean isRttSupported = isRttSupported(subscriptionId);
6967 boolean isUserRttSettingOn = Settings.Secure.getInt(
6968 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6969 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6970 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6971 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006972 } finally {
6973 Binder.restoreCallingIdentity(identity);
6974 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006975 }
6976
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006977 @Deprecated
6978 @Override
6979 public String getDeviceId(String callingPackage) {
6980 return getDeviceIdWithFeature(callingPackage, null);
6981 }
6982
Sanket Padawe7310cc72015-01-14 09:53:20 -08006983 /**
6984 * Returns the unique device ID of phone, for example, the IMEI for
6985 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6986 *
6987 * <p>Requires Permission:
6988 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6989 */
6990 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006991 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006992 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006993 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006994 return null;
6995 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006996 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006997 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006998 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006999 return null;
7000 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007001
7002 final long identity = Binder.clearCallingIdentity();
7003 try {
7004 return phone.getDeviceId();
7005 } finally {
7006 Binder.restoreCallingIdentity(identity);
7007 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007008 }
7009
Ping Sunc67b7c22016-03-02 19:16:45 +08007010 /**
7011 * {@hide}
7012 * Returns the IMS Registration Status on a particular subid
7013 *
7014 * @param subId
7015 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007016 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007017 Phone phone = getPhone(subId);
7018 if (phone != null) {
7019 return phone.isImsRegistered();
7020 } else {
7021 return false;
7022 }
7023 }
7024
Santos Cordon7a1885b2015-02-03 11:15:19 -08007025 @Override
7026 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007027 final long identity = Binder.clearCallingIdentity();
7028 try {
7029 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7030 } finally {
7031 Binder.restoreCallingIdentity(identity);
7032 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007033 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007034
Tyler Gunnf70ed162019-04-03 15:28:53 -07007035 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007036 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007037 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007038 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007039 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007040 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7041 }
7042 final long identity = Binder.clearCallingIdentity();
7043 try {
7044 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7045 } finally {
7046 Binder.restoreCallingIdentity(identity);
7047 }
7048 }
7049
7050 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007051 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007052 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7053 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007054 final long identity = Binder.clearCallingIdentity();
7055 try {
7056 Phone phone = getPhone(subscriptionId);
7057 if (phone == null) {
7058 return null;
7059 }
7060 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7061 } finally {
7062 Binder.restoreCallingIdentity(identity);
7063 }
7064 }
7065
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007066 /**
7067 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007068 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007069 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007070 final long identity = Binder.clearCallingIdentity();
7071 try {
7072 Phone phone = getPhone(subId);
7073 if (phone != null) {
7074 return phone.isWifiCallingEnabled();
7075 } else {
7076 return false;
7077 }
7078 } finally {
7079 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007080 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007081 }
7082
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007083 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007084 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007085 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007086 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007087 final long identity = Binder.clearCallingIdentity();
7088 try {
7089 Phone phone = getPhone(subId);
7090 if (phone != null) {
7091 return phone.isVideoEnabled();
7092 } else {
7093 return false;
7094 }
7095 } finally {
7096 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007097 }
7098 }
7099
7100 /**
7101 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7102 * defined in {@link ImsRegistrationImplBase}.
7103 */
7104 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007105 final long identity = Binder.clearCallingIdentity();
7106 try {
7107 Phone phone = getPhone(subId);
7108 if (phone != null) {
7109 return phone.getImsRegistrationTech();
7110 } else {
7111 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7112 }
7113 } finally {
7114 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007115 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007116 }
7117
Stuart Scott8eef64f2015-04-08 15:13:54 -07007118 @Override
7119 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007120 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007121 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7122 return;
7123 }
7124
Svet Ganovcc087f82015-05-12 20:35:54 -07007125 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007126
Svet Ganovcc087f82015-05-12 20:35:54 -07007127 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007128 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7129 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007130 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007131 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007132 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007133 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007134 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7135 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007136 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007137 // There has been issues when Sms raw table somehow stores orphan
7138 // fragments. They lead to garbled message when new fragments come
7139 // in and combined with those stale ones. In case this happens again,
7140 // user can reset all network settings which will clean up this table.
7141 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007142 // Clean up IMS settings as well here.
7143 int slotId = getSlotIndex(subId);
7144 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7145 ImsManager.getInstance(mApp, slotId).factoryReset();
7146 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007147
7148 // Erase modem config if erase modem on network setting is enabled.
7149 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7150 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7151 if (configValue != null && Boolean.parseBoolean(configValue)) {
7152 sendEraseModemConfig(getDefaultPhone());
7153 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007154 } finally {
7155 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007156 }
7157 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007158
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007159 private void cleanUpSmsRawTable(Context context) {
7160 ContentResolver resolver = context.getContentResolver();
7161 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7162 resolver.delete(uri, null, null);
7163 }
7164
Narayan Kamath1c496c22015-04-16 14:40:19 +01007165 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007166 public String getSimLocaleForSubscriber(int subId) {
7167 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7168 final Phone phone = getPhone(subId);
7169 if (phone == null) {
7170 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007171 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007172 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007173 final long identity = Binder.clearCallingIdentity();
7174 try {
chen xu5d3637b2019-01-21 23:31:38 -08007175 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007176 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007177 if (info == null) {
7178 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7179 return null;
7180 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007181 // Try and fetch the locale from the carrier properties or from the SIM language
7182 // preferences (EF-PL and EF-LI)...
7183 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007184 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007185 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7186 if (localeFromDefaultSim != null) {
7187 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7188 if (DBG) log("Using locale from subId: " + subId + " locale: "
7189 + localeFromDefaultSim);
7190 return localeFromDefaultSim.toLanguageTag();
7191 } else {
7192 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007193 }
7194 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196 // The SIM language preferences only store a language (e.g. fr = French), not an
7197 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7198 // the SIM and carrier preferences does not include a country we add the country
7199 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007200 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007201 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007202 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007203 return mccLocale.toLanguageTag();
7204 }
7205
7206 if (DBG) log("No locale found - returning null");
7207 return null;
7208 } finally {
7209 Binder.restoreCallingIdentity(identity);
7210 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007211 }
7212
7213 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007214 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007215 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007216 }
7217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007218 /**
7219 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7220 */
7221 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007222 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007223 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007224 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007225
Chenjie Yu1ba97252018-01-11 18:16:20 -08007226 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007227 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007228
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007229 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007230 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7231 * representing the state of the modem.
7232 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007233 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7234 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007235 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007236 */
7237 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007238 public void requestModemActivityInfo(ResultReceiver result) {
7239 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007240 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007241
7242 final long identity = Binder.clearCallingIdentity();
7243 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007244 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007245 } finally {
7246 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007247 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007248 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007249
Siddharth Rayb8114062018-06-17 15:02:38 -07007250 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7251 // less than total activity duration.
7252 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7253 if (info == null) {
7254 return false;
7255 }
7256 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007257 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7258 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7259
Siddharth Rayb8114062018-06-17 15:02:38 -07007260 return (info.isValid()
7261 && (info.getSleepTimeMillis() <= activityDurationMs)
7262 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007263 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007264 && (totalTxTimeMs <= activityDurationMs));
7265 }
7266
Jack Yu85bd38a2015-11-09 11:34:32 -08007267 /**
7268 * {@hide}
7269 * Returns the service state information on specified subscription.
7270 */
7271 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007272 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7273 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007274 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007275 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007276 return null;
7277 }
7278
Hall Liuf19c44f2018-11-27 14:38:17 -08007279 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7280 LocationAccessPolicy.checkLocationPermission(mApp,
7281 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7282 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007283 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007284 .setCallingPid(Binder.getCallingPid())
7285 .setCallingUid(Binder.getCallingUid())
7286 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007287 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007288 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007289 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7290 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007291 .build());
7292
7293 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7294 LocationAccessPolicy.checkLocationPermission(mApp,
7295 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7296 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007297 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007298 .setCallingPid(Binder.getCallingPid())
7299 .setCallingUid(Binder.getCallingUid())
7300 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007301 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007302 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007303 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7304 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007305 .build());
7306 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7307 boolean hasFinePermission =
7308 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7309 boolean hasCoarsePermission =
7310 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7311
Jack Yu479f40e2020-10-27 21:29:25 -07007312 final Phone phone = getPhone(subId);
7313 if (phone == null) {
7314 return null;
7315 }
7316
Jordan Liu0f2bc442020-11-18 16:47:37 -08007317 final long identity = Binder.clearCallingIdentity();
7318
Jack Yu479f40e2020-10-27 21:29:25 -07007319 boolean isCallingPackageDataService = phone.getDataServicePackages()
7320 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007321 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007322 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7323 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7324 Rlog.d(LOG_TAG,
7325 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7326 return null;
7327 }
7328
Hall Liuf19c44f2018-11-27 14:38:17 -08007329 ServiceState ss = phone.getServiceState();
7330
7331 // Scrub out the location info in ServiceState depending on what level of access
7332 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007333 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007334 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7335 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007336 } finally {
7337 Binder.restoreCallingIdentity(identity);
7338 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007339 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007340
7341 /**
7342 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7343 *
7344 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7345 * voicemail ringtone.
7346 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7347 * PhoneAccount.
7348 */
7349 @Override
7350 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007351 final long identity = Binder.clearCallingIdentity();
7352 try {
7353 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7354 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007355 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007356 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007357
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007358 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7359 } finally {
7360 Binder.restoreCallingIdentity(identity);
7361 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007362 }
7363
7364 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007365 * Sets the per-account voicemail ringtone.
7366 *
7367 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7368 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7369 *
7370 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7371 * voicemail ringtone.
7372 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7373 * PhoneAccount.
7374 */
7375 @Override
7376 public void setVoicemailRingtoneUri(String callingPackage,
7377 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007378 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007379 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007380 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7381 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7383 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7384 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007385 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007386
7387 final long identity = Binder.clearCallingIdentity();
7388 try {
7389 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7390 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007391 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007392 }
7393 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7394 } finally {
7395 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007396 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007397 }
7398
7399 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007400 * Returns whether vibration is set for voicemail notification in Phone settings.
7401 *
7402 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7403 * voicemail vibration setting.
7404 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7405 */
7406 @Override
7407 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007408 final long identity = Binder.clearCallingIdentity();
7409 try {
7410 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7411 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007412 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007413 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007414
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007415 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7416 } finally {
7417 Binder.restoreCallingIdentity(identity);
7418 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007419 }
7420
Youhan Wange64578a2016-05-02 15:32:42 -07007421 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007422 * Sets the per-account voicemail vibration.
7423 *
7424 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7425 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7426 *
7427 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7428 * voicemail vibration setting.
7429 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7430 * specific PhoneAccount.
7431 */
7432 @Override
7433 public void setVoicemailVibrationEnabled(String callingPackage,
7434 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007435 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007436 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007437 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7438 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007439 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7440 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7441 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007442 }
7443
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007444 final long identity = Binder.clearCallingIdentity();
7445 try {
7446 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7447 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007448 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007449 }
7450 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7451 } finally {
7452 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007453 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007454 }
7455
7456 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007457 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7458 *
7459 * @throws SecurityException if the caller does not have the required permission
7460 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007461 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007462 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007463 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007464 }
7465
7466 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007467 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7468 * permission.
7469 *
7470 * @throws SecurityException if the caller does not have the required permission
7471 */
7472 private void enforceSendSmsPermission() {
7473 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7474 }
7475
7476 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007477 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007478 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007479 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007480 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007481 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 final long identity = Binder.clearCallingIdentity();
7483 try {
7484 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007485 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 if (componentName == null) {
7487 throw new SecurityException(
7488 "Caller not current active visual voicemail package[null]");
7489 }
7490 String vvmPackage = componentName.getPackageName();
7491 if (!callingPackage.equals(vvmPackage)) {
7492 throw new SecurityException("Caller not current active visual voicemail package["
7493 + vvmPackage + "]");
7494 }
7495 } finally {
7496 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007497 }
7498 }
7499
7500 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007501 * Return the application ID for the app type.
7502 *
7503 * @param subId the subscription ID that this request applies to.
7504 * @param appType the uicc app type.
7505 * @return Application ID for specificied app type, or null if no uicc.
7506 */
7507 @Override
7508 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007509 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007510 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511
7512 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007513 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007514 if (phone == null) {
7515 return null;
7516 }
7517 String aid = null;
7518 try {
7519 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7520 .getApplicationByType(appType).getAid();
7521 } catch (Exception e) {
7522 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7523 }
7524 return aid;
7525 } finally {
7526 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007527 }
Youhan Wange64578a2016-05-02 15:32:42 -07007528 }
7529
Youhan Wang4001d252016-05-11 10:29:41 -07007530 /**
7531 * Return the Electronic Serial Number.
7532 *
7533 * @param subId the subscription ID that this request applies to.
7534 * @return ESN or null if error.
7535 */
7536 @Override
7537 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007538 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007539 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007540
7541 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007542 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543 if (phone == null) {
7544 return null;
7545 }
7546 String esn = null;
7547 try {
7548 esn = phone.getEsn();
7549 } catch (Exception e) {
7550 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7551 }
7552 return esn;
7553 } finally {
7554 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007555 }
Youhan Wang4001d252016-05-11 10:29:41 -07007556 }
7557
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007558 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007559 * Return the Preferred Roaming List Version.
7560 *
7561 * @param subId the subscription ID that this request applies to.
7562 * @return PRLVersion or null if error.
7563 */
7564 @Override
7565 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007566 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007567 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007568
7569 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007570 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007571 if (phone == null) {
7572 return null;
7573 }
7574 String cdmaPrlVersion = null;
7575 try {
7576 cdmaPrlVersion = phone.getCdmaPrlVersion();
7577 } catch (Exception e) {
7578 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7579 }
7580 return cdmaPrlVersion;
7581 } finally {
7582 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007583 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007584 }
7585
7586 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007587 * Get snapshot of Telephony histograms
7588 * @return List of Telephony histograms
7589 * @hide
7590 */
7591 @Override
7592 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7594 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007595
7596 final long identity = Binder.clearCallingIdentity();
7597 try {
7598 return RIL.getTelephonyRILTimingHistograms();
7599 } finally {
7600 Binder.restoreCallingIdentity(identity);
7601 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007602 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007603
7604 /**
7605 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007606 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7607 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007608 * Require system privileges. In the future we may add this to carrier APIs.
7609 *
Michele Berionne482f8202018-11-27 18:57:59 -08007610 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007611 */
7612 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007613 @TelephonyManager.SetCarrierRestrictionResult
7614 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007615 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007616 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007617
Michele Berionne482f8202018-11-27 18:57:59 -08007618 if (carrierRestrictionRules == null) {
7619 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007620 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007621
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007622 final long identity = Binder.clearCallingIdentity();
7623 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007624 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007625 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007626 } finally {
7627 Binder.restoreCallingIdentity(identity);
7628 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007629 }
7630
7631 /**
7632 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007633 * Get the allowed carrier list and the excluded carrier list, including the priority between
7634 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007635 * Require system privileges. In the future we may add this to carrier APIs.
7636 *
Michele Berionne482f8202018-11-27 18:57:59 -08007637 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007638 */
7639 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007640 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007641 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007642 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007643
7644 final long identity = Binder.clearCallingIdentity();
7645 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007646 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7647 if (response instanceof CarrierRestrictionRules) {
7648 return (CarrierRestrictionRules) response;
7649 }
7650 // Response is an Exception of some kind,
7651 // which is signalled to the user as a NULL retval
7652 return null;
7653 } catch (Exception e) {
7654 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7655 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007656 } finally {
7657 Binder.restoreCallingIdentity(identity);
7658 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007659 }
7660
fionaxu59545b42016-05-25 15:53:37 -07007661 /**
fionaxu59545b42016-05-25 15:53:37 -07007662 * Action set from carrier signalling broadcast receivers to enable/disable radio
7663 * @param subId the subscription ID that this action applies to.
7664 * @param enabled control enable or disable radio.
7665 * {@hide}
7666 */
7667 @Override
7668 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7669 enforceModifyPermission();
7670 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007671
7672 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007673 if (phone == null) {
7674 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7675 return;
7676 }
7677 try {
7678 phone.carrierActionSetRadioEnabled(enabled);
7679 } catch (Exception e) {
7680 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007681 } finally {
7682 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007683 }
7684 }
7685
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007686 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007687 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7688 * network status based on which carrier apps could apply actions accordingly,
7689 * enable/disable default url handler for example.
7690 *
7691 * @param subId the subscription ID that this action applies to.
7692 * @param report control start/stop reporting the default network status.
7693 * {@hide}
7694 */
7695 @Override
7696 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7697 enforceModifyPermission();
7698 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007699
7700 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007701 if (phone == null) {
7702 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7703 return;
7704 }
7705 try {
7706 phone.carrierActionReportDefaultNetworkStatus(report);
7707 } catch (Exception e) {
7708 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007709 } finally {
7710 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007711 }
7712 }
7713
7714 /**
fionaxud9622282017-07-17 17:51:30 -07007715 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7716 * @param subId the subscription ID that this action applies to.
7717 * {@hide}
7718 */
7719 @Override
7720 public void carrierActionResetAll(int subId) {
7721 enforceModifyPermission();
7722 final Phone phone = getPhone(subId);
7723 if (phone == null) {
7724 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7725 return;
7726 }
7727 try {
7728 phone.carrierActionResetAll();
7729 } catch (Exception e) {
7730 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7731 }
7732 }
7733
7734 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007735 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7736 * bug report is being generated.
7737 */
7738 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007739 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007740 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7741 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007742 writer.println("Permission Denial: can't dump Phone from pid="
7743 + Binder.getCallingPid()
7744 + ", uid=" + Binder.getCallingUid()
7745 + "without permission "
7746 + android.Manifest.permission.DUMP);
7747 return;
7748 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007749 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007750 }
Jack Yueb89b242016-06-22 13:27:47 -07007751
Brad Ebingerdac2f002018-04-03 15:17:52 -07007752 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007753 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7754 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7755 @NonNull String[] args) {
7756 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7757 this, in.getFileDescriptor(), out.getFileDescriptor(),
7758 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007759 }
7760
Jack Yueb89b242016-06-22 13:27:47 -07007761 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007762 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007763 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007764 * @param reason the reason the data enable change is taking place
7765 * @param enabled True if enabling the data, otherwise disabling.
7766 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007767 */
7768 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007769 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007770 boolean enabled) {
7771 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7772 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7773 try {
7774 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007775 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007776 } catch (SecurityException se) {
7777 enforceModifyPermission();
7778 }
7779 } else {
7780 enforceModifyPermission();
7781 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007782
7783 final long identity = Binder.clearCallingIdentity();
7784 try {
7785 Phone phone = getPhone(subId);
7786 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007787 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7788 phone.carrierActionSetMeteredApnsEnabled(enabled);
7789 } else {
7790 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7791 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007792 }
7793 } finally {
7794 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007795 }
7796 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007797
7798 /**
7799 * Get Client request stats
7800 * @return List of Client Request Stats
7801 * @hide
7802 */
7803 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007804 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7805 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007806 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007807 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007808 return null;
7809 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007810 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007811
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007812 final long identity = Binder.clearCallingIdentity();
7813 try {
7814 if (phone != null) {
7815 return phone.getClientRequestStats();
7816 }
7817
7818 return null;
7819 } finally {
7820 Binder.restoreCallingIdentity(identity);
7821 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007822 }
7823
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007824 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007825 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007826 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007827 }
Jack Yueb4124c2017-02-16 15:32:43 -08007828
7829 /**
Grace Chen70990072017-03-24 17:21:30 -07007830 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007831 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007832 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007833 * @param state State of SIM (power down, power up, pass through)
7834 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7835 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7836 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007837 *
7838 **/
7839 @Override
Grace Chen70990072017-03-24 17:21:30 -07007840 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007841 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007842 Phone phone = PhoneFactory.getPhone(slotIndex);
7843
vagdeviaf9a5b92018-08-15 16:01:53 -07007844 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7845
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007846 final long identity = Binder.clearCallingIdentity();
7847 try {
7848 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007849 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007850 }
7851 } finally {
7852 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007853 }
7854 }
Shuo Qiandd210312017-04-12 22:11:33 +00007855
Tyler Gunn65d45c22017-06-05 11:22:26 -07007856 private boolean isUssdApiAllowed(int subId) {
7857 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007858 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007859 if (configManager == null) {
7860 return false;
7861 }
7862 PersistableBundle pb = configManager.getConfigForSubId(subId);
7863 if (pb == null) {
7864 return false;
7865 }
7866 return pb.getBoolean(
7867 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7868 }
7869
Shuo Qiandd210312017-04-12 22:11:33 +00007870 /**
7871 * Check if phone is in emergency callback mode
7872 * @return true if phone is in emergency callback mode
7873 * @param subId sub id
7874 */
goneil9c5f4872017-12-05 14:07:56 -08007875 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007876 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007877 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007878 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007879
7880 final long identity = Binder.clearCallingIdentity();
7881 try {
7882 if (phone != null) {
7883 return phone.isInEcm();
7884 } else {
7885 return false;
7886 }
7887 } finally {
7888 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007889 }
7890 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007891
7892 /**
7893 * Get the current signal strength information for the given subscription.
7894 * Because this information is not updated when the device is in a low power state
7895 * it should not be relied-upon to be current.
7896 * @param subId Subscription index
7897 * @return the most recent cached signal strength info from the modem
7898 */
7899 @Override
7900 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007901 final long identity = Binder.clearCallingIdentity();
7902 try {
7903 Phone p = getPhone(subId);
7904 if (p == null) {
7905 return null;
7906 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007907
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007908 return p.getSignalStrength();
7909 } finally {
7910 Binder.restoreCallingIdentity(identity);
7911 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007912 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007913
Pengquan Meng77b7f132018-08-22 14:49:57 -07007914 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007915 * Get the current modem radio state for the given slot.
7916 * @param slotIndex slot index.
7917 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007918 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007919 * @return the current radio power state from the modem
7920 */
7921 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007922 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007923 Phone phone = PhoneFactory.getPhone(slotIndex);
7924 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007925 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7926 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007927 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7928 }
7929
7930 final long identity = Binder.clearCallingIdentity();
7931 try {
7932 return phone.getRadioPowerState();
7933 } finally {
7934 Binder.restoreCallingIdentity(identity);
7935 }
7936 }
7937 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7938 }
7939
7940 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007941 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7942 *
7943 * <p>Requires one of the following permissions:
7944 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7945 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7946 * privileges.
7947 *
7948 * @param subId subscription id
7949 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7950 * {@code false}.
7951 */
7952 @Override
7953 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07007954 try {
7955 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7956 null);
7957 } catch (Exception e) {
7958 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7959 mApp, subId, "isDataRoamingEnabled");
7960 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007961
Pengquan Menga1bb6272018-09-06 09:59:22 -07007962 boolean isEnabled = false;
7963 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007964 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007965 Phone phone = getPhone(subId);
7966 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007967 } finally {
7968 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007969 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007970 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007971 }
7972
7973
7974 /**
7975 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7976 *
7977 * <p> Requires permission:
7978 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7979 * privileges.
7980 *
7981 * @param subId subscription id
7982 * @param isEnabled {@code true} means enable, {@code false} means disable.
7983 */
7984 @Override
7985 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7987 mApp, subId, "setDataRoamingEnabled");
7988
Pengquan Menga1bb6272018-09-06 09:59:22 -07007989 final long identity = Binder.clearCallingIdentity();
7990 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007991 Phone phone = getPhone(subId);
7992 if (phone != null) {
7993 phone.setDataRoamingEnabled(isEnabled);
7994 }
7995 } finally {
7996 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007997 }
7998 }
7999
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008000 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008001 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008002 TelephonyPermissions
8003 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008004 mApp, subId, "isManualNetworkSelectionAllowed");
8005
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008006 boolean isAllowed = true;
8007 final long identity = Binder.clearCallingIdentity();
8008 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008009 Phone phone = getPhone(subId);
8010 if (phone != null) {
8011 isAllowed = phone.isCspPlmnEnabled();
8012 }
8013 } finally {
8014 Binder.restoreCallingIdentity(identity);
8015 }
8016 return isAllowed;
8017 }
8018
8019 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008020 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008021 // Verify that tha callingPackage belongs to the calling UID
8022 mApp.getSystemService(AppOpsManager.class)
8023 .checkPackage(Binder.getCallingUid(), callingPackage);
8024
Jordan Liu1e142fc2019-04-22 15:10:43 -07008025 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008026 try {
8027 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008028 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008029 } catch (SecurityException e) {
8030 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8031 // has carrier privileges on an active UICC
8032 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8033 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008034 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008035 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008036 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008037
8038 final long identity = Binder.clearCallingIdentity();
8039 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008040 UiccController uiccController = UiccController.getInstance();
8041 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008042 if (hasReadPermission) {
8043 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008044 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008045
8046 // Remove private info if the caller doesn't have access
8047 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8048 for (UiccCardInfo cardInfo : cardInfos) {
8049 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8050 // is available
8051 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8052 if (card == null || card.getUiccProfile() == null) {
8053 // assume no access if the card or profile is unavailable
8054 filteredInfos.add(cardInfo.getUnprivileged());
8055 continue;
8056 }
8057 UiccProfile profile = card.getUiccProfile();
8058 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8059 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8060 filteredInfos.add(cardInfo);
8061 } else {
8062 filteredInfos.add(cardInfo.getUnprivileged());
8063 }
8064 }
8065 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008066 } finally {
8067 Binder.restoreCallingIdentity(identity);
8068 }
8069 }
8070
8071 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008072 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008073 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008074
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008075 final long identity = Binder.clearCallingIdentity();
8076 try {
8077 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8078 if (slots == null) {
8079 Rlog.i(LOG_TAG, "slots is null.");
8080 return null;
8081 }
8082
8083 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8084 for (int i = 0; i < slots.length; i++) {
8085 UiccSlot slot = slots[i];
8086 if (slot == null) {
8087 continue;
8088 }
8089
Jordan Liu7be7e652019-05-06 18:55:02 +00008090 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008091 UiccCard card = slot.getUiccCard();
8092 if (card != null) {
8093 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008094 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008095 cardId = slot.getEid();
8096 if (TextUtils.isEmpty(cardId)) {
8097 cardId = slot.getIccId();
8098 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008099 }
8100
Jordan Liu857451f2019-05-09 16:35:35 -07008101 if (cardId != null) {
8102 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8103 // if cardId is an EID, it's all digits so this is fine
8104 cardId = IccUtils.stripTrailingFs(cardId);
8105 }
8106
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008107 int cardState = 0;
8108 switch (slot.getCardState()) {
8109 case CARDSTATE_ABSENT:
8110 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8111 break;
8112 case CARDSTATE_PRESENT:
8113 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8114 break;
8115 case CARDSTATE_ERROR:
8116 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8117 break;
8118 case CARDSTATE_RESTRICTED:
8119 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8120 break;
8121 default:
8122 break;
8123
8124 }
8125
8126 infos[i] = new UiccSlotInfo(
8127 slot.isActive(),
8128 slot.isEuicc(),
8129 cardId,
8130 cardState,
8131 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008132 slot.isExtendedApduSupported(),
8133 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008134 }
8135 return infos;
8136 } finally {
8137 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008138 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008139 }
8140
8141 @Override
8142 public boolean switchSlots(int[] physicalSlots) {
8143 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008144
8145 final long identity = Binder.clearCallingIdentity();
8146 try {
8147 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8148 } finally {
8149 Binder.restoreCallingIdentity(identity);
8150 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008151 }
Jack Yu4c988042018-02-27 15:30:01 -08008152
8153 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008154 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008155 final long identity = Binder.clearCallingIdentity();
8156 try {
8157 return UiccController.getInstance().getCardIdForDefaultEuicc();
8158 } finally {
8159 Binder.restoreCallingIdentity(identity);
8160 }
8161 }
8162
Pengquan Meng85728fb2018-03-12 16:31:21 -07008163 /**
goneil47ffb6e2018-04-06 15:40:58 -07008164 * A test API to reload the UICC profile.
8165 *
8166 * <p>Requires that the calling app has permission
8167 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8168 * @hide
8169 */
8170 @Override
8171 public void refreshUiccProfile(int subId) {
8172 enforceModifyPermission();
8173
8174 final long identity = Binder.clearCallingIdentity();
8175 try {
8176 Phone phone = getPhone(subId);
8177 if (phone == null) {
8178 return;
8179 }
8180 UiccCard uiccCard = phone.getUiccCard();
8181 if (uiccCard == null) {
8182 return;
8183 }
8184 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8185 if (uiccProfile == null) {
8186 return;
8187 }
8188 uiccProfile.refresh();
8189 } finally {
8190 Binder.restoreCallingIdentity(identity);
8191 }
8192 }
8193
8194 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008195 * Returns false if the mobile data is disabled by default, otherwise return true.
8196 */
8197 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008198 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008199 }
8200
8201 /**
8202 * Returns true if the data roaming is enabled by default, i.e the system property
8203 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8204 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8205 */
8206 private boolean getDefaultDataRoamingEnabled(int subId) {
8207 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008208 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008209 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008210 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8211 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8212 return isDataRoamingEnabled;
8213 }
8214
8215 /**
8216 * Returns the default network type for the given {@code subId}, if the default network type is
8217 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8218 */
8219 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008220 List<Integer> list = TelephonyProperties.default_network();
8221 int phoneId = mSubscriptionController.getPhoneId(subId);
8222 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8223 return list.get(phoneId);
8224 }
8225 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008226 }
fionaxua13278b2018-03-21 00:08:13 -07008227
8228 @Override
8229 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008230 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008231 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008232
8233 final long identity = Binder.clearCallingIdentity();
8234 try {
8235 final Phone phone = getPhone(subId);
8236 if (phone == null) {
8237 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8238 return;
8239 }
chen xueaba88a2019-03-15 13:15:10 -07008240 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8241 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008242 if (carrierPrivilegeRules == null) {
8243 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8244 } else {
8245 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8246 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008247 } finally {
8248 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008249 }
fionaxua13278b2018-03-21 00:08:13 -07008250 }
8251
8252 @Override
8253 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008254 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008255
8256 final long identity = Binder.clearCallingIdentity();
8257 try {
8258 final Phone phone = getPhone(subId);
8259 if (phone == null) {
8260 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8261 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8262 }
8263 return phone.getCarrierIdListVersion();
8264 } finally {
8265 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008266 }
fionaxua13278b2018-03-21 00:08:13 -07008267 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008268
8269 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008270 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8271 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008272 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008273 mApp, subId, callingPackage, callingFeatureId,
8274 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008275 return -1;
8276 }
8277
8278 final long identity = Binder.clearCallingIdentity();
8279 try {
8280 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8281 } finally {
8282 Binder.restoreCallingIdentity(identity);
8283 }
8284 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008285
8286 @Override
8287 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008288 TelephonyPermissions
8289 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008290 mApp, subId, "getCdmaRoamingMode");
8291
8292 final long identity = Binder.clearCallingIdentity();
8293 try {
8294 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8295 } finally {
8296 Binder.restoreCallingIdentity(identity);
8297 }
8298 }
8299
8300 @Override
8301 public boolean setCdmaRoamingMode(int subId, int mode) {
8302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8303 mApp, subId, "setCdmaRoamingMode");
8304
8305 final long identity = Binder.clearCallingIdentity();
8306 try {
8307 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8308 } finally {
8309 Binder.restoreCallingIdentity(identity);
8310 }
8311 }
8312
8313 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008314 public int getCdmaSubscriptionMode(int subId) {
8315 TelephonyPermissions
8316 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8317 mApp, subId, "getCdmaSubscriptionMode");
8318
8319 final long identity = Binder.clearCallingIdentity();
8320 try {
8321 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8322 } finally {
8323 Binder.restoreCallingIdentity(identity);
8324 }
8325 }
8326
8327 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008328 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8330 mApp, subId, "setCdmaSubscriptionMode");
8331
8332 final long identity = Binder.clearCallingIdentity();
8333 try {
8334 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8335 } finally {
8336 Binder.restoreCallingIdentity(identity);
8337 }
8338 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008339
sqianc5eccab2018-10-19 18:46:41 -07008340 @Override
sqian8c685422019-02-22 15:55:18 -08008341 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008342 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008344 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8345 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008346 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8347 }
8348 final long identity = Binder.clearCallingIdentity();
8349 try {
sqian854d44b2018-12-12 16:48:18 -08008350 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8351 for (Phone phone: PhoneFactory.getPhones()) {
8352 if (phone.getEmergencyNumberTracker() != null
8353 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8354 emergencyNumberListInternal.put(
8355 phone.getSubId(),
8356 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8357 }
sqian11b7a0e2018-12-05 18:48:28 -08008358 }
sqian854d44b2018-12-12 16:48:18 -08008359 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008360 } finally {
8361 Binder.restoreCallingIdentity(identity);
8362 }
sqianc5eccab2018-10-19 18:46:41 -07008363 }
8364
8365 @Override
sqian8c685422019-02-22 15:55:18 -08008366 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008367 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008368 if (!exactMatch) {
8369 TelephonyPermissions
8370 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008371 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008372 }
8373 final long identity = Binder.clearCallingIdentity();
8374 try {
sqian854d44b2018-12-12 16:48:18 -08008375 for (Phone phone: PhoneFactory.getPhones()) {
8376 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008377 && phone.getEmergencyNumberTracker()
8378 .isEmergencyNumber(number, exactMatch)) {
8379 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008380 }
sqian11b7a0e2018-12-05 18:48:28 -08008381 }
8382 return false;
8383 } finally {
8384 Binder.restoreCallingIdentity(identity);
8385 }
8386 }
8387
sqianf4ca7ed2019-01-15 18:32:07 -08008388 /**
8389 * Update emergency number list for test mode.
8390 */
8391 @Override
8392 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8393 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8394 "updateEmergencyNumberListTestMode");
8395
8396 final long identity = Binder.clearCallingIdentity();
8397 try {
8398 for (Phone phone: PhoneFactory.getPhones()) {
8399 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8400 if (tracker != null) {
8401 tracker.executeEmergencyNumberTestModeCommand(action, num);
8402 }
8403 }
8404 } finally {
8405 Binder.restoreCallingIdentity(identity);
8406 }
8407 }
8408
8409 /**
8410 * Get the full emergency number list for test mode.
8411 */
8412 @Override
8413 public List<String> getEmergencyNumberListTestMode() {
8414 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8415 "getEmergencyNumberListTestMode");
8416
8417 final long identity = Binder.clearCallingIdentity();
8418 try {
8419 Set<String> emergencyNumbers = new HashSet<>();
8420 for (Phone phone: PhoneFactory.getPhones()) {
8421 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8422 if (tracker != null) {
8423 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8424 emergencyNumbers.add(num.getNumber());
8425 }
8426 }
8427 }
8428 return new ArrayList<>(emergencyNumbers);
8429 } finally {
8430 Binder.restoreCallingIdentity(identity);
8431 }
8432 }
8433
chen xud6b45bd2018-10-30 22:27:10 -07008434 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008435 public int getEmergencyNumberDbVersion(int subId) {
8436 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8437
8438 final long identity = Binder.clearCallingIdentity();
8439 try {
8440 final Phone phone = getPhone(subId);
8441 if (phone == null) {
8442 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8443 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8444 }
8445 return phone.getEmergencyNumberDbVersion();
8446 } finally {
8447 Binder.restoreCallingIdentity(identity);
8448 }
8449 }
8450
8451 @Override
8452 public void notifyOtaEmergencyNumberDbInstalled() {
8453 enforceModifyPermission();
8454
8455 final long identity = Binder.clearCallingIdentity();
8456 try {
8457 for (Phone phone: PhoneFactory.getPhones()) {
8458 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8459 if (tracker != null) {
8460 tracker.updateOtaEmergencyNumberDatabase();
8461 }
8462 }
8463 } finally {
8464 Binder.restoreCallingIdentity(identity);
8465 }
8466 }
8467
8468 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008469 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008470 enforceActiveEmergencySessionPermission();
8471
8472 final long identity = Binder.clearCallingIdentity();
8473 try {
8474 for (Phone phone: PhoneFactory.getPhones()) {
8475 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8476 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008477 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8478 }
8479 }
8480 } finally {
8481 Binder.restoreCallingIdentity(identity);
8482 }
8483 }
8484
8485 @Override
8486 public void resetOtaEmergencyNumberDbFilePath() {
8487 enforceActiveEmergencySessionPermission();
8488
8489 final long identity = Binder.clearCallingIdentity();
8490 try {
8491 for (Phone phone: PhoneFactory.getPhones()) {
8492 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8493 if (tracker != null) {
8494 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008495 }
8496 }
8497 } finally {
8498 Binder.restoreCallingIdentity(identity);
8499 }
8500 }
8501
8502 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008503 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8504 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8505 Phone phone = getPhone(subId);
8506 if (phone == null) {
8507 return null;
8508 }
8509 final long identity = Binder.clearCallingIdentity();
8510 try {
8511 UiccProfile profile = UiccController.getInstance()
8512 .getUiccProfileForPhone(phone.getPhoneId());
8513 if (profile != null) {
8514 return profile.getCertsFromCarrierPrivilegeAccessRules();
8515 }
8516 } finally {
8517 Binder.restoreCallingIdentity(identity);
8518 }
8519 return null;
8520 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008521
8522 /**
8523 * Enable or disable a modem stack.
8524 */
8525 @Override
8526 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8527 enforceModifyPermission();
8528
8529 final long identity = Binder.clearCallingIdentity();
8530 try {
8531 Phone phone = PhoneFactory.getPhone(slotIndex);
8532 if (phone == null) {
8533 return false;
8534 } else {
8535 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8536 }
8537 } finally {
8538 Binder.restoreCallingIdentity(identity);
8539 }
8540 }
Michelecea4cf22018-12-21 15:00:11 -08008541
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008542 /**
8543 * Whether a modem stack is enabled or not.
8544 */
8545 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008546 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8547 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008548 Phone phone = PhoneFactory.getPhone(slotIndex);
8549 if (phone == null) return false;
8550
8551 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008552 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8553 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008554 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8555 }
8556
8557 final long identity = Binder.clearCallingIdentity();
8558 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008559 try {
8560 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8561 } catch (NoSuchElementException ex) {
8562 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8563 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008564 } finally {
8565 Binder.restoreCallingIdentity(identity);
8566 }
8567 }
8568
Michelecea4cf22018-12-21 15:00:11 -08008569 @Override
Michele0ea7d782019-03-19 14:58:42 -07008570 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008571 enforceModifyPermission();
8572
8573 final long identity = Binder.clearCallingIdentity();
8574 try {
8575 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008576 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008577 .commit();
8578 } finally {
8579 Binder.restoreCallingIdentity(identity);
8580 }
8581 }
8582
8583 @Override
Michele0ea7d782019-03-19 14:58:42 -07008584 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008585 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008587 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8588 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008589 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008590 }
Michelecea4cf22018-12-21 15:00:11 -08008591
8592 final long identity = Binder.clearCallingIdentity();
8593 try {
Michele0ea7d782019-03-19 14:58:42 -07008594 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008595 } finally {
8596 Binder.restoreCallingIdentity(identity);
8597 }
8598 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008599
Michele0ea7d782019-03-19 14:58:42 -07008600 @TelephonyManager.IsMultiSimSupportedResult
8601 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008602 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8603 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8604 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008605 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8606 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008607 }
8608 // Check if the hardware supports multisim functionality. If usage of multisim is not
8609 // supported by the modem, indicate that it is restricted.
8610 PhoneCapability staticCapability =
8611 mPhoneConfigurationManager.getStaticPhoneCapability();
8612 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008613 loge("isMultiSimSupportedInternal: no static configuration available");
8614 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008615 }
Sarah Chin7caee492020-02-18 20:49:02 +00008616 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008617 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8618 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008619 }
8620 // Check if support of multiple SIMs is restricted by carrier
8621 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008622 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008623 }
8624
Michele0ea7d782019-03-19 14:58:42 -07008625 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008626 }
8627
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008628 /**
8629 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008630 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8631 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8632 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008633 * @param numOfSims number of active sims we want to switch to
8634 */
8635 @Override
8636 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008637 if (numOfSims == 1) {
8638 enforceModifyPermission();
8639 } else {
8640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8641 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8642 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008643 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008644
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008645 try {
Michele30b57b22019-03-01 12:01:14 -08008646 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008647 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008648 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8649 return;
8650 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008651 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8652 } finally {
8653 Binder.restoreCallingIdentity(identity);
8654 }
8655 }
8656
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008657 @Override
8658 public boolean isApplicationOnUicc(int subId, int appType) {
8659 enforceReadPrivilegedPermission("isApplicationOnUicc");
8660 Phone phone = getPhone(subId);
8661 if (phone == null) {
8662 return false;
8663 }
8664 final long identity = Binder.clearCallingIdentity();
8665 try {
8666 UiccCard uiccCard = phone.getUiccCard();
8667 if (uiccCard == null) {
8668 return false;
8669 }
8670 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8671 if (uiccProfile == null) {
8672 return false;
8673 }
8674 if (TelephonyManager.APPTYPE_SIM <= appType
8675 && appType <= TelephonyManager.APPTYPE_ISIM) {
8676 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8677 }
8678 return false;
8679 } finally {
8680 Binder.restoreCallingIdentity(identity);
8681 }
8682 }
8683
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008684 /**
chen xub4baa772019-04-03 10:23:41 -07008685 * Get whether making changes to modem configurations will trigger reboot.
8686 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008687 */
8688 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008689 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8690 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008691 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008692 mApp, subId, callingPackage, callingFeatureId,
8693 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008694 return false;
8695 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008696 final long identity = Binder.clearCallingIdentity();
8697 try {
8698 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8699 } finally {
8700 Binder.restoreCallingIdentity(identity);
8701 }
8702 }
8703
Nathan Harold29f5f052019-02-15 13:41:57 -08008704 private void updateModemStateMetrics() {
8705 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8706 // TODO: check the state for each modem if the api is ready.
8707 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8708 }
8709
Pengquan Meng3889a572019-01-23 11:16:29 -08008710 @Override
8711 public int[] getSlotsMapping() {
8712 enforceReadPrivilegedPermission("getSlotsMapping");
8713
8714 final long identity = Binder.clearCallingIdentity();
8715 try {
8716 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8717 // All logical slots should have a mapping to a physical slot.
8718 int[] logicalSlotsMapping = new int[phoneCount];
8719 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8720 for (int i = 0; i < slotInfos.length; i++) {
8721 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8722 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8723 }
8724 }
8725 return logicalSlotsMapping;
8726 } finally {
8727 Binder.restoreCallingIdentity(identity);
8728 }
8729 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008730
8731 /**
8732 * Get the IRadio HAL Version
8733 */
8734 @Override
8735 public int getRadioHalVersion() {
8736 Phone phone = getDefaultPhone();
8737 if (phone == null) return -1;
8738 HalVersion hv = phone.getHalVersion();
8739 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8740 return hv.major * 100 + hv.minor;
8741 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008742
8743 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008744 * Get the current calling package name.
8745 * @return the current calling package name
8746 */
8747 @Override
8748 public String getCurrentPackageName() {
8749 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8750 }
8751
8752 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008753 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8754 * corresponding network requests on a subId.
8755 *
8756 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008757 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008758 * 2) APN is un-metered for this subscription, or
8759 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07008760 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008761 *
8762 * @return whether data is allowed for a apn type.
8763 *
8764 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008765 */
8766 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008767 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008768 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8769 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008770
8771 // Now that all security checks passes, perform the operation as ourselves.
8772 final long identity = Binder.clearCallingIdentity();
8773 try {
8774 Phone phone = getPhone(subId);
8775 if (phone == null) return false;
8776
Jack Yu41407ee2019-05-13 16:54:09 -07008777 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008778 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8779 } finally {
8780 Binder.restoreCallingIdentity(identity);
8781 }
8782 }
8783
8784 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008785 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008786 enforceReadPrivilegedPermission("isApnMetered");
8787
8788 // Now that all security checks passes, perform the operation as ourselves.
8789 final long identity = Binder.clearCallingIdentity();
8790 try {
8791 Phone phone = getPhone(subId);
8792 if (phone == null) return true; // By default return true.
8793
Jack Yu41407ee2019-05-13 16:54:09 -07008794 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008795 } finally {
8796 Binder.restoreCallingIdentity(identity);
8797 }
8798 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008799
8800 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008801 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8802 int subscriptionId, IBooleanConsumer resultCallback) {
8803 enforceModifyPermission();
8804 long token = Binder.clearCallingIdentity();
8805 try {
8806 Phone phone = getPhone(subscriptionId);
8807 if (phone == null) {
8808 try {
8809 if (resultCallback != null) {
8810 resultCallback.accept(false);
8811 }
8812 } catch (RemoteException e) {
8813 // ignore
8814 }
8815 return;
8816 }
8817 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8818 Pair.create(specifiers, (x) -> {
8819 try {
8820 if (resultCallback != null) {
8821 resultCallback.accept(x);
8822 }
8823 } catch (RemoteException e) {
8824 // ignore
8825 }
8826 });
8827 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8828 } finally {
8829 Binder.restoreCallingIdentity(token);
8830 }
8831 }
8832
8833 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08008834 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8835 TelephonyPermissions
8836 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8837 mApp, subId, "getSystemSelectionChannels");
8838 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8839 final long identity = Binder.clearCallingIdentity();
8840 try {
8841 List<RadioAccessSpecifier> specifiers =
8842 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8843 null, subId, workSource);
8844 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8845 return specifiers;
8846 } finally {
8847 Binder.restoreCallingIdentity(identity);
8848 }
8849 }
8850
8851 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008852 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008853 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008854 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8855 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8856 if (iccRecords == null) {
8857 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8858 return false;
8859 }
8860 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8861 }
8862
8863 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008864 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8865 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008866 if (callingPackage == null) {
8867 callingPackage = getCurrentPackageName();
8868 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008869 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8870 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008871 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8872 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008873 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8874 }
8875 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8876 Intent intent = new Intent();
8877 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8878 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8879 // Bring up choose default SMS subscription dialog right now
8880 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8881 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8882 mApp.startActivity(intent);
8883 }
chen xud5ca2d52019-05-28 15:20:57 -07008884
8885 @Override
8886 public String getMmsUAProfUrl(int subId) {
8887 //TODO investigate if this API should require proper permission check in R b/133791609
8888 final long identity = Binder.clearCallingIdentity();
8889 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008890 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8891 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8892 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8893 return carrierUAProfUrl;
8894 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008895 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8896 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008897 } finally {
8898 Binder.restoreCallingIdentity(identity);
8899 }
8900 }
8901
8902 @Override
8903 public String getMmsUserAgent(int subId) {
8904 //TODO investigate if this API should require proper permission check in R b/133791609
8905 final long identity = Binder.clearCallingIdentity();
8906 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008907 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8908 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8909 if (!TextUtils.isEmpty(carrierUserAgent)) {
8910 return carrierUserAgent;
8911 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008912 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8913 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008914 } finally {
8915 Binder.restoreCallingIdentity(identity);
8916 }
8917 }
Jack Yub07d4972019-05-28 16:12:25 -07008918
8919 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008920 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8921 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07008922
Jack Yub07d4972019-05-28 16:12:25 -07008923 final long identity = Binder.clearCallingIdentity();
8924 try {
Hall Liua62f5da2020-09-25 10:42:19 -07008925 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07008926 if (phone == null) return false;
8927
Hall Liua62f5da2020-09-25 10:42:19 -07008928 switch (policy) {
8929 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8930 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8931 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8932 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8933 default:
8934 throw new IllegalArgumentException(policy + " is not a valid policy");
8935 }
Jack Yub07d4972019-05-28 16:12:25 -07008936 } finally {
8937 Binder.restoreCallingIdentity(identity);
8938 }
8939 }
8940
8941 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008942 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8943 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08008944 enforceModifyPermission();
8945
changbettyd5c246e2019-12-24 15:40:37 +08008946 final long identity = Binder.clearCallingIdentity();
8947 try {
Hall Liua62f5da2020-09-25 10:42:19 -07008948 Phone phone = getPhone(subscriptionId);
8949 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08008950
Hall Liua62f5da2020-09-25 10:42:19 -07008951 switch (policy) {
8952 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8953 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8954 break;
8955 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8956 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
8957 break;
8958 default:
8959 throw new IllegalArgumentException(policy + " is not a valid policy");
8960 }
changbettyd5c246e2019-12-24 15:40:37 +08008961 } finally {
8962 Binder.restoreCallingIdentity(identity);
8963 }
8964 }
8965
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008966 /**
Hall Liu746e03c2020-09-25 11:13:49 -07008967 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008968 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8969 * otherwise.
8970 */
8971 @Override
8972 public void setCepEnabled(boolean isCepEnabled) {
8973 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8974
8975 final long identity = Binder.clearCallingIdentity();
8976 try {
8977 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8978 for (Phone phone : PhoneFactory.getPhones()) {
8979 Phone defaultPhone = phone.getImsPhone();
8980 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8981 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8982 ImsPhoneCallTracker imsPhoneCallTracker =
8983 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8984 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8985 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8986 + imsPhone.getMsisdn());
8987 }
8988 }
8989 } finally {
8990 Binder.restoreCallingIdentity(identity);
8991 }
8992 }
allenwtsu46dcc572020-01-08 18:24:03 +08008993
8994 /**
8995 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8996 *
8997 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8998 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8999 * before being read.
9000 */
9001 @Override
9002 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9003 isCompressed) {
9004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9005 mApp, subId, "notifyRcsAutoConfigurationReceived");
9006 try {
9007 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9008 if (configBinder == null) {
9009 Rlog.e(LOG_TAG, "null result for getImsConfig");
9010 } else {
9011 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
9012 }
9013 } catch (RemoteException e) {
9014 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
9015 }
9016 }
zoey chene02881a2019-12-30 16:11:23 +08009017
9018 @Override
9019 public boolean isIccLockEnabled(int subId) {
9020 enforceReadPrivilegedPermission("isIccLockEnabled");
9021
9022 // Now that all security checks passes, perform the operation as ourselves.
9023 final long identity = Binder.clearCallingIdentity();
9024 try {
9025 Phone phone = getPhone(subId);
9026 if (phone != null && phone.getIccCard() != null) {
9027 return phone.getIccCard().getIccLockEnabled();
9028 } else {
9029 return false;
9030 }
9031 } finally {
9032 Binder.restoreCallingIdentity(identity);
9033 }
9034 }
9035
9036 /**
9037 * Set the ICC pin lock enabled or disabled.
9038 *
9039 * @return an integer representing the status of IccLock enabled or disabled in the following
9040 * three cases:
9041 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9042 * successfully.
9043 * - Positive number and zero for remaining password attempts.
9044 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9045 *
9046 */
9047 @Override
9048 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9049 enforceModifyPermission();
9050
9051 Phone phone = getPhone(subId);
9052 if (phone == null) {
9053 return 0;
9054 }
9055 // Now that all security checks passes, perform the operation as ourselves.
9056 final long identity = Binder.clearCallingIdentity();
9057 try {
9058 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9059 new Pair<Boolean, String>(enabled, password), phone, null);
9060 return attemptsRemaining;
9061
9062 } catch (Exception e) {
9063 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9064 } finally {
9065 Binder.restoreCallingIdentity(identity);
9066 }
9067 return 0;
9068 }
9069
9070 /**
9071 * Change the ICC password used in ICC pin lock.
9072 *
9073 * @return an integer representing the status of IccLock changed in the following three cases:
9074 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9075 * - Positive number and zero for remaining password attempts.
9076 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9077 *
9078 */
9079 @Override
9080 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9081 enforceModifyPermission();
9082
9083 Phone phone = getPhone(subId);
9084 if (phone == null) {
9085 return 0;
9086 }
9087 // Now that all security checks passes, perform the operation as ourselves.
9088 final long identity = Binder.clearCallingIdentity();
9089 try {
9090 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9091 new Pair<String, String>(oldPassword, newPassword), phone, null);
9092 return attemptsRemaining;
9093
9094 } catch (Exception e) {
9095 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9096 } finally {
9097 Binder.restoreCallingIdentity(identity);
9098 }
9099 return 0;
9100 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009101
9102 /**
9103 * Request for receiving user activity notification
9104 */
9105 @Override
9106 public void requestUserActivityNotification() {
9107 if (!mNotifyUserActivity.get()
9108 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9109 mNotifyUserActivity.set(true);
9110 }
9111 }
9112
9113 /**
9114 * Called when userActivity is signalled in the power manager.
9115 * This is safe to call from any thread, with any window manager locks held or not.
9116 */
9117 @Override
9118 public void userActivity() {
9119 // ***************************************
9120 // * Inherited from PhoneWindowManager *
9121 // ***************************************
9122 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9123 // WITH ITS LOCKS HELD.
9124 //
9125 // This code must be VERY careful about the locks
9126 // it acquires.
9127 // In fact, the current code acquires way too many,
9128 // and probably has lurking deadlocks.
9129
9130 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9131 throw new SecurityException("Only the OS may call notifyUserActivity()");
9132 }
9133
9134 if (mNotifyUserActivity.getAndSet(false)) {
9135 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9136 USER_ACTIVITY_NOTIFICATION_DELAY);
9137 }
9138 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009139
9140 @Override
9141 public boolean canConnectTo5GInDsdsMode() {
9142 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9143 }
Jack Yud10cdd42020-09-28 20:28:01 -07009144
9145 @Override
9146 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9147 String callingFeatureId) {
9148 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9149 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9150 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9151 }
9152
9153 Phone phone = getPhone(subId);
9154 if (phone == null) {
9155 throw new RuntimeException("phone is not available");
9156 }
9157 // Now that all security checks passes, perform the operation as ourselves.
9158 final long identity = Binder.clearCallingIdentity();
9159 try {
9160 return phone.getEquivalentHomePlmns();
9161 } finally {
9162 Binder.restoreCallingIdentity(identity);
9163 }
9164 }
Daniel Bright59e67312020-11-13 11:49:37 -08009165
9166 @Override
9167 public boolean isRadioInterfaceCapabilitySupported(
9168 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9169 RadioInterfaceCapabilities radioInterfaceCapabilities =
9170 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9171 if (radioInterfaceCapabilities == null) {
9172 throw new RuntimeException("radio interface capabilities are not available");
9173 } else {
9174 return radioInterfaceCapabilities.isSupported(capability);
9175 }
9176 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009177
Hui Wang641e81c2020-10-12 12:14:23 -07009178 @Override
9179 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9180 UaSecurityProtocolIdentifier securityProtocol,
9181 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9182 throws RemoteException {
9183 enforceModifyPermission();
9184 if (DBG) {
9185 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9186 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9187 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9188 }
9189
9190 if (!SubscriptionManager.isValidSubscriptionId(subId)
9191 || appType < TelephonyManager.APPTYPE_UNKNOWN
9192 || appType > TelephonyManager.APPTYPE_ISIM
9193 || nafUrl == null || securityProtocol == null || callback == null) {
9194 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9195 if (callback != null) {
9196 try {
9197 callback.onAuthenticationFailure(
9198 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9199 } catch (RemoteException exception) {
9200 log("Fail to notify onAuthenticationFailure due to " + exception);
9201 }
9202 return;
9203 }
9204 }
9205
9206 final long token = Binder.clearCallingIdentity();
9207 try {
9208 getGbaManager(subId).bootstrapAuthenticationRequest(
9209 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9210 forceBootStrapping, callback));
9211 } finally {
9212 Binder.restoreCallingIdentity(token);
9213 }
9214 }
9215
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009216 /**
9217 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9218 * requested radio power state will actually be set. See {@link
9219 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9220 *
9221 * @param subId the subscription ID of the phone requesting to set the radio power state.
9222 * @param enable {@code true} if trying to turn radio on.
9223 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9224 * false}.
9225 */
9226 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9227 Phone phone = getPhone(subId);
9228 if (phone != null) {
9229 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9230 return true;
9231 }
9232 return false;
9233 }
9234
9235 private int handleDataThrottlingRequest(int subId,
9236 DataThrottlingRequest dataThrottlingRequest) {
9237 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9238 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9239 if (!setRadioPowerForThermal(subId, true)) {
9240 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9241 }
9242
9243 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9244
9245 int thermalMitigationResult =
9246 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9247 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9248 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9249 }
9250 return thermalMitigationResult;
9251 }
9252
9253 /**
9254 * Thermal mitigation request to control functionalities at modem.
9255 *
9256 * @param subId the id of the subscription.
9257 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9258 *
9259 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9260 */
9261 @Override
9262 @ThermalMitigationResult
9263 public int sendThermalMitigationRequest(
9264 int subId,
9265 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9266 enforceModifyPermission();
9267
9268 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9269 final long identity = Binder.clearCallingIdentity();
9270
9271 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9272 try {
9273 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9274 switch (thermalMitigationAction) {
9275 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9276 thermalMitigationResult =
9277 handleDataThrottlingRequest(subId,
9278 thermalMitigationRequest.getDataThrottlingRequest());
9279 break;
9280 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9281 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9282 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9283 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9284 }
9285
9286 // Ensure that radio is on. If not able to power on due to phone being
9287 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9288 if (!setRadioPowerForThermal(subId, true)) {
9289 thermalMitigationResult =
9290 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9291 break;
9292 }
9293
9294 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9295 false);
9296 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9297 break;
9298 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9299 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9300 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9301 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9302 }
9303
9304 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9305 if (registry != null) {
9306 TelephonyConnectionService service =
9307 registry.getTelephonyConnectionService();
9308 Phone phone = getPhone(subId);
9309 if (phone == null) {
9310 thermalMitigationResult =
9311 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9312 break;
9313 }
9314
9315 if (PhoneConstantConversions.convertCallState(phone.getState())
9316 != TelephonyManager.CALL_STATE_IDLE
9317 || phone.isInEmergencySmsMode() || phone.isInEcm()
9318 || (service != null && service.isEmergencyCallPending())) {
9319 String errorMessage = "Phone state is not valid. call state = "
9320 + PhoneConstantConversions.convertCallState(phone.getState())
9321 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9322 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9323 errorMessage += service == null
9324 ? " TelephonyConnectionService is null"
9325 : " isEmergencyCallPending = "
9326 + service.isEmergencyCallPending();
9327 Log.e(LOG_TAG, errorMessage);
9328 thermalMitigationResult =
9329 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9330 break;
9331 }
9332 } else {
9333 thermalMitigationResult =
9334 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9335 break;
9336 }
9337
9338 // Turn radio off. If not able to power off due to phone being unavailable,
9339 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9340 if (!setRadioPowerForThermal(subId, false)) {
9341 thermalMitigationResult =
9342 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9343 break;
9344 }
9345 thermalMitigationResult =
9346 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9347 break;
9348 default:
9349 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9350 + "not exist. Requested action: " + thermalMitigationAction);
9351 }
9352 } catch (IllegalArgumentException e) {
9353 throw e;
9354 } catch (Exception e) {
9355 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9356 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9357 } finally {
9358 Binder.restoreCallingIdentity(identity);
9359 }
9360
9361 if (DBG) {
9362 log("thermalMitigationRequest returning with thermalMitigationResult: "
9363 + thermalMitigationResult);
9364 }
9365
9366 return thermalMitigationResult;
9367 }
Hui Wang641e81c2020-10-12 12:14:23 -07009368
9369 /**
9370 * Set the GbaService Package Name that Telephony will bind to.
9371 *
9372 * @param subId The sim that the GbaService is associated with.
9373 * @param packageName The name of the package to be replaced with.
9374 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9375 */
9376 @Override
9377 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9378 enforceModifyPermission();
9379
9380 final long identity = Binder.clearCallingIdentity();
9381 try {
9382 return getGbaManager(subId).overrideServicePackage(packageName);
9383 } finally {
9384 Binder.restoreCallingIdentity(identity);
9385 }
9386 }
9387
9388 /**
9389 * Return the package name of the currently bound GbaService.
9390 *
9391 * @param subId The sim that the GbaService is associated with.
9392 * @return the package name of the GbaService configuration, null if GBA is not supported.
9393 */
9394 @Override
9395 public String getBoundGbaService(int subId) {
9396 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9397
9398 final long identity = Binder.clearCallingIdentity();
9399 try {
9400 return getGbaManager(subId).getServicePackage();
9401 } finally {
9402 Binder.restoreCallingIdentity(identity);
9403 }
9404 }
9405
9406 /**
9407 * Set the release time for telephony to unbind GbaService.
9408 *
9409 * @param subId The sim that the GbaService is associated with.
9410 * @param interval The release time to unbind GbaService by millisecond.
9411 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9412 */
9413 @Override
9414 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9415 enforceModifyPermission();
9416
9417 final long identity = Binder.clearCallingIdentity();
9418 try {
9419 return getGbaManager(subId).overrideReleaseTime(interval);
9420 } finally {
9421 Binder.restoreCallingIdentity(identity);
9422 }
9423 }
9424
9425 /**
9426 * Return the release time for telephony to unbind GbaService.
9427 *
9428 * @param subId The sim that the GbaService is associated with.
9429 * @return The release time to unbind GbaService by millisecond.
9430 */
9431 @Override
9432 public int getGbaReleaseTime(int subId) {
9433 enforceReadPrivilegedPermission("getGbaReleaseTime");
9434
9435 final long identity = Binder.clearCallingIdentity();
9436 try {
9437 return getGbaManager(subId).getReleaseTime();
9438 } finally {
9439 Binder.restoreCallingIdentity(identity);
9440 }
9441 }
9442
9443 private GbaManager getGbaManager(int subId) {
9444 GbaManager instance = GbaManager.getInstance(subId);
9445 if (instance == null) {
9446 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9447 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9448 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9449 }
9450 return instance;
9451 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009452}