blob: 6125bd83e508a07202c51f2546df14b7ed2323d4 [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;
changbetty363e8ac2019-12-06 18:16:37 +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;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080040import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Bundle;
42import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Looper;
45import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080047import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080050import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080051import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070052import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070053import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080054import android.os.SystemClock;
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 Nalluri8ff344d2019-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 Kim8d298d42018-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 Xuc7b18ec2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Jack Nudelman24d51a52020-11-24 12:08:04 -080067import android.telephony.Annotation.ThermalMitigationResult;
sqian80370722020-01-29 15:02:51 -080068import android.telephony.CallForwardingInfo;
Sooraj Sasindran1f812e02020-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 zhaod698b842019-09-06 17:06:54 -070072import android.telephony.CellIdentity;
Meng Wangd64acad2019-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 Nudelman24d51a52020-11-24 12:08:04 -080079import android.telephony.DataThrottlingRequest;
Hui Wang0866fcc2020-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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080092import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080093import android.telephony.SignalStrengthUpdateRequest;
94import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080095import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080096import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080097import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070098import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070099import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800100import android.telephony.TelephonyScanManager;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800101import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800102import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000103import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700104import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700105import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800106import android.telephony.data.ApnSetting;
107import android.telephony.emergency.EmergencyNumber;
Hui Wang0866fcc2020-10-12 12:14:23 -0700108import android.telephony.gba.GbaAuthRequest;
109import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700110import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800111import android.telephony.ims.ProvisioningManager;
Hui Wang068ab862020-10-31 05:12:53 +0000112import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger774ba362019-10-22 17:36:18 -0700113import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700114import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800115import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700116import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800117import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700118import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang068ab862020-10-31 05:12:53 +0000119import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700120import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800121import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800122import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800123import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800124import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800126import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700127import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800129import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800130
Andrew Lee312e8172014-10-23 17:01:36 -0700131import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800132import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800133import com.android.ims.rcs.uce.eab.EabUtil;
sqian80370722020-01-29 15:02:51 -0800134import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700135import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700136import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700137import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800138import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700139import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700140import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800141import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang0866fcc2020-10-12 12:14:23 -0700143import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800144import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800145import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700146import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700147import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800148import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800150import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700151import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700152import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700153import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700155import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800156import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700157import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700158import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700159import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700160import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700161import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700162import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700163import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700164import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800165import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800166import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800167import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700168import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800169import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700170import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800171import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700172import com.android.internal.telephony.imsphone.ImsPhone;
173import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800174import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900175import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700176import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800177import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700178import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800179import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700180import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800181import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700182import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800183import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000184import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800185import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700186import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700187import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800188import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700189import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700190import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800191import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700192import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700193import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800194import com.android.services.telephony.TelecomAccountRegistry;
195import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800196import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800197
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700198import java.io.FileDescriptor;
199import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800201import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800202import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800203import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800204import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100205import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800206import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700207import java.util.NoSuchElementException;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800208import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800209import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800210import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800211import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700212
213/**
214 * Implementation of the ITelephony interface.
215 */
Santos Cordon117fee72014-05-16 17:56:12 -0700216public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217 private static final String LOG_TAG = "PhoneInterfaceManager";
218 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
219 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800220 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700221
222 // Message codes used with mMainThreadHandler
223 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700224 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
225 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700226 private static final int CMD_OPEN_CHANNEL = 9;
227 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
228 private static final int CMD_CLOSE_CHANNEL = 11;
229 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800230 private static final int CMD_NV_READ_ITEM = 13;
231 private static final int EVENT_NV_READ_ITEM_DONE = 14;
232 private static final int CMD_NV_WRITE_ITEM = 15;
233 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
234 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
235 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700236 private static final int CMD_RESET_MODEM_CONFIG = 19;
237 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800238 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
239 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
240 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
241 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800242 private static final int CMD_SEND_ENVELOPE = 25;
243 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000244 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
245 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700246 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
247 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
248 private static final int CMD_EXCHANGE_SIM_IO = 31;
249 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800250 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
251 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700252 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
253 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700254 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
255 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700256 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
257 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
258 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
259 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700260 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
261 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
262 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
263 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700264 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800265 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
266 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000267 private static final int CMD_SWITCH_SLOTS = 50;
268 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700269 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
270 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
271 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
272 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
273 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
274 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
275 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
276 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700277 private static final int CMD_GET_ALL_CELL_INFO = 60;
278 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
279 private static final int CMD_GET_CELL_LOCATION = 62;
280 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700281 private static final int CMD_MODEM_REBOOT = 64;
282 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700283 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
284 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800285 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
286 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700287 private static final int CMD_GET_MODEM_STATUS = 70;
288 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700289 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
290 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700291 private static final int CMD_ERASE_MODEM_CONFIG = 74;
292 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800293 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
294 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
295 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
296 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800297 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
298 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800299 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800300 private static final int CMD_GET_CALL_FORWARDING = 83;
301 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
302 private static final int CMD_SET_CALL_FORWARDING = 85;
303 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
304 private static final int CMD_GET_CALL_WAITING = 87;
305 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
306 private static final int CMD_SET_CALL_WAITING = 89;
307 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700308 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
309 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
310 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
311 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700312 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
313 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800314 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
315 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800316 private static final int CMD_SET_DATA_THROTTLING = 99;
317 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800318 private static final int CMD_SET_SIM_POWER = 101;
319 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800320 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
321 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
322 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
323 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700324
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800325 // Parameters of select command.
326 private static final int SELECT_COMMAND = 0xA4;
327 private static final int SELECT_P1 = 0x04;
328 private static final int SELECT_P2 = 0;
329 private static final int SELECT_P3 = 0x10;
330
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700331 /** The singleton instance. */
332 private static PhoneInterfaceManager sInstance;
333
Wink Saville3ab207e2014-11-20 13:07:20 -0800334 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800335 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800336 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700337 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800338 private AppOpsManager mAppOps;
339 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800340 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800341 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700342 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343
Peter Wangdafb9ac2020-01-15 14:13:38 -0800344 /** User Activity */
345 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800346 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
347
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700348 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
349
Derek Tan97ebb422014-09-05 16:55:38 -0700350 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
351 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800352 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800353 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700354
Michelecea4cf22018-12-21 15:00:11 -0800355 // String to store multi SIM allowed
356 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
357
Derek Tan740e1672017-06-27 14:56:27 -0700358 // The AID of ISD-R.
359 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
360
yinxub1bed742017-04-17 11:45:04 -0700361 private NetworkScanRequestTracker mNetworkScanRequestTracker;
362
David Kelly5e06a7f2018-03-12 14:10:59 +0000363 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
364 private static final int MANUFACTURER_CODE_LENGTH = 8;
365
Jack Nudelman24d51a52020-11-24 12:08:04 -0800366 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
367
Derek Tan89e89d42014-07-08 17:00:10 -0700368 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700369 * Experiment flag to enable erase modem config on reset network, default value is false
370 */
371 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
372 "reset_network_erase_modem_config_enabled";
373
Rambo Wang0f050d82021-02-12 11:43:36 -0800374 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
375
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700376 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700377 * A request object to use for transmitting data to an ICC.
378 */
379 private static final class IccAPDUArgument {
380 public int channel, cla, command, p1, p2, p3;
381 public String data;
382
383 public IccAPDUArgument(int channel, int cla, int command,
384 int p1, int p2, int p3, String data) {
385 this.channel = channel;
386 this.cla = cla;
387 this.command = command;
388 this.p1 = p1;
389 this.p2 = p2;
390 this.p3 = p3;
391 this.data = data;
392 }
393 }
394
395 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700396 * A request object to use for transmitting data to an ICC.
397 */
398 private static final class ManualNetworkSelectionArgument {
399 public OperatorInfo operatorInfo;
400 public boolean persistSelection;
401
402 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
403 this.operatorInfo = operatorInfo;
404 this.persistSelection = persistSelection;
405 }
406 }
407
408 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
410 * request after sending. The main thread will notify the request when it is complete.
411 */
412 private static final class MainThreadRequest {
413 /** The argument to use for the request */
414 public Object argument;
415 /** The result of the request that is run on the main thread */
416 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800417 // The subscriber id that this request applies to. Defaults to
418 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
419 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700420
Nathan Harold92bed182018-10-12 18:16:49 -0700421 // In cases where subId is unavailable, the caller needs to specify the phone.
422 public Phone phone;
423
vagdeviaf9a5b92018-08-15 16:01:53 -0700424 public WorkSource workSource;
425
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700426 public MainThreadRequest(Object argument) {
427 this.argument = argument;
428 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800429
Nathan Harold92bed182018-10-12 18:16:49 -0700430 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
431 this.argument = argument;
432 if (phone != null) {
433 this.phone = phone;
434 }
435 this.workSource = workSource;
436 }
437
vagdeviaf9a5b92018-08-15 16:01:53 -0700438 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800439 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800440 if (subId != null) {
441 this.subId = subId;
442 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700443 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445 }
446
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800447 private static final class IncomingThirdPartyCallArgs {
448 public final ComponentName component;
449 public final String callId;
450 public final String callerDisplayName;
451
452 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
453 String callerDisplayName) {
454 this.component = component;
455 this.callId = callId;
456 this.callerDisplayName = callerDisplayName;
457 }
458 }
459
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700460 /**
461 * A handler that processes messages on the main thread in the phone process. Since many
462 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
463 * inbound binder threads to the main thread in the phone process. The Binder thread
464 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
465 * on, which will be notified when the operation completes and will contain the result of the
466 * request.
467 *
468 * <p>If a MainThreadRequest object is provided in the msg.obj field,
469 * note that request.result must be set to something non-null for the calling thread to
470 * unblock.
471 */
472 private final class MainThreadHandler extends Handler {
473 @Override
474 public void handleMessage(Message msg) {
475 MainThreadRequest request;
476 Message onCompleted;
477 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800478 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700479 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800480 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481
482 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700483 case CMD_HANDLE_USSD_REQUEST: {
484 request = (MainThreadRequest) msg.obj;
485 final Phone phone = getPhoneFromRequest(request);
486 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
487 String ussdRequest = ussdObject.first;
488 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700489
Pengquan Menga1bb6272018-09-06 09:59:22 -0700490 if (!isUssdApiAllowed(request.subId)) {
491 // Carrier does not support use of this API, return failure.
492 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
493 UssdResponse response = new UssdResponse(ussdRequest, null);
494 Bundle returnData = new Bundle();
495 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
496 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700497
Pengquan Menga1bb6272018-09-06 09:59:22 -0700498 request.result = true;
499 notifyRequester(request);
500 return;
501 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700502
Pengquan Menga1bb6272018-09-06 09:59:22 -0700503 try {
504 request.result = phone != null
505 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
506 } catch (CallStateException cse) {
507 request.result = false;
508 }
509 // Wake up the requesting thread
510 notifyRequester(request);
511 break;
pkanwar32d516d2016-10-14 19:37:38 -0700512 }
513
Yorke Lee716f67e2015-06-17 15:39:16 -0700514 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700515 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700516 final Phone phone = getPhoneFromRequest(request);
517 request.result = phone != null ?
518 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
519 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700521 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700522 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700524
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700525 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700526 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800528 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700529 if (uiccCard == null) {
530 loge("iccTransmitApduLogicalChannel: No UICC");
531 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700533 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
535 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700536 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700537 iccArgument.channel, iccArgument.cla, iccArgument.command,
538 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700539 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700540 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700541 break;
542
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700543 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700544 ar = (AsyncResult) msg.obj;
545 request = (MainThreadRequest) ar.userObj;
546 if (ar.exception == null && ar.result != null) {
547 request.result = ar.result;
548 } else {
549 request.result = new IccIoResult(0x6F, 0, (byte[])null);
550 if (ar.result == null) {
551 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800552 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700553 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800554 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700555 } else {
556 loge("iccTransmitApduLogicalChannel: Unknown exception");
557 }
558 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700560 break;
561
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
563 request = (MainThreadRequest) msg.obj;
564 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800565 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 if (uiccCard == null) {
567 loge("iccTransmitApduBasicChannel: No UICC");
568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 } else {
571 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
572 request);
573 uiccCard.iccTransmitApduBasicChannel(
574 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
575 iccArgument.p3, iccArgument.data, onCompleted);
576 }
577 break;
578
579 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
580 ar = (AsyncResult) msg.obj;
581 request = (MainThreadRequest) ar.userObj;
582 if (ar.exception == null && ar.result != null) {
583 request.result = ar.result;
584 } else {
585 request.result = new IccIoResult(0x6F, 0, (byte[])null);
586 if (ar.result == null) {
587 loge("iccTransmitApduBasicChannel: Empty response");
588 } else if (ar.exception instanceof CommandException) {
589 loge("iccTransmitApduBasicChannel: CommandException: " +
590 ar.exception);
591 } else {
592 loge("iccTransmitApduBasicChannel: Unknown exception");
593 }
594 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700595 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 break;
597
598 case CMD_EXCHANGE_SIM_IO:
599 request = (MainThreadRequest) msg.obj;
600 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800601 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700602 if (uiccCard == null) {
603 loge("iccExchangeSimIO: No UICC");
604 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700605 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 } else {
607 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
608 request);
609 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
610 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
611 iccArgument.data, onCompleted);
612 }
613 break;
614
615 case EVENT_EXCHANGE_SIM_IO_DONE:
616 ar = (AsyncResult) msg.obj;
617 request = (MainThreadRequest) ar.userObj;
618 if (ar.exception == null && ar.result != null) {
619 request.result = ar.result;
620 } else {
621 request.result = new IccIoResult(0x6f, 0, (byte[])null);
622 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700623 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 break;
625
Derek Tan4d5e5c12014-02-04 11:54:58 -0800626 case CMD_SEND_ENVELOPE:
627 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800628 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700629 if (uiccCard == null) {
630 loge("sendEnvelopeWithStatus: No UICC");
631 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700632 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700633 } else {
634 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
635 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
636 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800637 break;
638
639 case EVENT_SEND_ENVELOPE_DONE:
640 ar = (AsyncResult) msg.obj;
641 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700642 if (ar.exception == null && ar.result != null) {
643 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800644 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700645 request.result = new IccIoResult(0x6F, 0, (byte[])null);
646 if (ar.result == null) {
647 loge("sendEnvelopeWithStatus: Empty response");
648 } else if (ar.exception instanceof CommandException) {
649 loge("sendEnvelopeWithStatus: CommandException: " +
650 ar.exception);
651 } else {
652 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
653 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800654 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700655 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800656 break;
657
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 case CMD_OPEN_CHANNEL:
659 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800660 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800661 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700662 if (uiccCard == null) {
663 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800664 request.result = new IccOpenLogicalChannelResponse(-1,
665 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700666 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700667 } else {
668 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800669 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
670 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700671 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 break;
673
674 case EVENT_OPEN_CHANNEL_DONE:
675 ar = (AsyncResult) msg.obj;
676 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700677 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700679 int[] result = (int[]) ar.result;
680 int channelId = result[0];
681 byte[] selectResponse = null;
682 if (result.length > 1) {
683 selectResponse = new byte[result.length - 1];
684 for (int i = 1; i < result.length; ++i) {
685 selectResponse[i - 1] = (byte) result[i];
686 }
687 }
688 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700689 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 if (ar.result == null) {
692 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700694 if (ar.exception != null) {
695 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
696 }
697
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700698 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700699 if (ar.exception instanceof CommandException) {
700 CommandException.Error error =
701 ((CommandException) (ar.exception)).getCommandError();
702 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700703 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700704 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700705 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700706 }
707 }
708 openChannelResp = new IccOpenLogicalChannelResponse(
709 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700710 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700711 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700712 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 break;
714
715 case CMD_CLOSE_CHANNEL:
716 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800717 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700718 if (uiccCard == null) {
719 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900720 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700721 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700722 } else {
723 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
724 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
725 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700726 break;
727
728 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800729 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
730 break;
731
732 case CMD_NV_READ_ITEM:
733 request = (MainThreadRequest) msg.obj;
734 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800735 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
736 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800737 break;
738
739 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 ar = (AsyncResult) msg.obj;
741 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800742 if (ar.exception == null && ar.result != null) {
743 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700744 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800745 request.result = "";
746 if (ar.result == null) {
747 loge("nvReadItem: Empty response");
748 } else if (ar.exception instanceof CommandException) {
749 loge("nvReadItem: CommandException: " +
750 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700751 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800752 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700753 }
754 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700755 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700756 break;
757
Jake Hambye994d462014-02-03 13:10:13 -0800758 case CMD_NV_WRITE_ITEM:
759 request = (MainThreadRequest) msg.obj;
760 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
761 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800762 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700763 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800764 break;
765
766 case EVENT_NV_WRITE_ITEM_DONE:
767 handleNullReturnEvent(msg, "nvWriteItem");
768 break;
769
770 case CMD_NV_WRITE_CDMA_PRL:
771 request = (MainThreadRequest) msg.obj;
772 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800773 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800774 break;
775
776 case EVENT_NV_WRITE_CDMA_PRL_DONE:
777 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
778 break;
779
chen xu6dac5ab2018-10-26 17:39:23 -0700780 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800781 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700782 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800783 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800784 break;
785
chen xu6dac5ab2018-10-26 17:39:23 -0700786 case EVENT_RESET_MODEM_CONFIG_DONE:
787 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800788 break;
789
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700790 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
791 request = (MainThreadRequest) msg.obj;
792 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
793 request);
794 Phone phone = getPhoneFromRequest(request);
795 if (phone != null) {
796 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
797 } else {
798 loge("isNRDualConnectivityEnabled: No phone object");
799 request.result = false;
800 notifyRequester(request);
801 }
802 break;
803 }
804
805 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
806 ar = (AsyncResult) msg.obj;
807 request = (MainThreadRequest) ar.userObj;
808 if (ar.exception == null && ar.result != null) {
809 request.result = ar.result;
810 } else {
811 // request.result must be set to something non-null
812 // for the calling thread to unblock
813 if (request.result != null) {
814 request.result = ar.result;
815 } else {
816 request.result = false;
817 }
818 if (ar.result == null) {
819 loge("isNRDualConnectivityEnabled: Empty response");
820 } else if (ar.exception instanceof CommandException) {
821 loge("isNRDualConnectivityEnabled: CommandException: "
822 + ar.exception);
823 } else {
824 loge("isNRDualConnectivityEnabled: Unknown exception");
825 }
826 }
827 notifyRequester(request);
828 break;
829
830 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
831 request = (MainThreadRequest) msg.obj;
832 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
833 Phone phone = getPhoneFromRequest(request);
834 if (phone != null) {
835 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
836 request.workSource);
837 } else {
838 loge("enableNrDualConnectivity: No phone object");
839 request.result =
840 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
841 notifyRequester(request);
842 }
843 break;
844 }
845
846 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
847 ar = (AsyncResult) msg.obj;
848 request = (MainThreadRequest) ar.userObj;
849 if (ar.exception == null) {
850 request.result =
851 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
852 } else {
853 request.result =
854 TelephonyManager
855 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
856 if (ar.exception instanceof CommandException) {
857 CommandException.Error error =
858 ((CommandException) (ar.exception)).getCommandError();
859 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
860 request.result =
861 TelephonyManager
862 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
863 }
864 loge("enableNrDualConnectivity" + ": CommandException: "
865 + ar.exception);
866 } else {
867 loge("enableNrDualConnectivity" + ": Unknown exception");
868 }
869 }
870 notifyRequester(request);
871 break;
872 }
873
Jake Hamby7c27be32014-03-03 13:25:59 -0800874 case CMD_GET_PREFERRED_NETWORK_TYPE:
875 request = (MainThreadRequest) msg.obj;
876 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700877 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800878 break;
879
880 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
881 ar = (AsyncResult) msg.obj;
882 request = (MainThreadRequest) ar.userObj;
883 if (ar.exception == null && ar.result != null) {
884 request.result = ar.result; // Integer
885 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530886 // request.result must be set to something non-null
887 // for the calling thread to unblock
888 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800889 if (ar.result == null) {
890 loge("getPreferredNetworkType: Empty response");
891 } else if (ar.exception instanceof CommandException) {
892 loge("getPreferredNetworkType: CommandException: " +
893 ar.exception);
894 } else {
895 loge("getPreferredNetworkType: Unknown exception");
896 }
897 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700898 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800899 break;
900
901 case CMD_SET_PREFERRED_NETWORK_TYPE:
902 request = (MainThreadRequest) msg.obj;
903 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
904 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700905 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800906 break;
907
908 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
909 handleNullReturnEvent(msg, "setPreferredNetworkType");
910 break;
911
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000912 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
913 request = (MainThreadRequest)msg.obj;
914 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800915 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000916 break;
917
918 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
919 ar = (AsyncResult)msg.obj;
920 request = (MainThreadRequest)ar.userObj;
921 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700922 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000923 break;
924
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800925 case CMD_SET_VOICEMAIL_NUMBER:
926 request = (MainThreadRequest) msg.obj;
927 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
928 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800929 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
930 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800931 break;
932
933 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
934 handleNullReturnEvent(msg, "setVoicemailNumber");
935 break;
936
Stuart Scott54788802015-03-30 13:18:01 -0700937 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
938 request = (MainThreadRequest) msg.obj;
939 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
940 request);
941 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
942 break;
943
944 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
945 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
946 break;
947
Shishir Agrawal302c8692015-06-19 13:49:39 -0700948 case CMD_PERFORM_NETWORK_SCAN:
949 request = (MainThreadRequest) msg.obj;
950 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
951 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
952 break;
953
Hall Liua1acea22020-09-18 19:04:59 -0700954 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800955 request = (MainThreadRequest) msg.obj;
956 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700957 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
958 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
959 request.argument;
960 int callForwardingReason = args.first;
961 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800962 break;
Hall Liua1acea22020-09-18 19:04:59 -0700963 }
964 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800965 ar = (AsyncResult) msg.obj;
966 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700967 TelephonyManager.CallForwardingInfoCallback callback =
968 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
969 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800970 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700971 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800972 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
973 for (CallForwardInfo callForwardInfo : callForwardInfos) {
974 // Service Class is a bit mask per 3gpp 27.007. Search for
975 // any service for voice call.
976 if ((callForwardInfo.serviceClass
977 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700978 callForwardingInfo = new CallForwardingInfo(true,
979 callForwardInfo.reason,
980 callForwardInfo.number,
981 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800982 break;
983 }
984 }
985 // Didn't find a call forward info for voice call.
986 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700987 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
988 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800989 }
Hall Liua1acea22020-09-18 19:04:59 -0700990 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -0800991 } else {
992 if (ar.result == null) {
993 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
994 }
995 if (ar.exception != null) {
996 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
997 }
Hall Liuae527aa2020-09-29 17:10:18 -0700998 int errorCode = TelephonyManager
999 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001000 if (ar.exception instanceof CommandException) {
1001 CommandException.Error error =
1002 ((CommandException) (ar.exception)).getCommandError();
1003 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001004 errorCode = TelephonyManager
1005 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001006 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001007 errorCode = TelephonyManager
1008 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001009 }
1010 }
Hall Liua1acea22020-09-18 19:04:59 -07001011 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001012 }
sqian80370722020-01-29 15:02:51 -08001013 break;
Hall Liua1acea22020-09-18 19:04:59 -07001014 }
sqian80370722020-01-29 15:02:51 -08001015
Hall Liua1acea22020-09-18 19:04:59 -07001016 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001017 request = (MainThreadRequest) msg.obj;
1018 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001019 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001020 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001021 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1022 request.argument).first;
1023 request.phone.setCallForwardingOption(
1024 callForwardingInfoToSet.isEnabled()
1025 ? CommandsInterface.CF_ACTION_ENABLE
1026 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001027 callForwardingInfoToSet.getReason(),
1028 callForwardingInfoToSet.getNumber(),
1029 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1030 break;
Hall Liua1acea22020-09-18 19:04:59 -07001031 }
sqian80370722020-01-29 15:02:51 -08001032
Hall Liua1acea22020-09-18 19:04:59 -07001033 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001034 ar = (AsyncResult) msg.obj;
1035 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001036 Consumer<Integer> callback =
1037 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1038 request.argument).second;
1039 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001040 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001041 int errorCode = TelephonyManager.CallForwardingInfoCallback
1042 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001043 if (ar.exception instanceof CommandException) {
1044 CommandException.Error error =
1045 ((CommandException) (ar.exception)).getCommandError();
1046 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001047 errorCode = TelephonyManager.CallForwardingInfoCallback
1048 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001049 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001050 errorCode = TelephonyManager.CallForwardingInfoCallback
1051 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001052 }
1053 }
1054 callback.accept(errorCode);
1055 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001056 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001057 }
sqian80370722020-01-29 15:02:51 -08001058 break;
Hall Liua1acea22020-09-18 19:04:59 -07001059 }
sqian80370722020-01-29 15:02:51 -08001060
Hall Liua1acea22020-09-18 19:04:59 -07001061 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001062 request = (MainThreadRequest) msg.obj;
1063 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1064 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1065 break;
Hall Liua1acea22020-09-18 19:04:59 -07001066 }
sqian80370722020-01-29 15:02:51 -08001067
Hall Liua1acea22020-09-18 19:04:59 -07001068 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001069 ar = (AsyncResult) msg.obj;
1070 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001071 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001072 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1073 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001074 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001075 // Service Class is a bit mask per 3gpp 27.007.
1076 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001077 if (callForwardResults.length > 1
1078 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001079 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001080 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001081 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1082 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001083 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001084 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001085 }
1086 } else {
1087 if (ar.result == null) {
1088 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1089 }
1090 if (ar.exception != null) {
1091 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1092 }
1093 if (ar.exception instanceof CommandException) {
1094 CommandException.Error error =
1095 ((CommandException) (ar.exception)).getCommandError();
1096 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1097 callForwardingStatus =
1098 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1099 }
1100 }
1101 }
Hall Liua1acea22020-09-18 19:04:59 -07001102 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001103 break;
Hall Liua1acea22020-09-18 19:04:59 -07001104 }
sqian80370722020-01-29 15:02:51 -08001105
Hall Liua1acea22020-09-18 19:04:59 -07001106 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001107 request = (MainThreadRequest) msg.obj;
1108 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001109 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1110 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001111 break;
Hall Liua1acea22020-09-18 19:04:59 -07001112 }
sqian80370722020-01-29 15:02:51 -08001113
Hall Liua1acea22020-09-18 19:04:59 -07001114 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001115 ar = (AsyncResult) msg.obj;
1116 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001117 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1118 Consumer<Integer> callback =
1119 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1120 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001121 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001122 if (ar.exception instanceof CommandException) {
1123 CommandException.Error error =
1124 ((CommandException) (ar.exception)).getCommandError();
1125 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1126 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1127 } else {
1128 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1129 }
1130 } else {
1131 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1132 }
1133 } else {
1134 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1135 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001136 }
sqian80370722020-01-29 15:02:51 -08001137 break;
Hall Liua1acea22020-09-18 19:04:59 -07001138 }
sqian80370722020-01-29 15:02:51 -08001139
Shishir Agrawal302c8692015-06-19 13:49:39 -07001140 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1141 ar = (AsyncResult) msg.obj;
1142 request = (MainThreadRequest) ar.userObj;
1143 CellNetworkScanResult cellScanResult;
1144 if (ar.exception == null && ar.result != null) {
1145 cellScanResult = new CellNetworkScanResult(
1146 CellNetworkScanResult.STATUS_SUCCESS,
1147 (List<OperatorInfo>) ar.result);
1148 } else {
1149 if (ar.result == null) {
1150 loge("getCellNetworkScanResults: Empty response");
1151 }
1152 if (ar.exception != null) {
1153 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1154 }
1155 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1156 if (ar.exception instanceof CommandException) {
1157 CommandException.Error error =
1158 ((CommandException) (ar.exception)).getCommandError();
1159 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1160 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1161 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1162 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1163 }
1164 }
1165 cellScanResult = new CellNetworkScanResult(errorCode, null);
1166 }
1167 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001168 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001169 break;
1170
1171 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1172 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001173 ManualNetworkSelectionArgument selArg =
1174 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001175 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1176 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001177 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1178 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001179 break;
1180
1181 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001182 ar = (AsyncResult) msg.obj;
1183 request = (MainThreadRequest) ar.userObj;
1184 if (ar.exception == null) {
1185 request.result = true;
1186 } else {
1187 request.result = false;
1188 loge("setNetworkSelectionModeManual " + ar.exception);
1189 }
1190 notifyRequester(request);
1191 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001192 break;
1193
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001194 case CMD_GET_MODEM_ACTIVITY_INFO:
1195 request = (MainThreadRequest) msg.obj;
1196 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001197 if (defaultPhone != null) {
1198 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001199 } else {
1200 ResultReceiver result = (ResultReceiver) request.argument;
1201 Bundle bundle = new Bundle();
1202 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1203 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1204 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001205 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001206 break;
1207
1208 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1209 ar = (AsyncResult) msg.obj;
1210 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001211 ResultReceiver result = (ResultReceiver) request.argument;
1212
1213 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001214 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001215 // Update the last modem activity info and the result of the request.
1216 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1217 if (isModemActivityInfoValid(info)) {
1218 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1219 int[] txTimeMs = info.getTransmitTimeMillis();
1220 int[] lastModemTxTimeMs = mLastModemActivityInfo
1221 .getTransmitTimeMillis();
1222 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1223 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1224 }
1225 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1226 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1227 + mLastModemActivityInfo.getSleepTimeMillis());
1228 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1229 + mLastModemActivityInfo.getIdleTimeMillis());
1230 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1231 mLastModemActivityInfo.setReceiveTimeMillis(
1232 info.getReceiveTimeMillis()
1233 + mLastModemActivityInfo.getReceiveTimeMillis());
1234 }
1235 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1236 mLastModemActivityInfo.getSleepTimeMillis(),
1237 mLastModemActivityInfo.getIdleTimeMillis(),
1238 mLastModemActivityInfo.getTransmitTimeMillis(),
1239 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001240 } else {
1241 if (ar.result == null) {
1242 loge("queryModemActivityInfo: Empty response");
1243 } else if (ar.exception instanceof CommandException) {
1244 loge("queryModemActivityInfo: CommandException: " +
1245 ar.exception);
1246 } else {
1247 loge("queryModemActivityInfo: Unknown exception");
1248 }
1249 }
sqian1a1be542020-03-05 11:37:28 -08001250 Bundle bundle = new Bundle();
1251 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1252 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001253 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001254 break;
1255
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 Chin49f22af2020-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 Chin49f22af2020-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 Wang6c08ecd2019-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 Wang6c08ecd2019-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 Chincc055732020-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 Wangd64acad2019-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 Chincc055732020-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 Chincc055732020-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 Wangd64acad2019-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 Chincc055732020-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 Liud0d1dc92020-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 Chincc055732020-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 zhaod698b842019-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 Nalluri8ff344d2019-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 zhaod698b842019-09-06 17:06:54 -07001665 break;
zoey chenf95ca592019-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 Nudelman24d51a52020-11-24 12:08:04 -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;
Jordan Liud5366d92020-11-24 14:50:34 -08001756
1757 case CMD_SET_SIM_POWER: {
1758 request = (MainThreadRequest) msg.obj;
1759 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1760 request = (MainThreadRequest) msg.obj;
1761 int stateToSet =
1762 ((Pair<Integer, IIntegerConsumer>)
1763 request.argument).first;
1764 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1765 break;
1766 }
1767 case EVENT_SET_SIM_POWER_DONE: {
1768 ar = (AsyncResult) msg.obj;
1769 request = (MainThreadRequest) ar.userObj;
1770 IIntegerConsumer callback =
1771 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1772 if (ar.exception != null) {
1773 loge("setSimPower exception: " + ar.exception);
1774 int errorCode = TelephonyManager.CallForwardingInfoCallback
1775 .RESULT_ERROR_UNKNOWN;
1776 if (ar.exception instanceof CommandException) {
1777 CommandException.Error error =
1778 ((CommandException) (ar.exception)).getCommandError();
1779 if (error == CommandException.Error.SIM_ERR) {
1780 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1781 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1782 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1783 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1784 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1785 } else {
1786 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1787 }
1788 }
1789 try {
1790 callback.accept(errorCode);
1791 } catch (RemoteException e) {
1792 // Ignore if the remote process is no longer available to call back.
1793 Log.w(LOG_TAG, "setSimPower: callback not available.");
1794 }
1795 } else {
1796 try {
1797 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1798 } catch (RemoteException e) {
1799 // Ignore if the remote process is no longer available to call back.
1800 Log.w(LOG_TAG, "setSimPower: callback not available.");
1801 }
1802 }
1803 break;
1804 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001805 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1806 request = (MainThreadRequest) msg.obj;
1807
1808 final Phone phone = getPhoneFromRequest(request);
1809 if (phone == null || phone.getServiceStateTracker() == null) {
1810 request.result = new IllegalStateException("Phone or SST is null");
1811 notifyRequester(request);
1812 break;
1813 }
1814
1815 Pair<Integer, SignalStrengthUpdateRequest> pair =
1816 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1817 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1818 request);
1819 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1820 request.subId, pair.first /*callingUid*/,
1821 pair.second /*request*/, onCompleted);
1822 break;
1823 }
1824 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1825 ar = (AsyncResult) msg.obj;
1826 request = (MainThreadRequest) ar.userObj;
1827 // request.result will be the exception of ar if present, true otherwise.
1828 // Be cautious not to leave result null which will wait() forever
1829 request.result = ar.exception != null ? ar.exception : true;
1830 notifyRequester(request);
1831 break;
1832 }
1833 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1834 request = (MainThreadRequest) msg.obj;
1835
1836 Phone phone = getPhoneFromRequest(request);
1837 if (phone == null || phone.getServiceStateTracker() == null) {
1838 request.result = new IllegalStateException("Phone or SST is null");
1839 notifyRequester(request);
1840 break;
1841 }
1842
1843 Pair<Integer, SignalStrengthUpdateRequest> pair =
1844 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1845 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1846 request);
1847 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1848 request.subId, pair.first /*callingUid*/,
1849 pair.second /*request*/, onCompleted);
1850 break;
1851 }
1852 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1853 ar = (AsyncResult) msg.obj;
1854 request = (MainThreadRequest) ar.userObj;
1855 request.result = ar.exception != null ? ar.exception : true;
1856 notifyRequester(request);
1857 break;
1858 }
Jordan Liud5366d92020-11-24 14:50:34 -08001859
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860 default:
1861 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1862 break;
1863 }
1864 }
Jake Hambye994d462014-02-03 13:10:13 -08001865
Pengquan Menga1bb6272018-09-06 09:59:22 -07001866 private void notifyRequester(MainThreadRequest request) {
1867 synchronized (request) {
1868 request.notifyAll();
1869 }
1870 }
1871
Jake Hambye994d462014-02-03 13:10:13 -08001872 private void handleNullReturnEvent(Message msg, String command) {
1873 AsyncResult ar = (AsyncResult) msg.obj;
1874 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1875 if (ar.exception == null) {
1876 request.result = true;
1877 } else {
1878 request.result = false;
1879 if (ar.exception instanceof CommandException) {
1880 loge(command + ": CommandException: " + ar.exception);
1881 } else {
1882 loge(command + ": Unknown exception");
1883 }
1884 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001885 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 }
1888
1889 /**
1890 * Posts the specified command to be executed on the main thread,
1891 * waits for the request to complete, and returns the result.
1892 * @see #sendRequestAsync
1893 */
1894 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001895 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1896 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001897 }
1898
1899 /**
1900 * Posts the specified command to be executed on the main thread,
1901 * waits for the request to complete, and returns the result.
1902 * @see #sendRequestAsync
1903 */
1904 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1905 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001906 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001907 }
1908
1909 /**
1910 * Posts the specified command to be executed on the main thread,
1911 * waits for the request to complete, and returns the result.
1912 * @see #sendRequestAsync
1913 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001914 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001915 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1916 }
1917
1918 /**
1919 * Posts the specified command to be executed on the main thread,
1920 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1921 * if not timeout or null otherwise.
1922 * @see #sendRequestAsync
1923 */
1924 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1925 long timeoutInMs) {
1926 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001927 }
1928
1929 /**
1930 * Posts the specified command to be executed on the main thread,
1931 * waits for the request to complete, and returns the result.
1932 * @see #sendRequestAsync
1933 */
Nathan Harold92bed182018-10-12 18:16:49 -07001934 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001935 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001936 }
1937
1938 /**
1939 * Posts the specified command to be executed on the main thread,
1940 * waits for the request to complete, and returns the result.
1941 * @see #sendRequestAsync
1942 */
1943 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001944 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1945 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001946 }
1947
1948 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08001949 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
1950 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
1951 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07001952 * @see #sendRequestAsync
1953 */
Rambo Wang0f050d82021-02-12 11:43:36 -08001954 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
1955 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1957 throw new RuntimeException("This method will deadlock if called from the main thread.");
1958 }
1959
Nathan Harold92bed182018-10-12 18:16:49 -07001960 MainThreadRequest request = null;
1961 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1962 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1963 } else if (phone != null) {
1964 request = new MainThreadRequest(argument, phone, workSource);
1965 } else {
1966 request = new MainThreadRequest(argument, subId, workSource);
1967 }
1968
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001969 Message msg = mMainThreadHandler.obtainMessage(command, request);
1970 msg.sendToTarget();
1971
Rambo Wang0f050d82021-02-12 11:43:36 -08001972
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001973 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001974 if (timeoutInMs >= 0) {
1975 // Wait for at least timeoutInMs before returning null request result
1976 long now = SystemClock.elapsedRealtime();
1977 long deadline = now + timeoutInMs;
1978 while (request == null && now < deadline) {
1979 try {
1980 request.wait(deadline - now);
1981 } catch (InterruptedException e) {
1982 // Do nothing, go back and check if request is completed or timeout
1983 } finally {
1984 now = SystemClock.elapsedRealtime();
1985 }
1986 }
1987 } else {
1988 // Wait for the request to complete
1989 while (request.result == null) {
1990 try {
1991 request.wait();
1992 } catch (InterruptedException e) {
1993 // Do nothing, go back and wait until the request is complete
1994 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995 }
1996 }
1997 }
Rambo Wang0f050d82021-02-12 11:43:36 -08001998 if (request.result == null) {
1999 Log.wtf(LOG_TAG,
2000 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2001 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002002 return request.result;
2003 }
2004
2005 /**
2006 * Asynchronous ("fire and forget") version of sendRequest():
2007 * Posts the specified command to be executed on the main thread, and
2008 * returns immediately.
2009 * @see #sendRequest
2010 */
2011 private void sendRequestAsync(int command) {
2012 mMainThreadHandler.sendEmptyMessage(command);
2013 }
2014
2015 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002016 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002017 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002018 */
2019 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002020 sendRequestAsync(command, argument, null, null);
2021 }
2022
2023 /**
2024 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2025 * @see {@link #sendRequest(int,Object)}
2026 */
2027 private void sendRequestAsync(
2028 int command, Object argument, Phone phone, WorkSource workSource) {
2029 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002030 Message msg = mMainThreadHandler.obtainMessage(command, request);
2031 msg.sendToTarget();
2032 }
2033
2034 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002035 * Initialize the singleton PhoneInterfaceManager instance.
2036 * This is only done once, at startup, from PhoneApp.onCreate().
2037 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002038 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002039 synchronized (PhoneInterfaceManager.class) {
2040 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002041 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002042 } else {
2043 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2044 }
2045 return sInstance;
2046 }
2047 }
2048
2049 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002050 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002051 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002052 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08002053 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002054 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002055 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2056 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002057 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002058 mTelephonySharedPreferences =
2059 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002060 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002061 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002062 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002063
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002064 publish();
2065 }
2066
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002067 private Phone getDefaultPhone() {
2068 Phone thePhone = getPhone(getDefaultSubscription());
2069 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2070 }
2071
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002072 private void publish() {
2073 if (DBG) log("publish: " + this);
2074
Peter Wangc035ce42020-01-08 21:00:22 -08002075 TelephonyFrameworkInitializer
2076 .getTelephonyServiceManager()
2077 .getTelephonyServiceRegisterer()
2078 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 }
2080
Stuart Scott584921c2015-01-15 17:10:34 -08002081 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002082 if (request.phone != null) {
2083 return request.phone;
2084 } else {
2085 return getPhoneFromSubId(request.subId);
2086 }
2087 }
2088
2089 private Phone getPhoneFromSubId(int subId) {
2090 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2091 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002092 }
2093
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002094 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2095 Phone phone = getPhoneFromRequest(request);
2096 return phone == null ? null :
2097 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2098 }
2099
Wink Saville36469e72014-06-11 15:17:00 -07002100 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002101 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002102 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002103 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002104
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002105 private void sendEraseModemConfig(Phone phone) {
2106 if (phone != null) {
2107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2108 mApp, phone.getSubId(), "eraseModemConfig");
2109 final long identity = Binder.clearCallingIdentity();
2110 try {
2111 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2112 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2113 } finally {
2114 Binder.restoreCallingIdentity(identity);
2115 }
2116 }
2117 }
2118
Peter Wang050bb052020-01-13 23:33:09 -08002119 private boolean isImsAvailableOnDevice() {
2120 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2121 if (pm == null) {
2122 // For some reason package manger is not available.. This will fail internally anyway,
2123 // so do not throw error and allow.
2124 return true;
2125 }
2126 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2127 }
2128
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002129 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002130 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002131 }
2132
Wink Savilleb564aae2014-10-23 10:18:09 -07002133 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002134 if (DBG) log("dial: " + number);
2135 // No permission check needed here: This is just a wrapper around the
2136 // ACTION_DIAL intent, which is available to any app since it puts up
2137 // the UI before it does anything.
2138
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002139 final long identity = Binder.clearCallingIdentity();
2140 try {
2141 String url = createTelUrl(number);
2142 if (url == null) {
2143 return;
2144 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002145
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002146 // PENDING: should we just silently fail if phone is offhook or ringing?
2147 PhoneConstants.State state = mCM.getState(subId);
2148 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2149 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2150 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2151 mApp.startActivity(intent);
2152 }
2153 } finally {
2154 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155 }
2156 }
2157
2158 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002159 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002160 }
2161
Wink Savilleb564aae2014-10-23 10:18:09 -07002162 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002163 if (DBG) log("call: " + number);
2164
2165 // This is just a wrapper around the ACTION_CALL intent, but we still
2166 // need to do a permission check since we're calling startActivity()
2167 // from the context of the phone app.
2168 enforceCallPermission();
2169
Jordan Liu1617b712019-07-10 15:06:26 -07002170 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171 != AppOpsManager.MODE_ALLOWED) {
2172 return;
2173 }
2174
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002175 final long identity = Binder.clearCallingIdentity();
2176 try {
2177 String url = createTelUrl(number);
2178 if (url == null) {
2179 return;
2180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002182 boolean isValid = false;
2183 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2184 if (slist != null) {
2185 for (SubscriptionInfo subInfoRecord : slist) {
2186 if (subInfoRecord.getSubscriptionId() == subId) {
2187 isValid = true;
2188 break;
2189 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002190 }
Wink Saville08874612014-08-31 19:19:58 -07002191 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002192 if (!isValid) {
2193 return;
2194 }
Wink Saville08874612014-08-31 19:19:58 -07002195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002196 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2197 intent.putExtra(SUBSCRIPTION_KEY, subId);
2198 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2199 mApp.startActivity(intent);
2200 } finally {
2201 Binder.restoreCallingIdentity(identity);
2202 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002203 }
2204
Wink Savilleb564aae2014-10-23 10:18:09 -07002205 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002206 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002207 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2208 }
2209
Wink Savilleb564aae2014-10-23 10:18:09 -07002210 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002211 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002212 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2213 }
2214
Wink Savilleb564aae2014-10-23 10:18:09 -07002215 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002217
2218 final long identity = Binder.clearCallingIdentity();
2219 try {
2220 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2221 checkSimPin.start();
2222 return checkSimPin.unlockSim(null, pin);
2223 } finally {
2224 Binder.restoreCallingIdentity(identity);
2225 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002226 }
2227
Wink Savilleb564aae2014-10-23 10:18:09 -07002228 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002230
2231 final long identity = Binder.clearCallingIdentity();
2232 try {
2233 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2234 checkSimPuk.start();
2235 return checkSimPuk.unlockSim(puk, pin);
2236 } finally {
2237 Binder.restoreCallingIdentity(identity);
2238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 }
2240
2241 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002242 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002243 * a synchronous one.
2244 */
2245 private static class UnlockSim extends Thread {
2246
2247 private final IccCard mSimCard;
2248
2249 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002250 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2251 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252
2253 // For replies from SimCard interface
2254 private Handler mHandler;
2255
2256 // For async handler to identify request type
2257 private static final int SUPPLY_PIN_COMPLETE = 100;
2258
2259 public UnlockSim(IccCard simCard) {
2260 mSimCard = simCard;
2261 }
2262
2263 @Override
2264 public void run() {
2265 Looper.prepare();
2266 synchronized (UnlockSim.this) {
2267 mHandler = new Handler() {
2268 @Override
2269 public void handleMessage(Message msg) {
2270 AsyncResult ar = (AsyncResult) msg.obj;
2271 switch (msg.what) {
2272 case SUPPLY_PIN_COMPLETE:
2273 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2274 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002275 mRetryCount = msg.arg1;
2276 if (ar.exception != null) {
2277 if (ar.exception instanceof CommandException &&
2278 ((CommandException)(ar.exception)).getCommandError()
2279 == CommandException.Error.PASSWORD_INCORRECT) {
2280 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002281 } //When UiccCardApp dispose,handle message and return exception
2282 else if (ar.exception instanceof CommandException &&
2283 ((CommandException) (ar.exception)).getCommandError()
2284 == CommandException.Error.ABORTED) {
2285 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002286 } else {
2287 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2288 }
2289 } else {
2290 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 mDone = true;
2293 UnlockSim.this.notifyAll();
2294 }
2295 break;
2296 }
2297 }
2298 };
2299 UnlockSim.this.notifyAll();
2300 }
2301 Looper.loop();
2302 }
2303
2304 /*
2305 * Use PIN or PUK to unlock SIM card
2306 *
2307 * If PUK is null, unlock SIM card with PIN
2308 *
2309 * If PUK is not null, unlock SIM card with PUK and set PIN code
2310 */
Wink Saville9de0f752013-10-22 19:04:03 -07002311 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312
2313 while (mHandler == null) {
2314 try {
2315 wait();
2316 } catch (InterruptedException e) {
2317 Thread.currentThread().interrupt();
2318 }
2319 }
2320 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2321
2322 if (puk == null) {
2323 mSimCard.supplyPin(pin, callback);
2324 } else {
2325 mSimCard.supplyPuk(puk, pin, callback);
2326 }
2327
2328 while (!mDone) {
2329 try {
2330 Log.d(LOG_TAG, "wait for done");
2331 wait();
2332 } catch (InterruptedException e) {
2333 // Restore the interrupted status
2334 Thread.currentThread().interrupt();
2335 }
2336 }
2337 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002338 int[] resultArray = new int[2];
2339 resultArray[0] = mResult;
2340 resultArray[1] = mRetryCount;
2341 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 }
2343 }
2344
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002345 /**
2346 * This method has been removed due to privacy and stability concerns.
2347 */
2348 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002349 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002350 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2351 return;
Wink Saville36469e72014-06-11 15:17:00 -07002352 }
2353
Nathan Harold1f889d82020-06-04 17:05:26 -07002354 @Override
2355 public void updateServiceLocationWithPackageName(String callingPackage) {
2356 mApp.getSystemService(AppOpsManager.class)
2357 .checkPackage(Binder.getCallingUid(), callingPackage);
2358
Nathan Haroldf096d982020-11-18 17:18:06 -08002359 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002360 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2361 // Callers targeting S have no business invoking this method.
2362 return;
2363 }
2364
2365 LocationAccessPolicy.LocationPermissionResult locationResult =
2366 LocationAccessPolicy.checkLocationPermission(mApp,
2367 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2368 .setCallingPackage(callingPackage)
2369 .setCallingFeatureId(null)
2370 .setCallingPid(Binder.getCallingPid())
2371 .setCallingUid(Binder.getCallingUid())
2372 .setMethod("updateServiceLocation")
2373 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2374 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2375 .build());
2376 // Apps that lack location permission have no business calling this method;
2377 // however, because no permission was declared in the public API, denials must
2378 // all be "soft".
2379 switch (locationResult) {
2380 case DENIED_HARD: /* fall through */
2381 case DENIED_SOFT:
2382 return;
2383 }
2384
2385 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002386 final long identity = Binder.clearCallingIdentity();
2387 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002388 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002389 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002390 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002391 }
2392 } finally {
2393 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002394 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 }
2396
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002397 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002398 @Override
2399 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002400 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002401 }
2402
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002403
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002404 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002405 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2406 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2407 callingFeatureId);
2408 }
2409
2410 @Deprecated
2411 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002412 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002413 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2414 }
2415
2416 @Override
2417 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2418 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002419 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002420 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002421 return false;
2422 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002423
2424 final long identity = Binder.clearCallingIdentity();
2425 try {
2426 return isRadioOnForSubscriber(subId);
2427 } finally {
2428 Binder.restoreCallingIdentity(identity);
2429 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002430 }
2431
2432 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002433 final long identity = Binder.clearCallingIdentity();
2434 try {
2435 final Phone phone = getPhone(subId);
2436 if (phone != null) {
2437 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2438 } else {
2439 return false;
2440 }
2441 } finally {
2442 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002443 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 }
2445
2446 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002447 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 }
Wink Saville36469e72014-06-11 15:17:00 -07002449
Wink Savilleb564aae2014-10-23 10:18:09 -07002450 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002452
2453 final long identity = Binder.clearCallingIdentity();
2454 try {
2455 final Phone phone = getPhone(subId);
2456 if (phone != null) {
2457 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2458 }
2459 } finally {
2460 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002461 }
Wink Saville36469e72014-06-11 15:17:00 -07002462 }
2463
2464 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002465 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002466 }
2467
Wink Savilleb564aae2014-10-23 10:18:09 -07002468 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002469 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002470
2471 final long identity = Binder.clearCallingIdentity();
2472 try {
2473 final Phone phone = getPhone(subId);
2474 if (phone == null) {
2475 return false;
2476 }
2477 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2478 toggleRadioOnOffForSubscriber(subId);
2479 }
2480 return true;
2481 } finally {
2482 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002484 }
Wink Saville36469e72014-06-11 15:17:00 -07002485
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002486 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002487 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002488 /*
2489 * If any of the Radios are available, it will need to be
2490 * shutdown. So return true if any Radio is available.
2491 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002492 final long identity = Binder.clearCallingIdentity();
2493 try {
2494 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2495 Phone phone = PhoneFactory.getPhone(i);
2496 if (phone != null && phone.isRadioAvailable()) return true;
2497 }
2498 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2499 return false;
2500 } finally {
2501 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002502 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002503 }
2504
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002506 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507 enforceModifyPermission();
2508
2509 final long identity = Binder.clearCallingIdentity();
2510 try {
2511 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2512 logv("Shutting down Phone " + i);
2513 shutdownRadioUsingPhoneId(i);
2514 }
2515 } finally {
2516 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002517 }
2518 }
2519
2520 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002521 Phone phone = PhoneFactory.getPhone(phoneId);
2522 if (phone != null && phone.isRadioAvailable()) {
2523 phone.shutdownRadio();
2524 }
2525 }
2526
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002527 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002528 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002529
2530 final long identity = Binder.clearCallingIdentity();
2531 try {
2532 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2533 if (defaultPhone != null) {
2534 defaultPhone.setRadioPower(turnOn);
2535 return true;
2536 } else {
2537 loge("There's no default phone.");
2538 return false;
2539 }
2540 } finally {
2541 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002542 }
Wink Saville36469e72014-06-11 15:17:00 -07002543 }
2544
Wink Savilleb564aae2014-10-23 10:18:09 -07002545 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002546 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002547
2548 final long identity = Binder.clearCallingIdentity();
2549 try {
2550 final Phone phone = getPhone(subId);
2551 if (phone != null) {
2552 phone.setRadioPower(turnOn);
2553 return true;
2554 } else {
2555 return false;
2556 }
2557 } finally {
2558 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002559 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002560 }
2561
Wink Saville36469e72014-06-11 15:17:00 -07002562 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002563 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 public boolean enableDataConnectivity() {
2565 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002566
2567 final long identity = Binder.clearCallingIdentity();
2568 try {
2569 int subId = mSubscriptionController.getDefaultDataSubId();
2570 final Phone phone = getPhone(subId);
2571 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002572 phone.getDataEnabledSettings().setDataEnabled(
2573 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002574 return true;
2575 } else {
2576 return false;
2577 }
2578 } finally {
2579 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 }
2582
Wink Saville36469e72014-06-11 15:17:00 -07002583 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002584 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002585 public boolean disableDataConnectivity() {
2586 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002587
2588 final long identity = Binder.clearCallingIdentity();
2589 try {
2590 int subId = mSubscriptionController.getDefaultDataSubId();
2591 final Phone phone = getPhone(subId);
2592 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002593 phone.getDataEnabledSettings().setDataEnabled(
2594 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595 return true;
2596 } else {
2597 return false;
2598 }
2599 } finally {
2600 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002601 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602 }
2603
Sanket Padawe356d7632015-06-22 14:03:32 -07002604 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002605 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002606 final long identity = Binder.clearCallingIdentity();
2607 try {
2608 final Phone phone = getPhone(subId);
2609 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002610 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002611 } else {
2612 return false;
2613 }
2614 } finally {
2615 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002616 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002617 }
2618
2619 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002620 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002621 }
2622
pkanwarae03a6b2016-11-06 20:37:09 -08002623 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002624 enforceCallPermission();
2625
2626 final long identity = Binder.clearCallingIdentity();
2627 try {
2628 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2629 return;
2630 }
2631 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2632 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2633 } finally {
2634 Binder.restoreCallingIdentity(identity);
2635 }
pkanwar32d516d2016-10-14 19:37:38 -07002636 };
2637
Wink Savilleb564aae2014-10-23 10:18:09 -07002638 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002639 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640
2641 final long identity = Binder.clearCallingIdentity();
2642 try {
2643 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2644 return false;
2645 }
2646 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2647 } finally {
2648 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002649 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002650 }
2651
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002652 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002653 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002654 }
2655
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002656 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657 final long identity = Binder.clearCallingIdentity();
2658 try {
2659 Phone phone = PhoneFactory.getPhone(slotIndex);
2660 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2661 PhoneConstantConversions.convertCallState(phone.getState());
2662 } finally {
2663 Binder.restoreCallingIdentity(identity);
2664 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 }
2666
Sanket Padawe356d7632015-06-22 14:03:32 -07002667 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002668 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002669 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2670 }
2671
2672 @Override
2673 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002674 final long identity = Binder.clearCallingIdentity();
2675 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002676 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002677 if (phone != null) {
2678 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2679 } else {
2680 return PhoneConstantConversions.convertDataState(
2681 PhoneConstants.DataState.DISCONNECTED);
2682 }
2683 } finally {
2684 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002685 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002686 }
2687
Sanket Padawe356d7632015-06-22 14:03:32 -07002688 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002689 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002690 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2691 }
2692
2693 @Override
2694 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002695 final long identity = Binder.clearCallingIdentity();
2696 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002697 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002698 if (phone != null) {
2699 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2700 } else {
2701 return TelephonyManager.DATA_ACTIVITY_NONE;
2702 }
2703 } finally {
2704 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002706 }
2707
2708 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002709 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002710 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002711 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002712
2713 LocationAccessPolicy.LocationPermissionResult locationResult =
2714 LocationAccessPolicy.checkLocationPermission(mApp,
2715 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2716 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002717 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002718 .setCallingPid(Binder.getCallingPid())
2719 .setCallingUid(Binder.getCallingUid())
2720 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002721 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002722 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2723 .build());
2724 switch (locationResult) {
2725 case DENIED_HARD:
2726 throw new SecurityException("Not allowed to access cell location");
2727 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002728 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2729 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730 }
2731
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002732 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002733 final long identity = Binder.clearCallingIdentity();
2734 try {
2735 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002736 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002737 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738 } finally {
2739 Binder.restoreCallingIdentity(identity);
2740 }
Svetoslav64fad262015-04-14 14:35:21 -07002741 }
2742
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002743 @Override
Jack Yu01425032020-02-22 19:38:58 -08002744 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002745 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2746 // registered cell info, so return a NULL country instead.
2747 final long identity = Binder.clearCallingIdentity();
2748 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002749 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2750 // Get default phone in this case.
2751 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2752 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002753 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002754 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002755 if (phone == null) return "";
2756 ServiceStateTracker sst = phone.getServiceStateTracker();
2757 if (sst == null) return "";
2758 LocaleTracker lt = sst.getLocaleTracker();
2759 if (lt == null) return "";
2760 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2761 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2762 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002763 } finally {
2764 Binder.restoreCallingIdentity(identity);
2765 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002766 }
2767
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002768 /**
2769 * This method was removed due to potential issues caused by performing partial
2770 * updates of service state, and lack of a credible use case.
2771 *
2772 * This has the ability to break the telephony implementation by disabling notification of
2773 * changes in device connectivity. DO NOT USE THIS!
2774 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002775 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 public void enableLocationUpdates() {
2777 mApp.enforceCallingOrSelfPermission(
2778 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 }
2780
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002781 /**
2782 * This method was removed due to potential issues caused by performing partial
2783 * updates of service state, and lack of a credible use case.
2784 *
2785 * This has the ability to break the telephony implementation by disabling notification of
2786 * changes in device connectivity. DO NOT USE THIS!
2787 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002788 @Override
2789 public void disableLocationUpdates() {
2790 mApp.enforceCallingOrSelfPermission(
2791 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 }
2793
2794 @Override
2795 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002796 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2797 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002798 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002799 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2800 throw new SecurityException(
2801 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2802 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002803
Jordan Liu1617b712019-07-10 15:06:26 -07002804 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002805 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2806 return null;
2807 }
Svetoslav64fad262015-04-14 14:35:21 -07002808
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002809 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002810
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002811 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002812 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002813
Nathan Haroldf180aac2018-06-01 18:43:55 -07002814 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2815 for (CellInfo ci : info) {
2816 if (ci instanceof CellInfoGsm) {
2817 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2818 } else if (ci instanceof CellInfoWcdma) {
2819 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2820 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002821 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002822 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002823 }
2824
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002825 private List<CellInfo> getCachedCellInfo() {
2826 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2827 for (Phone phone : PhoneFactory.getPhones()) {
2828 List<CellInfo> info = phone.getAllCellInfo();
2829 if (info != null) cellInfos.addAll(info);
2830 }
2831 return cellInfos;
2832 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002833
2834 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002835 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002836 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002837 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002838
2839 LocationAccessPolicy.LocationPermissionResult locationResult =
2840 LocationAccessPolicy.checkLocationPermission(mApp,
2841 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2842 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002843 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002844 .setCallingPid(Binder.getCallingPid())
2845 .setCallingUid(Binder.getCallingUid())
2846 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002847 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002848 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2849 .build());
2850 switch (locationResult) {
2851 case DENIED_HARD:
2852 throw new SecurityException("Not allowed to access cell info");
2853 case DENIED_SOFT:
2854 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002855 }
2856
Nathan Haroldf096d982020-11-18 17:18:06 -08002857 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002858 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2859 return getCachedCellInfo();
2860 }
2861
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002862 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002863 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2867 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002868 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002869 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002870 if (info != null) cellInfos.addAll(info);
2871 }
2872 return cellInfos;
2873 } finally {
2874 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002875 }
2876 }
2877
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002878 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002879 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2880 String callingFeatureId) {
2881 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2882 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002883 }
2884
2885 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002886 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2887 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002888 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002889 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002890 }
2891
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002892 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2893 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002894 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002895 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002896
2897 LocationAccessPolicy.LocationPermissionResult locationResult =
2898 LocationAccessPolicy.checkLocationPermission(mApp,
2899 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2900 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002901 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002902 .setCallingPid(Binder.getCallingPid())
2903 .setCallingUid(Binder.getCallingUid())
2904 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002905 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2906 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002907 .build());
2908 switch (locationResult) {
2909 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002910 if (TelephonyPermissions
2911 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002912 // Safetynet logging for b/154934934
2913 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2914 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002915 throw new SecurityException("Not allowed to access cell info");
2916 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002917 if (TelephonyPermissions
2918 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002919 // Safetynet logging for b/154934934
2920 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2921 }
Nathan Harold5320c422019-05-09 10:26:08 -07002922 try {
2923 cb.onCellInfo(new ArrayList<CellInfo>());
2924 } catch (RemoteException re) {
2925 // Drop without consequences
2926 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002927 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002928 }
2929
Nathan Harolda939a962019-05-09 10:13:47 -07002930
2931 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002932 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2933
2934 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2935 }
2936
2937 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002938 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002939 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002940 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941
2942 final long identity = Binder.clearCallingIdentity();
2943 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002944 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002945 } finally {
2946 Binder.restoreCallingIdentity(identity);
2947 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002948 }
2949
Shishir Agrawala9f32182016-04-12 12:00:16 -07002950 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002951 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002952 Phone phone = PhoneFactory.getPhone(slotIndex);
2953 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002954 return null;
2955 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002956 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002957 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002958 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002959 return null;
2960 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002961
2962 final long identity = Binder.clearCallingIdentity();
2963 try {
2964 return phone.getImei();
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
2967 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002968 }
2969
2970 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002971 public String getTypeAllocationCodeForSlot(int slotIndex) {
2972 Phone phone = PhoneFactory.getPhone(slotIndex);
2973 String tac = null;
2974 if (phone != null) {
2975 String imei = phone.getImei();
2976 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2977 }
2978 return tac;
2979 }
2980
2981 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002982 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002983 Phone phone = PhoneFactory.getPhone(slotIndex);
2984 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002985 return null;
2986 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002987
Jeff Davidson913390f2018-02-23 17:11:49 -08002988 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002989 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002990 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002991 return null;
2992 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002993
2994 final long identity = Binder.clearCallingIdentity();
2995 try {
2996 return phone.getMeid();
2997 } finally {
2998 Binder.restoreCallingIdentity(identity);
2999 }
Jack Yu2af8d712017-03-15 17:14:14 -07003000 }
3001
3002 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003003 public String getManufacturerCodeForSlot(int slotIndex) {
3004 Phone phone = PhoneFactory.getPhone(slotIndex);
3005 String manufacturerCode = null;
3006 if (phone != null) {
3007 String meid = phone.getMeid();
3008 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3009 }
3010 return manufacturerCode;
3011 }
3012
3013 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003014 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3015 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003016 Phone phone = PhoneFactory.getPhone(slotIndex);
3017 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003018 return null;
3019 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003020 int subId = phone.getSubId();
3021 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003022 mApp, subId, callingPackage, callingFeatureId,
3023 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003024 return null;
3025 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026
3027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 return phone.getDeviceSvn();
3030 } finally {
3031 Binder.restoreCallingIdentity(identity);
3032 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003033 }
3034
fionaxu43304da2017-11-27 22:51:16 -08003035 @Override
3036 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003037 final long identity = Binder.clearCallingIdentity();
3038 try {
3039 final Phone phone = getPhone(subId);
3040 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
fionaxu43304da2017-11-27 22:51:16 -08003044 }
3045
3046 @Override
3047 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048 final long identity = Binder.clearCallingIdentity();
3049 try {
3050 final Phone phone = getPhone(subId);
3051 return phone == null ? null : phone.getCarrierName();
3052 } finally {
3053 Binder.restoreCallingIdentity(identity);
3054 }
fionaxu43304da2017-11-27 22:51:16 -08003055 }
3056
calvinpanffe225e2018-11-01 19:43:06 +08003057 @Override
chen xu0026ca62019-03-06 15:28:50 -08003058 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003059 final long identity = Binder.clearCallingIdentity();
3060 try {
3061 final Phone phone = getPhone(subId);
3062 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003063 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003064 } finally {
3065 Binder.restoreCallingIdentity(identity);
3066 }
3067 }
3068
3069 @Override
chen xu0026ca62019-03-06 15:28:50 -08003070 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003074 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003075 } finally {
3076 Binder.restoreCallingIdentity(identity);
3077 }
3078 }
3079
chen xu651eec72018-11-11 19:03:44 -08003080 @Override
chen xu864e11c2018-12-06 22:10:03 -08003081 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3082 if (!isSubscriptionMccMnc) {
3083 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3084 }
chen xu651eec72018-11-11 19:03:44 -08003085 final Phone phone = PhoneFactory.getPhone(slotIndex);
3086 if (phone == null) {
3087 return TelephonyManager.UNKNOWN_CARRIER_ID;
3088 }
3089 final long identity = Binder.clearCallingIdentity();
3090 try {
3091 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
3095 }
3096
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003097 //
3098 // Internal helper methods.
3099 //
3100
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003101 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003102 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3103 *
3104 * @throws SecurityException if the caller does not have the required permission
3105 */
3106 private void enforceModifyPermission() {
3107 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3108 }
3109
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003110 /**
3111 * Make sure the caller is system.
3112 *
3113 * @throws SecurityException if the caller is not system.
3114 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003115 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003116 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3117 throw new SecurityException("Caller must be system");
3118 }
3119 }
3120
Shuo Qianf2b2df42019-11-13 17:43:31 -08003121 private void enforceActiveEmergencySessionPermission() {
3122 mApp.enforceCallingOrSelfPermission(
3123 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3124 }
3125
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003126 /**
3127 * Make sure the caller has the CALL_PHONE permission.
3128 *
3129 * @throws SecurityException if the caller does not have the required permission
3130 */
3131 private void enforceCallPermission() {
3132 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3133 }
3134
paulhu423b5f22019-08-23 19:17:33 +08003135 private void enforceSettingsPermission() {
3136 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003137 }
3138
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003139 private String createTelUrl(String number) {
3140 if (TextUtils.isEmpty(number)) {
3141 return null;
3142 }
3143
Jake Hambye994d462014-02-03 13:10:13 -08003144 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003145 }
3146
Ihab Awadf9e92732013-12-05 18:02:52 -08003147 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003148 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3149 }
3150
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003151 private static void logv(String msg) {
3152 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3153 }
3154
Ihab Awadf9e92732013-12-05 18:02:52 -08003155 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003156 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3157 }
3158
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003159 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003160 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003161 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003162 }
3163
Sanket Padawe356d7632015-06-22 14:03:32 -07003164 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003165 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003166 final long identity = Binder.clearCallingIdentity();
3167 try {
3168 final Phone phone = PhoneFactory.getPhone(slotIndex);
3169 if (phone == null) {
3170 return PhoneConstants.PHONE_TYPE_NONE;
3171 } else {
3172 return phone.getPhoneType();
3173 }
3174 } finally {
3175 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003176 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003177 }
3178
3179 /**
3180 * Returns the CDMA ERI icon index to display
3181 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003182 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003183 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3184 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3185 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003186 }
3187
Sanket Padawe356d7632015-06-22 14:03:32 -07003188 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003189 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3190 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003191 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003192 mApp, subId, callingPackage, callingFeatureId,
3193 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003194 return -1;
3195 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003196
3197 final long identity = Binder.clearCallingIdentity();
3198 try {
3199 final Phone phone = getPhone(subId);
3200 if (phone != null) {
3201 return phone.getCdmaEriIconIndex();
3202 } else {
3203 return -1;
3204 }
3205 } finally {
3206 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003207 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003208 }
3209
3210 /**
3211 * Returns the CDMA ERI icon mode,
3212 * 0 - ON
3213 * 1 - FLASHING
3214 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003215 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003216 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3217 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3218 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003219 }
3220
Sanket Padawe356d7632015-06-22 14:03:32 -07003221 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003222 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3223 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003224 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003225 mApp, subId, callingPackage, callingFeatureId,
3226 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003227 return -1;
3228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003229
3230 final long identity = Binder.clearCallingIdentity();
3231 try {
3232 final Phone phone = getPhone(subId);
3233 if (phone != null) {
3234 return phone.getCdmaEriIconMode();
3235 } else {
3236 return -1;
3237 }
3238 } finally {
3239 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003240 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003241 }
3242
3243 /**
3244 * Returns the CDMA ERI text,
3245 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003246 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003247 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3248 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3249 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003250 }
3251
Sanket Padawe356d7632015-06-22 14:03:32 -07003252 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003253 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3254 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003255 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003256 mApp, subId, callingPackage, callingFeatureId,
3257 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003258 return null;
3259 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003260
3261 final long identity = Binder.clearCallingIdentity();
3262 try {
3263 final Phone phone = getPhone(subId);
3264 if (phone != null) {
3265 return phone.getCdmaEriText();
3266 } else {
3267 return null;
3268 }
3269 } finally {
3270 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003271 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003272 }
3273
3274 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003275 * Returns the CDMA MDN.
3276 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003277 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003278 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003279 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3280 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003281
3282 final long identity = Binder.clearCallingIdentity();
3283 try {
3284 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003285 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003286 return phone.getLine1Number();
3287 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003288 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003289 return null;
3290 }
3291 } finally {
3292 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003293 }
3294 }
3295
3296 /**
3297 * Returns the CDMA MIN.
3298 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003299 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003300 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003301 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3302 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003303
3304 final long identity = Binder.clearCallingIdentity();
3305 try {
3306 final Phone phone = getPhone(subId);
3307 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3308 return phone.getCdmaMin();
3309 } else {
3310 return null;
3311 }
3312 } finally {
3313 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003314 }
3315 }
3316
Hall Liud892bec2018-11-30 14:51:45 -08003317 @Override
3318 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3319 INumberVerificationCallback callback, String callingPackage) {
3320 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3321 != PERMISSION_GRANTED) {
3322 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3323 }
3324 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3325
3326 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3327 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003328 throw new SecurityException("Calling package must be configured in the device config: "
3329 + "calling package: " + callingPackage
3330 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003331 }
3332
3333 if (range == null) {
3334 throw new NullPointerException("Range must be non-null");
3335 }
3336
3337 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003338 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003339
3340 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3341 }
3342
Junda Liuca05d5d2014-08-14 22:36:34 -07003343 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003344 * Returns true if CDMA provisioning needs to run.
3345 */
3346 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347 final long identity = Binder.clearCallingIdentity();
3348 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003349 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003350 } finally {
3351 Binder.restoreCallingIdentity(identity);
3352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003353 }
3354
3355 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003356 * Sets the voice mail number of a given subId.
3357 */
3358 @Override
3359 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003360 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3361 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003362
3363 final long identity = Binder.clearCallingIdentity();
3364 try {
3365 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3366 new Pair<String, String>(alphaTag, number), new Integer(subId));
3367 return success;
3368 } finally {
3369 Binder.restoreCallingIdentity(identity);
3370 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003371 }
3372
Ta-wei Yen87c49842016-05-13 21:19:52 -07003373 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003374 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3375 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003376 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3377 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003378 if (!TextUtils.equals(callingPackage, systemDialer)) {
3379 throw new SecurityException("caller must be system dialer");
3380 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003381
3382 final long identity = Binder.clearCallingIdentity();
3383 try {
3384 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3385 if (phoneAccountHandle == null) {
3386 return null;
3387 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003388 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003389 } finally {
3390 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003391 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003392 }
3393
3394 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003395 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3396 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003397 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003398 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003399 mApp, subId, callingPackage, callingFeatureId,
3400 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003401 return null;
3402 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003403
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003404 final long identity = Binder.clearCallingIdentity();
3405 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003406 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003407 } finally {
3408 Binder.restoreCallingIdentity(identity);
3409 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003410 }
3411
3412 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003413 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3414 VisualVoicemailSmsFilterSettings settings) {
3415 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003416
3417 final long identity = Binder.clearCallingIdentity();
3418 try {
3419 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003420 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003421 } finally {
3422 Binder.restoreCallingIdentity(identity);
3423 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003424 }
3425
3426 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003427 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3428 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429
3430 final long identity = Binder.clearCallingIdentity();
3431 try {
3432 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003433 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003434 } finally {
3435 Binder.restoreCallingIdentity(identity);
3436 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003437 }
3438
3439 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003440 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3441 String callingPackage, int subId) {
3442 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003443
3444 final long identity = Binder.clearCallingIdentity();
3445 try {
3446 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003447 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003448 } finally {
3449 Binder.restoreCallingIdentity(identity);
3450 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003451 }
3452
3453 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003454 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003455 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003456
3457 final long identity = Binder.clearCallingIdentity();
3458 try {
3459 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003460 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003461 } finally {
3462 Binder.restoreCallingIdentity(identity);
3463 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003464 }
3465
3466 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003467 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3468 String callingAttributionTag, int subId, String number, int port, String text,
3469 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003470 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003471 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003472 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003473 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003474 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3475 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003476 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003477
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003478 /**
fionaxu0152e512016-11-14 13:36:14 -08003479 * Sets the voice activation state of a given subId.
3480 */
3481 @Override
3482 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003483 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3484 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003485
3486 final long identity = Binder.clearCallingIdentity();
3487 try {
3488 final Phone phone = getPhone(subId);
3489 if (phone != null) {
3490 phone.setVoiceActivationState(activationState);
3491 } else {
3492 loge("setVoiceActivationState fails with invalid subId: " + subId);
3493 }
3494 } finally {
3495 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003496 }
3497 }
3498
3499 /**
3500 * Sets the data activation state of a given subId.
3501 */
3502 @Override
3503 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003504 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3505 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003506
3507 final long identity = Binder.clearCallingIdentity();
3508 try {
3509 final Phone phone = getPhone(subId);
3510 if (phone != null) {
3511 phone.setDataActivationState(activationState);
3512 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003513 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003514 }
3515 } finally {
3516 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003517 }
3518 }
3519
3520 /**
3521 * Returns the voice activation state of a given subId.
3522 */
3523 @Override
3524 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003525 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003526
fionaxu0152e512016-11-14 13:36:14 -08003527 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003528 final long identity = Binder.clearCallingIdentity();
3529 try {
3530 if (phone != null) {
3531 return phone.getVoiceActivationState();
3532 } else {
3533 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3534 }
3535 } finally {
3536 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003537 }
3538 }
3539
3540 /**
3541 * Returns the data activation state of a given subId.
3542 */
3543 @Override
3544 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003545 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003546
fionaxu0152e512016-11-14 13:36:14 -08003547 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 if (phone != null) {
3551 return phone.getDataActivationState();
3552 } else {
3553 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3554 }
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003557 }
3558 }
3559
3560 /**
Wink Saville36469e72014-06-11 15:17:00 -07003561 * Returns the unread count of voicemails for a subId
3562 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003563 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003564 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3565 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003566 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003567 mApp, subId, callingPackage, callingFeatureId,
3568 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003569 return 0;
3570 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003571 final long identity = Binder.clearCallingIdentity();
3572 try {
3573 final Phone phone = getPhone(subId);
3574 if (phone != null) {
3575 return phone.getVoiceMessageCount();
3576 } else {
3577 return 0;
3578 }
3579 } finally {
3580 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003582 }
3583
3584 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003585 * returns true, if the device is in a state where both voice and data
3586 * are supported simultaneously. This can change based on location or network condition.
3587 */
3588 @Override
3589 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003590 final long identity = Binder.clearCallingIdentity();
3591 try {
3592 final Phone phone = getPhone(subId);
3593 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3594 } finally {
3595 Binder.restoreCallingIdentity(identity);
3596 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003597 }
3598
3599 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003600 * Send the dialer code if called from the current default dialer or the caller has
3601 * carrier privilege.
3602 * @param inputCode The dialer code to send
3603 */
3604 @Override
3605 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003606 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003607 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003608 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3609 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003610 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003611 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003612 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003613 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003614
3615 final long identity = Binder.clearCallingIdentity();
3616 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003617 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003618 } finally {
3619 Binder.restoreCallingIdentity(identity);
3620 }
fionaxu235cc5e2017-03-06 22:25:57 -08003621 }
3622
Pengquan Menga1bb6272018-09-06 09:59:22 -07003623 @Override
3624 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003625 TelephonyPermissions
3626 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3627 mApp, subId, "getNetworkSelectionMode");
3628 final long identity = Binder.clearCallingIdentity();
3629 try {
3630 if (!isActiveSubscription(subId)) {
3631 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3632 }
3633 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3634 } finally {
3635 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003636 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003637 }
3638
Brad Ebinger35c841c2018-10-01 10:40:55 -07003639 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003640 public boolean isInEmergencySmsMode() {
3641 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3642 final long identity = Binder.clearCallingIdentity();
3643 try {
3644 for (Phone phone : PhoneFactory.getPhones()) {
3645 if (phone.isInEmergencySmsMode()) {
3646 return true;
3647 }
3648 }
3649 } finally {
3650 Binder.restoreCallingIdentity(identity);
3651 }
3652 return false;
3653 }
3654
shilu366312e2019-12-17 09:28:10 -08003655 /**
3656 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3657 * @param subId The subscription to use to check the configuration.
3658 * @param c The callback that will be used to send the result.
3659 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003660 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003661 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3662 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003663 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3664 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003665
Brad Ebinger77b832e2019-10-17 17:03:22 -07003666 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3667 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3668 "IMS not available on device.");
3669 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003670 final long token = Binder.clearCallingIdentity();
3671 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003672 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003673 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003674 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003675 } catch (ImsException e) {
3676 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003677 } finally {
3678 Binder.restoreCallingIdentity(token);
3679 }
3680 }
3681
shilu366312e2019-12-17 09:28:10 -08003682 /**
3683 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3684 * @param subId The subscription to use to check the configuration.
3685 * @param c The callback that will be used to send the result.
3686 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003687 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003688 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003689 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3690 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003691 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3692 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3693 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003694 final long token = Binder.clearCallingIdentity();
3695 try {
3696 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3697 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3698 .removeRegistrationCallbackForSubscription(c, subId);
3699 } catch (ImsException e) {
3700 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3701 + "is inactive, ignoring unregister.");
3702 // If the subscription is no longer active, just return, since the callback
3703 // will already have been removed internally.
3704 } finally {
3705 Binder.restoreCallingIdentity(token);
3706 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003707 }
3708
Brad Ebinger774ba362019-10-22 17:36:18 -07003709 /**
3710 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3711 */
3712 @Override
3713 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3714 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3715 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3716 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3717 "IMS not available on device.");
3718 }
3719 final long token = Binder.clearCallingIdentity();
3720 try {
3721 Phone phone = getPhone(subId);
3722 if (phone == null) {
3723 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3724 + subId + "'");
3725 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3726 }
3727 phone.getImsRegistrationState(regState -> {
3728 try {
3729 consumer.accept((regState == null)
3730 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3731 } catch (RemoteException e) {
3732 // Ignore if the remote process is no longer available to call back.
3733 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3734 }
3735 });
3736 } finally {
3737 Binder.restoreCallingIdentity(token);
3738 }
3739 }
3740
3741 /**
3742 * Get the transport type for the IMS service registration state.
3743 */
3744 @Override
3745 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003746 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3747 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003748 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3749 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3750 "IMS not available on device.");
3751 }
3752 final long token = Binder.clearCallingIdentity();
3753 try {
3754 Phone phone = getPhone(subId);
3755 if (phone == null) {
3756 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3757 + subId + "'");
3758 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3759 }
3760 phone.getImsRegistrationTech(regTech -> {
3761 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3762 int regTechConverted = (regTech == null)
3763 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3764 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3765 regTechConverted);
3766 try {
3767 consumer.accept(regTechConverted);
3768 } catch (RemoteException e) {
3769 // Ignore if the remote process is no longer available to call back.
3770 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3771 }
3772 });
3773 } finally {
3774 Binder.restoreCallingIdentity(token);
3775 }
3776 }
3777
shilu366312e2019-12-17 09:28:10 -08003778 /**
3779 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3780 * @param subId The subscription to use to check the configuration.
3781 * @param c The callback that will be used to send the result.
3782 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003783 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003784 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3785 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003786 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3787 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003788 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3789 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3790 "IMS not available on device.");
3791 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003792 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3793 final long token = Binder.clearCallingIdentity();
3794 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003795 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003796 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003797 } catch (ImsException e) {
3798 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003799 } finally {
3800 Binder.restoreCallingIdentity(token);
3801 }
3802 }
3803
shilu366312e2019-12-17 09:28:10 -08003804 /**
3805 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3806 * @param subId The subscription to use to check the configuration.
3807 * @param c The callback that will be used to send the result.
3808 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003809 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003810 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003811 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3812 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003813 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3814 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3815 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003816
3817 final long token = Binder.clearCallingIdentity();
3818 try {
3819 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3820 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003821 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003822 } catch (ImsException e) {
3823 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3824 + "is inactive, ignoring unregister.");
3825 // If the subscription is no longer active, just return, since the callback
3826 // will already have been removed internally.
3827 } finally {
3828 Binder.restoreCallingIdentity(token);
3829 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003830 }
3831
3832 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003833 public boolean isCapable(int subId, int capability, int regTech) {
3834 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003835 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3836 final long token = Binder.clearCallingIdentity();
3837 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003838 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003839 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003840 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003841 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3842 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003843 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003844 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3845 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003846 } finally {
3847 Binder.restoreCallingIdentity(token);
3848 }
3849 }
3850
3851 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003852 public boolean isAvailable(int subId, int capability, int regTech) {
3853 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003854 final long token = Binder.clearCallingIdentity();
3855 try {
3856 Phone phone = getPhone(subId);
3857 if (phone == null) return false;
3858 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003859 } catch (com.android.ims.ImsException e) {
3860 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3861 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003862 } finally {
3863 Binder.restoreCallingIdentity(token);
3864 }
3865 }
3866
Brad Ebinger77b832e2019-10-17 17:03:22 -07003867 /**
3868 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3869 * subscription.
3870 * @param subId The subscription to use to check the configuration.
3871 * @param callback The callback that will be used to send the result.
3872 * @param capability The MmTelFeature capability that will be used to send the result.
3873 * @param transportType The transport type of the MmTelFeature capability.
3874 */
3875 @Override
3876 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3877 int transportType) {
3878 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3879 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3880 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3881 "IMS not available on device.");
3882 }
3883 final long token = Binder.clearCallingIdentity();
3884 try {
3885 int slotId = getSlotIndex(subId);
3886 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3887 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3888 + subId + "'");
3889 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3890 }
3891 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3892 transportType, aBoolean -> {
3893 try {
3894 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3895 } catch (RemoteException e) {
3896 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3897 + "running. Ignore");
3898 }
3899 });
3900 } finally {
3901 Binder.restoreCallingIdentity(token);
3902 }
3903 }
3904
shilu366312e2019-12-17 09:28:10 -08003905 /**
3906 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3907 * @param subId The subscription to use to check the configuration.
3908 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003909 @Override
3910 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003911 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3912 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003913
Brad Ebinger35c841c2018-10-01 10:40:55 -07003914 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3915 final long token = Binder.clearCallingIdentity();
3916 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003917 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003918 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
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(token);
3923 }
3924 }
3925
3926 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003927 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003929 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003930 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 Ebinger35c841c2018-10-01 10:40:55 -07003934 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003935 } catch (ImsException e) {
3936 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003937 } finally {
3938 Binder.restoreCallingIdentity(identity);
3939 }
3940 }
3941
shilu366312e2019-12-17 09:28:10 -08003942 /**
3943 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3944 * @param subId The subscription to use to check the configuration.
3945 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003946 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003947 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003948 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3949 mApp, subId, "isVtSettingEnabled");
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.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003953 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3954 } catch (ImsException e) {
3955 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003956 } finally {
3957 Binder.restoreCallingIdentity(identity);
3958 }
3959 }
3960
3961 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003962 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003963 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003964 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003965 final long identity = Binder.clearCallingIdentity();
3966 try {
3967 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003968 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003969 } catch (ImsException e) {
3970 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003971 } finally {
3972 Binder.restoreCallingIdentity(identity);
3973 }
3974 }
3975
shilu366312e2019-12-17 09:28:10 -08003976 /**
3977 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3978 * @param subId The subscription to use to check the configuration.
3979 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003980 @Override
3981 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003982 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3983 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003984 final long identity = Binder.clearCallingIdentity();
3985 try {
3986 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003987 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003988 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003989 } catch (ImsException e) {
3990 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003991 } finally {
3992 Binder.restoreCallingIdentity(identity);
3993 }
3994 }
3995
3996 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003997 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003999 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004000 final long identity = Binder.clearCallingIdentity();
4001 try {
4002 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004003 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004004 } catch (ImsException e) {
4005 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004006 } finally {
4007 Binder.restoreCallingIdentity(identity);
4008 }
4009 }
4010
shilu366312e2019-12-17 09:28:10 -08004011 /**
4012 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4013 * @param subId The subscription to use to check the configuration.
4014 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004015 @Override
4016 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004017 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4018 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004019 final long identity = Binder.clearCallingIdentity();
4020 try {
4021 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004022 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004023 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004024 } catch (ImsException e) {
4025 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004026 } finally {
4027 Binder.restoreCallingIdentity(identity);
4028 }
4029 }
4030
4031 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004032 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004034 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004035 final long identity = Binder.clearCallingIdentity();
4036 try {
4037 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004038 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004040 } catch (ImsException e) {
4041 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004042 } finally {
4043 Binder.restoreCallingIdentity(identity);
4044 }
4045 }
4046
4047 @Override
4048 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4050 "setVoWiFiNonPersistent");
4051 final long identity = Binder.clearCallingIdentity();
4052 try {
4053 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004054 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004055 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004056 } catch (ImsException e) {
4057 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004058 } finally {
4059 Binder.restoreCallingIdentity(identity);
4060 }
4061 }
4062
shilu366312e2019-12-17 09:28:10 -08004063 /**
4064 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4065 * @param subId The subscription to use to check the configuration.
4066 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004067 @Override
4068 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004069 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4070 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004071 final long identity = Binder.clearCallingIdentity();
4072 try {
4073 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004074 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004075 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004076 } catch (ImsException e) {
4077 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004078 } finally {
4079 Binder.restoreCallingIdentity(identity);
4080 }
4081 }
4082
4083 @Override
4084 public void setVoWiFiModeSetting(int subId, int mode) {
4085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4086 "setVoWiFiModeSetting");
4087 final long identity = Binder.clearCallingIdentity();
4088 try {
4089 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004090 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004091 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004092 } catch (ImsException e) {
4093 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004094 } finally {
4095 Binder.restoreCallingIdentity(identity);
4096 }
4097 }
4098
4099 @Override
4100 public int getVoWiFiRoamingModeSetting(int subId) {
4101 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4102 final long identity = Binder.clearCallingIdentity();
4103 try {
4104 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004105 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004106 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004107 } catch (ImsException e) {
4108 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004109 } finally {
4110 Binder.restoreCallingIdentity(identity);
4111 }
4112 }
4113
4114 @Override
4115 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4117 "setVoWiFiRoamingModeSetting");
4118 final long identity = Binder.clearCallingIdentity();
4119 try {
4120 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004121 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004122 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004123 } catch (ImsException e) {
4124 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004125 } finally {
4126 Binder.restoreCallingIdentity(identity);
4127 }
4128 }
4129
4130 @Override
4131 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4132 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4133 "setRttCapabilityEnabled");
4134 final long identity = Binder.clearCallingIdentity();
4135 try {
4136 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004137 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4138 } catch (ImsException e) {
4139 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004140 } finally {
4141 Binder.restoreCallingIdentity(identity);
4142 }
4143 }
4144
shilu366312e2019-12-17 09:28:10 -08004145 /**
4146 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4147 * @param subId The subscription to use to check the configuration.
4148 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004149 @Override
4150 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004151 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4152 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004153 final long identity = Binder.clearCallingIdentity();
4154 try {
4155 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004156 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004157 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004158 } catch (ImsException e) {
4159 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004160 } finally {
4161 Binder.restoreCallingIdentity(identity);
4162 }
4163 }
4164
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004165 @Override
4166 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4167 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4168 final long identity = Binder.clearCallingIdentity();
4169 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004170 if (!isImsAvailableOnDevice()) {
4171 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4172 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004173 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004174 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004175 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004176 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004177 } catch (ImsException e) {
4178 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004179 } finally {
4180 Binder.restoreCallingIdentity(identity);
4181 }
4182 }
4183
4184 @Override
4185 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4186 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4187 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004188 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4189 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4190 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004191 try {
4192 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004193 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004194 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004195 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004196 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4197 + "is inactive, ignoring unregister.");
4198 // If the subscription is no longer active, just return, since the callback will already
4199 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004200 } finally {
4201 Binder.restoreCallingIdentity(identity);
4202 }
4203 }
4204
allenwtsu99c623b2020-01-03 18:24:23 +08004205
4206 private void checkModifyPhoneStatePermission(int subId, String message) {
4207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4208 message);
4209 }
4210
4211 private boolean isImsProvisioningRequired(int subId, int capability,
4212 boolean isMmtelCapability) {
4213 Phone phone = getPhone(subId);
4214 if (phone == null) {
4215 loge("phone instance null for subid " + subId);
4216 return false;
4217 }
4218 if (isMmtelCapability) {
4219 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4220 return false;
4221 }
4222 } else {
4223 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4224 return false;
4225 }
4226 }
4227 return true;
4228 }
4229
4230 @Override
4231 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4232 boolean isProvisioned) {
4233 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4234
4235 final long identity = Binder.clearCallingIdentity();
4236 try {
4237 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4238 if (!isImsProvisioningRequired(subId, capability, false)) {
4239 return;
4240 }
4241
4242 // this capability requires provisioning, route to the correct API.
4243 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4244 switch (capability) {
4245 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4246 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4247 ims.setEabProvisioned(isProvisioned);
4248 break;
4249 default: {
4250 throw new IllegalArgumentException("Tried to set provisioning for "
4251 + "rcs capability '" + capability + "', which does not require "
4252 + "provisioning.");
4253 }
4254 }
4255 } finally {
4256 Binder.restoreCallingIdentity(identity);
4257 }
4258
4259 }
4260
4261
4262 @Override
4263 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4264 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4265 final long identity = Binder.clearCallingIdentity();
4266 try {
4267 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4268 if (!isImsProvisioningRequired(subId, capability, false)) {
4269 return true;
4270 }
4271
4272 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4273 switch (capability) {
4274 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4275 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4276 return ims.isEabProvisionedOnDevice();
4277
4278 default: {
4279 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4280 + "capability '" + capability + "', which does not require "
4281 + "provisioning.");
4282 }
4283 }
4284
4285 } finally {
4286 Binder.restoreCallingIdentity(identity);
4287 }
4288 }
4289
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004290 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004291 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4292 boolean isProvisioned) {
4293 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4294 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4295 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4296 }
allenwtsu99c623b2020-01-03 18:24:23 +08004297 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004298 final long identity = Binder.clearCallingIdentity();
4299 try {
4300 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004301 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004302 return;
4303 }
4304
4305 // this capability requires provisioning, route to the correct API.
4306 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4307 switch (capability) {
4308 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4309 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4310 ims.setVolteProvisioned(isProvisioned);
4311 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4312 ims.setWfcProvisioned(isProvisioned);
4313 }
4314 break;
4315 }
4316 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4317 // There is currently no difference in VT provisioning type.
4318 ims.setVtProvisioned(isProvisioned);
4319 break;
4320 }
4321 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4322 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4323 // change the capability of the feature instead if needed.
4324 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4325 == isProvisioned) {
4326 // No change in provisioning.
4327 return;
4328 }
4329 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4330 try {
4331 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004332 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004333 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4334 + ", Exception" + e.getMessage());
4335 }
4336 break;
4337 }
4338 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004339 throw new IllegalArgumentException("Tried to set provisioning for "
4340 + "MmTel capability '" + capability + "', which does not require "
4341 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004342 }
4343 }
4344
4345 } finally {
4346 Binder.restoreCallingIdentity(identity);
4347 }
4348 }
4349
4350 @Override
4351 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4352 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4353 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4354 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4355 }
4356 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4357 final long identity = Binder.clearCallingIdentity();
4358 try {
4359 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004360 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004361 return true;
4362 }
4363
4364 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4365 switch (capability) {
4366 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4367 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4368 return ims.isVolteProvisionedOnDevice();
4369 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4370 return ims.isWfcProvisionedOnDevice();
4371 }
4372 // This should never happen, since we are checking tech above to make sure it
4373 // is either LTE or IWLAN.
4374 throw new IllegalArgumentException("Invalid radio technology for voice "
4375 + "capability.");
4376 }
4377 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4378 // There is currently no difference in VT provisioning type.
4379 return ims.isVtProvisionedOnDevice();
4380 }
4381 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4382 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4383 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4384 }
4385 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004386 throw new IllegalArgumentException(
4387 "Tried to get provisioning for MmTel capability '" + capability
4388 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004389 }
4390 }
4391
4392 } finally {
4393 Binder.restoreCallingIdentity(identity);
4394 }
4395 }
4396
4397 @Override
4398 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4399 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4400 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4401 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4402 }
4403 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4404 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4405 return (provisionedBits & capability) > 0;
4406 }
4407
4408 @Override
4409 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4410 boolean isProvisioned) {
4411 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4412 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4413 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4414 }
4415 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4416 "setProvisioningStatusForCapability");
4417 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4418 // If the current provisioning status for capability already matches isProvisioned,
4419 // do nothing.
4420 if (((provisionedBits & capability) > 0) == isProvisioned) {
4421 return;
4422 }
4423 if (isProvisioned) {
4424 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4425 } else {
4426 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4427 }
4428 }
4429
4430 /**
4431 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4432 * technology. The bitfield should mirror the bitfield defined by
4433 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4434 */
4435 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4436 String key = getMmTelProvisioningKey(subId, tech);
4437 // Default is no capabilities are provisioned.
4438 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4439 }
4440
4441 /**
4442 * Sets the MmTel capability provisioning bitfield (defined by
4443 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4444 * technology specified.
4445 *
4446 * Note: This is a synchronous command and should not be called on UI thread.
4447 */
4448 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4449 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4450 String key = getMmTelProvisioningKey(subId, tech);
4451 editor.putInt(key, newField);
4452 editor.commit();
4453 }
4454
4455 private static String getMmTelProvisioningKey(int subId, int tech) {
4456 // resulting key is provision_ims_mmtel_{subId}_{tech}
4457 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4458 }
4459
4460 /**
4461 * Query CarrierConfig to see if the specified capability requires provisioning for the
4462 * carrier associated with the subscription id.
4463 */
4464 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4465 int capability) {
4466 CarrierConfigManager configManager = new CarrierConfigManager(context);
4467 PersistableBundle c = configManager.getConfigForSubId(subId);
4468 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004469 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004470 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4471 false);
4472 boolean requireVoiceVtProvisioning = c.getBoolean(
4473 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4474
4475 // First check to make sure that the capability requires provisioning.
4476 switch (capability) {
4477 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4478 // intentional fallthrough
4479 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4480 if (requireVoiceVtProvisioning) {
4481 // Voice and Video requires provisioning
4482 return true;
4483 }
4484 break;
4485 }
4486 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4487 if (requireUtProvisioning) {
4488 // UT requires provisioning
4489 return true;
4490 }
4491 break;
4492 }
4493 }
4494 return false;
4495 }
4496
allenwtsu99c623b2020-01-03 18:24:23 +08004497 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4498 int capability) {
4499 CarrierConfigManager configManager = new CarrierConfigManager(context);
4500 PersistableBundle c = configManager.getConfigForSubId(subId);
4501
4502 boolean requireRcsProvisioning = c.getBoolean(
4503 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4504
4505 // First check to make sure that the capability requires provisioning.
4506 switch (capability) {
4507 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4508 // intentional fallthrough
4509 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4510 if (requireRcsProvisioning) {
4511 // OPTION or PRESENCE requires provisioning
4512 return true;
4513 }
4514 break;
4515 }
4516 }
4517 return false;
4518 }
4519
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004520 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004521 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004522 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4523 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4524 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004525 enforceReadPrivilegedPermission("getImsProvisioningInt");
4526 final long identity = Binder.clearCallingIdentity();
4527 try {
4528 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004529 int slotId = getSlotIndex(subId);
4530 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4531 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4532 + subId + "' for key:" + key);
4533 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4534 }
4535 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004536 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004537 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4538 + subId + "' for key:" + key);
4539 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004540 } finally {
4541 Binder.restoreCallingIdentity(identity);
4542 }
4543 }
4544
4545 @Override
4546 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004547 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4548 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4549 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004550 enforceReadPrivilegedPermission("getImsProvisioningString");
4551 final long identity = Binder.clearCallingIdentity();
4552 try {
4553 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004554 int slotId = getSlotIndex(subId);
4555 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4556 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4557 + subId + "' for key:" + key);
4558 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4559 }
4560 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004561 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004562 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4563 + subId + "' for key:" + key);
4564 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004565 } finally {
4566 Binder.restoreCallingIdentity(identity);
4567 }
4568 }
4569
4570 @Override
4571 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004572 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4573 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4574 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4576 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004577 final long identity = Binder.clearCallingIdentity();
4578 try {
4579 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004580 int slotId = getSlotIndex(subId);
4581 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4582 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4583 + subId + "' for key:" + key);
4584 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4585 }
4586 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004587 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004588 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4589 + "' for key:" + key);
4590 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004591 } finally {
4592 Binder.restoreCallingIdentity(identity);
4593 }
4594 }
4595
4596 @Override
4597 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004598 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4599 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4600 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4602 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004603 final long identity = Binder.clearCallingIdentity();
4604 try {
4605 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004606 int slotId = getSlotIndex(subId);
4607 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4608 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4609 + subId + "' for key:" + key);
4610 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4611 }
4612 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004613 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004614 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4615 + "' for key:" + key);
4616 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004617 } finally {
4618 Binder.restoreCallingIdentity(identity);
4619 }
4620 }
4621
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004622 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004623 int slotId = SubscriptionManager.getSlotIndex(subId);
4624 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004625 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4626 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004627 }
4628 return slotId;
4629 }
4630
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004631 private int getSlotIndex(int subId) {
4632 int slotId = SubscriptionManager.getSlotIndex(subId);
4633 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4634 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4635 }
4636 return slotId;
4637 }
4638
Wink Saville36469e72014-06-11 15:17:00 -07004639 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004640 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004641 */
4642 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004643 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4644 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004645 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004646 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004647 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004648 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004649 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004650 mApp, subId, callingPackage, callingFeatureId,
4651 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004652 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4653 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004654
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004655 final long identity = Binder.clearCallingIdentity();
4656 try {
4657 final Phone phone = getPhone(subId);
4658 if (phone != null) {
4659 return phone.getServiceState().getDataNetworkType();
4660 } else {
4661 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4662 }
4663 } finally {
4664 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004665 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004666 }
4667
4668 /**
4669 * Returns the data network type
4670 */
4671 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004672 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4673 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4674 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004675 }
4676
4677 /**
4678 * Returns the data network type for a subId
4679 */
4680 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004681 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4682 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004683 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004684 mApp, subId, callingPackage, callingFeatureId,
4685 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004686 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4687 }
4688
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004689 final long identity = Binder.clearCallingIdentity();
4690 try {
4691 final Phone phone = getPhone(subId);
4692 if (phone != null) {
4693 return phone.getServiceState().getDataNetworkType();
4694 } else {
4695 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4696 }
4697 } finally {
4698 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004699 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004700 }
4701
4702 /**
Wink Saville36469e72014-06-11 15:17:00 -07004703 * Returns the Voice network type for a subId
4704 */
4705 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004706 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4707 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004708 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004709 mApp, subId, callingPackage, callingFeatureId,
4710 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004711 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4712 }
4713
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004714 final long identity = Binder.clearCallingIdentity();
4715 try {
4716 final Phone phone = getPhone(subId);
4717 if (phone != null) {
4718 return phone.getServiceState().getVoiceNetworkType();
4719 } else {
4720 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4721 }
4722 } finally {
4723 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004725 }
4726
4727 /**
4728 * @return true if a ICC card is present
4729 */
4730 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004731 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004732 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4733 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004734 }
4735
4736 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004737 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004738 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004739 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004740 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004741 final long identity = Binder.clearCallingIdentity();
4742 try {
4743 final Phone phone = PhoneFactory.getPhone(slotIndex);
4744 if (phone != null) {
4745 return phone.getIccCard().hasIccCard();
4746 } else {
4747 return false;
4748 }
4749 } finally {
4750 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004751 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004752 }
4753
4754 /**
4755 * Return if the current radio is LTE on CDMA. This
4756 * is a tri-state return value as for a period of time
4757 * the mode may be unknown.
4758 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004759 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004760 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004761 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004762 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004763 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004764 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4765 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4766 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004767 }
4768
Sanket Padawe356d7632015-06-22 14:03:32 -07004769 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004770 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4771 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004772 try {
4773 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4774 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004775 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4776 }
4777
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004778 final long identity = Binder.clearCallingIdentity();
4779 try {
4780 final Phone phone = getPhone(subId);
4781 if (phone == null) {
4782 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4783 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004784 return TelephonyProperties.lte_on_cdma_device()
4785 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004786 }
4787 } finally {
4788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004789 }
Wink Saville36469e72014-06-11 15:17:00 -07004790 }
4791
Wink Saville36469e72014-06-11 15:17:00 -07004792 /**
4793 * {@hide}
4794 * Returns Default subId, 0 in the case of single standby.
4795 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004796 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004797 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004798 }
4799
Shishir Agrawala9f32182016-04-12 12:00:16 -07004800 private int getSlotForDefaultSubscription() {
4801 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4802 }
4803
Wink Savilleb564aae2014-10-23 10:18:09 -07004804 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004805 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004806 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004807
Pengquan Menge92a50d2018-09-21 15:54:48 -07004808 private boolean isActiveSubscription(int subId) {
4809 return mSubscriptionController.isActiveSubId(subId);
4810 }
4811
Ihab Awadf2177b72013-11-25 13:33:23 -08004812 /**
4813 * @see android.telephony.TelephonyManager.WifiCallingChoices
4814 */
4815 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004816 final long identity = Binder.clearCallingIdentity();
4817 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004818 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004819 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4820 getWhenToMakeWifiCallsDefaultPreference());
4821 } finally {
4822 Binder.restoreCallingIdentity(identity);
4823 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004824 }
4825
4826 /**
4827 * @see android.telephony.TelephonyManager.WifiCallingChoices
4828 */
4829 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004830 final long identity = Binder.clearCallingIdentity();
4831 try {
4832 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004833 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004834 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4835 } finally {
4836 Binder.restoreCallingIdentity(identity);
4837 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004838 }
4839
Sailesh Nepald1e68152013-12-12 19:08:02 -08004840 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004841 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004842 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004843 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004844
Jordan Liu4c733742019-02-28 12:03:40 -08004845 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4846 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4847 if (phoneId == -1) {
4848 throw new IllegalArgumentException("Given slot index: " + slotIndex
4849 + " does not correspond to an active phone");
4850 }
4851 return PhoneFactory.getPhone(phoneId);
4852 }
4853
Shishir Agrawal566b7612013-10-28 14:41:00 -07004854 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004855 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4856 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4858 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004859 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004860 if (DBG) {
4861 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4862 }
4863 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4864 p2);
4865 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004866
Jordan Liu4c733742019-02-28 12:03:40 -08004867
4868 @Override
4869 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4870 int slotIndex, String callingPackage, String aid, int p2) {
4871 enforceModifyPermission();
4872 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4873 if (DBG) {
4874 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4875 }
4876 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4877 callingPackage, aid, p2);
4878 }
4879
4880 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4881 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004882 final long identity = Binder.clearCallingIdentity();
4883 try {
4884 if (TextUtils.equals(ISDR_AID, aid)) {
4885 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004886 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4887 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004888 if (bestComponent == null
4889 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4890 loge("The calling package is not allowed to access ISD-R.");
4891 throw new SecurityException(
4892 "The calling package is not allowed to access ISD-R.");
4893 }
Derek Tan740e1672017-06-27 14:56:27 -07004894 }
Derek Tan740e1672017-06-27 14:56:27 -07004895
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004896 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004897 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4898 null /* workSource */);
4899 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004900 return response;
4901 } finally {
4902 Binder.restoreCallingIdentity(identity);
4903 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004904 }
4905
4906 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004907 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004908 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4909 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004910 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4911 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4912 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004913
Jordan Liu4c733742019-02-28 12:03:40 -08004914 @Override
4915 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4916 enforceModifyPermission();
4917 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4918 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4919 channel);
4920 }
4921
4922 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004923 final long identity = Binder.clearCallingIdentity();
4924 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004925 if (channel < 0) {
4926 return false;
4927 }
Jordan Liu4c733742019-02-28 12:03:40 -08004928 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4929 null /* workSource */);
4930 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931 return success;
4932 } finally {
4933 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004934 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004935 }
4936
4937 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004938 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004939 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4941 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004942 if (DBG) {
4943 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4944 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4945 + p3 + " data=" + data);
4946 }
4947 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4948 command, p1, p2, p3, data);
4949 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004950
Jordan Liu4c733742019-02-28 12:03:40 -08004951 @Override
4952 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4953 int command, int p1, int p2, int p3, String data) {
4954 enforceModifyPermission();
4955 if (DBG) {
4956 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4957 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4958 + p3 + " data=" + data);
4959 }
4960 return iccTransmitApduLogicalChannelWithPermission(
4961 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4962 data);
4963 }
4964
4965 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4966 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004967 final long identity = Binder.clearCallingIdentity();
4968 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004969 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970 return "";
4971 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004972
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004974 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4975 null /* workSource */);
4976 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004978 // Append the returned status code to the end of the response payload.
4979 String s = Integer.toHexString(
4980 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4981 if (response.payload != null) {
4982 s = IccUtils.bytesToHexString(response.payload) + s;
4983 }
4984 return s;
4985 } finally {
4986 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004987 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004988 }
Jake Hambye994d462014-02-03 13:10:13 -08004989
Evan Charltonc66da362014-05-16 14:06:40 -07004990 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004991 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4992 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4994 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004995 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004996 if (DBG) {
4997 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4998 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4999 }
5000 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5001 cla, command, p1, p2, p3, data);
5002 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005003
Jordan Liu4c733742019-02-28 12:03:40 -08005004 @Override
5005 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5006 int command, int p1, int p2, int p3, String data) {
5007 enforceModifyPermission();
5008 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5009 if (DBG) {
5010 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5011 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5012 + " data=" + data);
5013 }
5014
5015 return iccTransmitApduBasicChannelWithPermission(
5016 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5017 p2, p3, data);
5018 }
5019
5020 // open APDU basic channel assuming the caller has sufficient permissions
5021 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5022 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023 final long identity = Binder.clearCallingIdentity();
5024 try {
5025 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5026 && TextUtils.equals(ISDR_AID, data)) {
5027 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005028 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5029 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005030 if (bestComponent == null
5031 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5032 loge("The calling package is not allowed to select ISD-R.");
5033 throw new SecurityException(
5034 "The calling package is not allowed to select ISD-R.");
5035 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005036 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005037
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005039 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5040 null /* workSource */);
5041 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005042
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005043 // Append the returned status code to the end of the response payload.
5044 String s = Integer.toHexString(
5045 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5046 if (response.payload != null) {
5047 s = IccUtils.bytesToHexString(response.payload) + s;
5048 }
5049 return s;
5050 } finally {
5051 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005052 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005053 }
5054
5055 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005056 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005057 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5059 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005060
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005061 final long identity = Binder.clearCallingIdentity();
5062 try {
5063 if (DBG) {
5064 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5065 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5066 }
5067
5068 IccIoResult response =
5069 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5070 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5071 subId);
5072
5073 if (DBG) {
5074 log("Exchange SIM_IO [R]" + response);
5075 }
5076
5077 byte[] result = null;
5078 int length = 2;
5079 if (response.payload != null) {
5080 length = 2 + response.payload.length;
5081 result = new byte[length];
5082 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5083 } else {
5084 result = new byte[length];
5085 }
5086
5087 result[length - 1] = (byte) response.sw2;
5088 result[length - 2] = (byte) response.sw1;
5089 return result;
5090 } finally {
5091 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005092 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005093 }
5094
Nathan Haroldb3014052017-01-25 15:57:32 -08005095 /**
5096 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5097 * on a particular subscription
5098 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005099 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5100 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005101 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005102 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005103 return null;
5104 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005105
5106 final long identity = Binder.clearCallingIdentity();
5107 try {
5108 if (appType != TelephonyManager.APPTYPE_USIM
5109 && appType != TelephonyManager.APPTYPE_SIM) {
5110 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5111 return null;
5112 }
5113 Object response = sendRequest(
5114 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5115 if (response instanceof String[]) {
5116 return (String[]) response;
5117 }
yincheng zhaod698b842019-09-06 17:06:54 -07005118 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005119 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005120 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005121 } finally {
5122 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005123 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005124 }
5125
yincheng zhaod698b842019-09-06 17:06:54 -07005126 /**
5127 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5128 * subscription.
5129 *
5130 * @param subId the id of the subscription.
5131 * @param appType the uicc app type, must be USIM or SIM.
5132 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5133 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005134 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005135 * @return number of fplmns that is successfully written to the SIM.
5136 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005137 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5138 String callingFeatureId) {
5139 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5140 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005141 if (DBG) logv("no permissions for setForbiddenplmns");
5142 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5143 }
5144 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5145 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5146 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5147 }
5148 if (fplmns == null) {
5149 throw new IllegalArgumentException("Fplmn List provided is null");
5150 }
5151 for (String fplmn : fplmns) {
5152 if (!CellIdentity.isValidPlmn(fplmn)) {
5153 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5154 }
5155 }
5156 final long identity = Binder.clearCallingIdentity();
5157 try {
5158 Object response = sendRequest(
5159 CMD_SET_FORBIDDEN_PLMNS,
5160 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5161 subId);
5162 return (int) response;
5163 } finally {
5164 Binder.restoreCallingIdentity(identity);
5165 }
5166 }
5167
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005168 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005169 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005170 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5171 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005172
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 final long identity = Binder.clearCallingIdentity();
5174 try {
5175 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5176 if (response.payload == null) {
5177 return "";
5178 }
Evan Charltonc66da362014-05-16 14:06:40 -07005179
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005180 // Append the returned status code to the end of the response payload.
5181 String s = Integer.toHexString(
5182 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5183 s = IccUtils.bytesToHexString(response.payload) + s;
5184 return s;
5185 } finally {
5186 Binder.restoreCallingIdentity(identity);
5187 }
Evan Charltonc66da362014-05-16 14:06:40 -07005188 }
5189
Jake Hambye994d462014-02-03 13:10:13 -08005190 /**
5191 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5192 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5193 *
5194 * @param itemID the ID of the item to read
5195 * @return the NV item as a String, or null on error.
5196 */
5197 @Override
5198 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005199 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005200 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5201 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005202
5203 final long identity = Binder.clearCallingIdentity();
5204 try {
5205 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005206 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5208 return value;
5209 } finally {
5210 Binder.restoreCallingIdentity(identity);
5211 }
Jake Hambye994d462014-02-03 13:10:13 -08005212 }
5213
5214 /**
5215 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5216 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5217 *
5218 * @param itemID the ID of the item to read
5219 * @param itemValue the value to write, as a String
5220 * @return true on success; false on any failure
5221 */
5222 @Override
5223 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005224 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5226 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005227
5228 final long identity = Binder.clearCallingIdentity();
5229 try {
5230 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5231 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005232 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005233 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5234 return success;
5235 } finally {
5236 Binder.restoreCallingIdentity(identity);
5237 }
Jake Hambye994d462014-02-03 13:10:13 -08005238 }
5239
5240 /**
5241 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5242 * Used for device configuration by some CDMA operators.
5243 *
5244 * @param preferredRoamingList byte array containing the new PRL
5245 * @return true on success; false on any failure
5246 */
5247 @Override
5248 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005249 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5250 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005251
5252 final long identity = Binder.clearCallingIdentity();
5253 try {
5254 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5255 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5256 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5257 return success;
5258 } finally {
5259 Binder.restoreCallingIdentity(identity);
5260 }
Jake Hambye994d462014-02-03 13:10:13 -08005261 }
5262
5263 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005264 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005265 * Used for device configuration by some CDMA operators.
5266 *
chen xu6dac5ab2018-10-26 17:39:23 -07005267 * @param slotIndex - device slot.
5268 *
Jake Hambye994d462014-02-03 13:10:13 -08005269 * @return true on success; false on any failure
5270 */
5271 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005272 public boolean resetModemConfig(int slotIndex) {
5273 Phone phone = PhoneFactory.getPhone(slotIndex);
5274 if (phone != null) {
5275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5276 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005277
chen xu6dac5ab2018-10-26 17:39:23 -07005278 final long identity = Binder.clearCallingIdentity();
5279 try {
5280 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5281 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5282 return success;
5283 } finally {
5284 Binder.restoreCallingIdentity(identity);
5285 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 }
chen xu6dac5ab2018-10-26 17:39:23 -07005287 return false;
5288 }
5289
5290 /**
5291 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5292 *
5293 * @param slotIndex - device slot.
5294 *
5295 * @return true on success; false on any failure
5296 */
5297 @Override
5298 public boolean rebootModem(int slotIndex) {
5299 Phone phone = PhoneFactory.getPhone(slotIndex);
5300 if (phone != null) {
5301 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5302 mApp, phone.getSubId(), "rebootModem");
5303
5304 final long identity = Binder.clearCallingIdentity();
5305 try {
5306 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5307 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5308 return success;
5309 } finally {
5310 Binder.restoreCallingIdentity(identity);
5311 }
5312 }
5313 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005314 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005315
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005316 public String[] getPcscfAddress(String apnType, String callingPackage,
5317 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005318 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005319 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5320 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005321 return new String[0];
5322 }
5323
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324 final long identity = Binder.clearCallingIdentity();
5325 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005326 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327 } finally {
5328 Binder.restoreCallingIdentity(identity);
5329 }
Wink Saville36469e72014-06-11 15:17:00 -07005330 }
5331
Brad Ebinger51f743a2017-01-23 13:50:20 -08005332 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005333 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5334 * {@link #disableIms(int)}.
5335 * @param slotIndex device slot.
5336 */
5337 public void resetIms(int slotIndex) {
5338 enforceModifyPermission();
5339
5340 final long identity = Binder.clearCallingIdentity();
5341 try {
5342 if (mImsResolver == null) {
5343 // may happen if the does not support IMS.
5344 return;
5345 }
5346 mImsResolver.disableIms(slotIndex);
5347 mImsResolver.enableIms(slotIndex);
5348 } finally {
5349 Binder.restoreCallingIdentity(identity);
5350 }
5351 }
5352
5353 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005354 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5355 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005356 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005357 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005358 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359
5360 final long identity = Binder.clearCallingIdentity();
5361 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005362 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005363 // may happen if the device does not support IMS.
5364 return;
5365 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005366 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005367 } finally {
5368 Binder.restoreCallingIdentity(identity);
5369 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005370 }
5371
5372 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005373 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5374 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005375 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005376 public void disableIms(int slotId) {
5377 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005378
5379 final long identity = Binder.clearCallingIdentity();
5380 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005381 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005382 // may happen if the device does not support IMS.
5383 return;
5384 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005385 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386 } finally {
5387 Binder.restoreCallingIdentity(identity);
5388 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005389 }
5390
5391 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005392 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5393 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005394 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005395 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005396 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005397 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398
5399 final long identity = Binder.clearCallingIdentity();
5400 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005401 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005402 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5403 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005404 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005405 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 } finally {
5407 Binder.restoreCallingIdentity(identity);
5408 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005409 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005410 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005411 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5412 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005413 @Override
5414 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005415 enforceModifyPermission();
5416
5417 final long identity = Binder.clearCallingIdentity();
5418 try {
5419 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005420 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005421 } finally {
5422 Binder.restoreCallingIdentity(identity);
5423 }
5424 }
5425
5426 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005427 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005428 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005429 */
5430 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5431 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005432
5433 final long identity = Binder.clearCallingIdentity();
5434 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005435 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005436 // may happen if the device does not support IMS.
5437 return null;
5438 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005439 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005440 } finally {
5441 Binder.restoreCallingIdentity(identity);
5442 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005443 }
5444
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005445 /**
5446 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005447 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005448 */
5449 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5450 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005451
5452 final long identity = Binder.clearCallingIdentity();
5453 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005454 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005455 // may happen if the device does not support IMS.
5456 return null;
5457 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005458 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459 } finally {
5460 Binder.restoreCallingIdentity(identity);
5461 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005462 }
5463
Brad Ebinger884c07b2018-02-15 16:17:40 -08005464 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005465 * Sets the ImsService Package Name that Telephony will bind to.
5466 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005467 * @param slotIndex the slot ID that the ImsService should bind for.
5468 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005469 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005470 * @param featureTypes An integer array of feature types associated with a packageName.
5471 * @param packageName The name of the package that the current configuration will be replaced
5472 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005473 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005474 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005475 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5476 int[] featureTypes, String packageName) {
5477 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5478 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005479 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5480 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005481 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005482
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483 final long identity = Binder.clearCallingIdentity();
5484 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005485 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005486 // may happen if the device does not support IMS.
5487 return false;
5488 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005489 Map<Integer, String> featureConfig = new HashMap<>();
5490 for (int featureType : featureTypes) {
5491 featureConfig.put(featureType, packageName);
5492 }
5493 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5494 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005495 } finally {
5496 Binder.restoreCallingIdentity(identity);
5497 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005498 }
5499
5500 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005501 * Clears any carrier ImsService overrides for the slot index specified that were previously
5502 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5503 *
5504 * This should only be used for testing.
5505 *
5506 * @param slotIndex the slot ID that the ImsService should bind for.
5507 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5508 */
5509 @Override
5510 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5511 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5512 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5513 "clearCarrierImsServiceOverride");
5514 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5515 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5516 "clearCarrierImsServiceOverride");
5517
5518 final long identity = Binder.clearCallingIdentity();
5519 try {
5520 if (mImsResolver == null) {
5521 // may happen if the device does not support IMS.
5522 return false;
5523 }
5524 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5525 } finally {
5526 Binder.restoreCallingIdentity(identity);
5527 }
5528 }
5529
5530 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005531 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005532 *
5533 * @param slotId The slot that the ImsService is associated with.
5534 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5535 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005536 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005537 * @return the package name of the ImsService configuration.
5538 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005539 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5540 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005541 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005542 TelephonyPermissions
5543 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5544 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5545 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005546
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005547 final long identity = Binder.clearCallingIdentity();
5548 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005549 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005550 // may happen if the device does not support IMS.
5551 return "";
5552 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005553 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005554 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5555 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005556 } finally {
5557 Binder.restoreCallingIdentity(identity);
5558 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005559 }
5560
Brad Ebinger77b832e2019-10-17 17:03:22 -07005561 /**
5562 * Get the MmTelFeature state associated with the requested subscription id.
5563 * @param subId The subscription that the MmTelFeature is associated with.
5564 * @param callback A callback with an integer containing the
5565 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5566 */
5567 @Override
5568 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5569 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5570 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5571 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5572 "IMS not available on device.");
5573 }
5574 final long token = Binder.clearCallingIdentity();
5575 try {
5576 int slotId = getSlotIndex(subId);
5577 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5578 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5579 + subId + "'");
5580 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5581 }
5582 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5583 try {
5584 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5585 } catch (RemoteException e) {
5586 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5587 + "Ignore");
5588 }
5589 });
5590 } finally {
5591 Binder.restoreCallingIdentity(token);
5592 }
5593 }
5594
Daniel Brightbb5840b2021-01-12 15:48:18 -08005595 /**
5596 * Sets the ims registration state on all valid {@link Phone}s.
5597 */
5598 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005599 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005600
5601 final long identity = Binder.clearCallingIdentity();
5602 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005603 // NOTE: Before S, this method only set the default phone.
5604 for (final Phone phone : PhoneFactory.getPhones()) {
5605 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5606 phone.setImsRegistrationState(registered);
5607 }
5608 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005609 } finally {
5610 Binder.restoreCallingIdentity(identity);
5611 }
Wink Saville36469e72014-06-11 15:17:00 -07005612 }
5613
5614 /**
Stuart Scott54788802015-03-30 13:18:01 -07005615 * Set the network selection mode to automatic.
5616 *
5617 */
5618 @Override
5619 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5621 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005622
5623 final long identity = Binder.clearCallingIdentity();
5624 try {
shilufc958392020-01-20 11:36:01 -08005625 if (!isActiveSubscription(subId)) {
5626 return;
5627 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005629 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5630 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005631 } finally {
5632 Binder.restoreCallingIdentity(identity);
5633 }
Stuart Scott54788802015-03-30 13:18:01 -07005634 }
5635
Jack Yud10cdd42020-09-28 20:28:01 -07005636 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005637 * Ask the radio to connect to the input network and change selection mode to manual.
5638 *
5639 * @param subId the id of the subscription.
5640 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5641 * the operator to attach to.
5642 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5643 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5644 * normal network selection next time.
5645 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005646 */
5647 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005648 public boolean setNetworkSelectionModeManual(
5649 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5651 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005652
5653 if (!isActiveSubscription(subId)) {
5654 return false;
5655 }
5656
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005657 final long identity = Binder.clearCallingIdentity();
5658 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005659 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005660 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005661 if (DBG) {
5662 log("setNetworkSelectionModeManual: subId: " + subId
5663 + " operator: " + operatorInfo);
5664 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005665 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5666 } finally {
5667 Binder.restoreCallingIdentity(identity);
5668 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005669 }
shilu84f6e8b2019-12-19 13:58:01 -08005670 /**
5671 * Get the manual network selection
5672 *
5673 * @param subId the id of the subscription.
5674 *
5675 * @return the previously saved user selected PLMN
5676 */
5677 @Override
5678 public String getManualNetworkSelectionPlmn(int subId) {
5679 TelephonyPermissions
5680 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5681 mApp, subId, "getManualNetworkSelectionPlmn");
5682
5683 final long identity = Binder.clearCallingIdentity();
5684 try {
5685 if (!isActiveSubscription(subId)) {
5686 return "";
5687 }
5688
5689 final Phone phone = getPhone(subId);
5690 if (phone == null) {
5691 return "";
5692 }
5693 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5694 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5695 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5696 } finally {
5697 Binder.restoreCallingIdentity(identity);
5698 }
5699 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005700
5701 /**
5702 * Scans for available networks.
5703 */
5704 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005705 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5706 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5708 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005709 LocationAccessPolicy.LocationPermissionResult locationResult =
5710 LocationAccessPolicy.checkLocationPermission(mApp,
5711 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5712 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005713 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005714 .setCallingPid(Binder.getCallingPid())
5715 .setCallingUid(Binder.getCallingUid())
5716 .setMethod("getCellNetworkScanResults")
5717 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5718 .build());
5719 switch (locationResult) {
5720 case DENIED_HARD:
5721 throw new SecurityException("Not allowed to access scan results -- location");
5722 case DENIED_SOFT:
5723 return null;
5724 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005725
Pengquan Menga1bb6272018-09-06 09:59:22 -07005726 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005727 try {
5728 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005729 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005731 } finally {
5732 Binder.restoreCallingIdentity(identity);
5733 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005734 }
5735
5736 /**
sqian80370722020-01-29 15:02:51 -08005737 * Get the call forwarding info, given the call forwarding reason.
5738 */
5739 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005740 public void getCallForwarding(int subId, int callForwardingReason,
5741 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005742 enforceReadPrivilegedPermission("getCallForwarding");
5743 long identity = Binder.clearCallingIdentity();
5744 try {
5745 if (DBG) {
5746 log("getCallForwarding: subId " + subId
5747 + " callForwardingReason" + callForwardingReason);
5748 }
Hall Liua1acea22020-09-18 19:04:59 -07005749
5750 Phone phone = getPhone(subId);
5751 if (phone == null) {
5752 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005753 callback.onError(
5754 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005755 } catch (RemoteException e) {
5756 // ignore
5757 }
5758 return;
5759 }
5760
5761 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5762 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5763 @Override
5764 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5765 try {
5766 callback.onCallForwardingInfoAvailable(info);
5767 } catch (RemoteException e) {
5768 // ignore
5769 }
5770 }
5771
5772 @Override
5773 public void onError(int error) {
5774 try {
5775 callback.onError(error);
5776 } catch (RemoteException e) {
5777 // ignore
5778 }
5779 }
5780 });
5781 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005782 } finally {
5783 Binder.restoreCallingIdentity(identity);
5784 }
5785 }
5786
5787 /**
5788 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5789 * reason, the number to forward, and the timeout before the forwarding is attempted.
5790 */
5791 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005792 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5793 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005794 enforceModifyPermission();
5795 long identity = Binder.clearCallingIdentity();
5796 try {
5797 if (DBG) {
5798 log("setCallForwarding: subId " + subId
5799 + " callForwardingInfo" + callForwardingInfo);
5800 }
Hall Liua1acea22020-09-18 19:04:59 -07005801
5802 Phone phone = getPhone(subId);
5803 if (phone == null) {
5804 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005805 callback.accept(
5806 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005807 } catch (RemoteException e) {
5808 // ignore
5809 }
5810 return;
5811 }
5812
5813 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5814 FunctionalUtils.ignoreRemoteException(callback::accept));
5815
5816 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005817 } finally {
5818 Binder.restoreCallingIdentity(identity);
5819 }
5820 }
5821
5822 /**
Hall Liua1acea22020-09-18 19:04:59 -07005823 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005824 */
5825 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005826 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005827 enforceReadPrivilegedPermission("getCallForwarding");
5828 long identity = Binder.clearCallingIdentity();
5829 try {
Hall Liua1acea22020-09-18 19:04:59 -07005830
5831 Phone phone = getPhone(subId);
5832 if (phone == null) {
5833 try {
5834 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5835 } catch (RemoteException e) {
5836 // ignore
5837 }
5838 return;
5839 }
5840
5841 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5842
sqian80370722020-01-29 15:02:51 -08005843 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005844 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005845 } finally {
5846 Binder.restoreCallingIdentity(identity);
5847 }
5848 }
5849
5850 /**
Hall Liua1acea22020-09-18 19:04:59 -07005851 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005852 */
5853 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005854 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005855 enforceModifyPermission();
5856 long identity = Binder.clearCallingIdentity();
5857 try {
Hall Liua1acea22020-09-18 19:04:59 -07005858 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5859
5860 Phone phone = getPhone(subId);
5861 if (phone == null) {
5862 try {
5863 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5864 } catch (RemoteException e) {
5865 // ignore
5866 }
5867 return;
5868 }
5869
5870 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5871 FunctionalUtils.ignoreRemoteException(callback::accept));
5872
5873 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005874 } finally {
5875 Binder.restoreCallingIdentity(identity);
5876 }
5877 }
5878
5879 /**
yinxub1bed742017-04-17 11:45:04 -07005880 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005881 *
yinxub1bed742017-04-17 11:45:04 -07005882 * @param subId id of the subscription
5883 * @param request contains the radio access networks with bands/channels to scan
5884 * @param messenger callback messenger for scan results or errors
5885 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005886 * @return the id of the requested scan which can be used to stop the scan.
5887 */
5888 @Override
5889 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005890 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005891 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5892 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005893 LocationAccessPolicy.LocationPermissionResult locationResult =
5894 LocationAccessPolicy.checkLocationPermission(mApp,
5895 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5896 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005897 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005898 .setCallingPid(Binder.getCallingPid())
5899 .setCallingUid(Binder.getCallingUid())
5900 .setMethod("requestNetworkScan")
5901 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5902 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005903 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005904 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5905 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005906 if (e != null) {
5907 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5908 throw e;
5909 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005910 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005911 return TelephonyScanManager.INVALID_SCAN_ID;
5912 }
5913 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005914 }
Hall Liu912dfd32019-04-25 14:02:26 -07005915 int callingUid = Binder.getCallingUid();
5916 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005917 final long identity = Binder.clearCallingIdentity();
5918 try {
5919 return mNetworkScanRequestTracker.startNetworkScan(
5920 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005921 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005922 } finally {
5923 Binder.restoreCallingIdentity(identity);
5924 }
yinxu504e1392017-04-12 16:03:22 -07005925 }
5926
Hall Liub2ac8ef2019-02-28 15:56:23 -08005927 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005928 NetworkScanRequest request, int subId, String callingPackage) {
5929 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005930 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5931 boolean hasNetworkScanPermission =
5932 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5933 == PERMISSION_GRANTED;
5934
5935 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5936 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5937 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005938 }
5939
5940 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5941 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005942 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5943 return new SecurityException("Specific channels must not be"
5944 + " scanned without location access.");
5945 }
5946 }
5947 }
5948
Hall Liub2ac8ef2019-02-28 15:56:23 -08005949 return null;
5950 }
5951
yinxu504e1392017-04-12 16:03:22 -07005952 /**
5953 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005954 *
5955 * @param subId id of the subscription
5956 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005957 */
5958 @Override
5959 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005960 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5961 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962
Hall Liu912dfd32019-04-25 14:02:26 -07005963 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005964 final long identity = Binder.clearCallingIdentity();
5965 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005966 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005967 } finally {
5968 Binder.restoreCallingIdentity(identity);
5969 }
yinxu504e1392017-04-12 16:03:22 -07005970 }
5971
5972 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005973 * Get the calculated preferred network type.
5974 * Used for debugging incorrect network type.
5975 *
5976 * @return the preferred network type, defined in RILConstants.java.
5977 */
5978 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005979 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005980 final Phone defaultPhone = getDefaultPhone();
5981 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005982 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005983 return RILConstants.PREFERRED_NETWORK_MODE;
5984 }
5985
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005986 final long identity = Binder.clearCallingIdentity();
5987 try {
5988 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005989 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990 } finally {
5991 Binder.restoreCallingIdentity(identity);
5992 }
Junda Liu84d15a22014-07-02 11:21:04 -07005993 }
5994
5995 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005996 * Get the preferred network type.
5997 * Used for device configuration by some CDMA operators.
5998 *
5999 * @return the preferred network type, defined in RILConstants.java.
6000 */
6001 @Override
Stuart Scott54788802015-03-30 13:18:01 -07006002 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006003 TelephonyPermissions
6004 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6005 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006
6007 final long identity = Binder.clearCallingIdentity();
6008 try {
6009 if (DBG) log("getPreferredNetworkType");
6010 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
6011 int networkType = (result != null ? result[0] : -1);
6012 if (DBG) log("getPreferredNetworkType: " + networkType);
6013 return networkType;
6014 } finally {
6015 Binder.restoreCallingIdentity(identity);
6016 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006017 }
6018
6019 /**
6020 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08006021 *
6022 * @param networkType the preferred network type, defined in RILConstants.java.
6023 * @return true on success; false on any failure.
6024 */
6025 @Override
Stuart Scott54788802015-03-30 13:18:01 -07006026 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6028 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006029
6030 final long identity = Binder.clearCallingIdentity();
6031 try {
calvinpan089c2a62020-03-12 14:17:55 +08006032 Boolean success = (Boolean) sendRequest(
6033 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08006034
6035 if (success) {
6036 Settings.Global.putInt(mApp.getContentResolver(),
6037 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
6038 }
calvinpan089c2a62020-03-12 14:17:55 +08006039 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
6040 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006041 } finally {
6042 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07006043 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006044 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006045
6046 /**
calvinpan677fc2b2020-01-14 20:42:55 +08006047 * Get the allowed network types that store in the telephony provider.
6048 *
6049 * @param subId the id of the subscription.
6050 * @return allowedNetworkTypes the allowed network types.
6051 */
6052 @Override
6053 public long getAllowedNetworkTypes(int subId) {
6054 TelephonyPermissions
6055 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6056 mApp, subId, "getAllowedNetworkTypes");
6057
6058 final long identity = Binder.clearCallingIdentity();
6059 try {
6060 return SubscriptionManager.getLongSubscriptionProperty(
6061 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
6062 } finally {
6063 Binder.restoreCallingIdentity(identity);
6064 }
6065 }
6066
6067 /**
6068 * Set the allowed network types.
6069 *
6070 * @param subId the id of the subscription.
6071 * @param allowedNetworkTypes the allowed network types.
6072 * @return true on success; false on any failure.
6073 */
6074 @Override
6075 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
6076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6077 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08006078
calvinpan089c2a62020-03-12 14:17:55 +08006079 SubscriptionManager.setSubscriptionProperty(subId,
6080 SubscriptionManager.ALLOWED_NETWORK_TYPES,
6081 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08006082
calvinpan089c2a62020-03-12 14:17:55 +08006083 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6084 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6085 RILConstants.PREFERRED_NETWORK_MODE);
6086 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08006087 }
6088
6089 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006090 * Get the allowed network types for certain reason.
6091 *
6092 * @param subId the id of the subscription.
6093 * @param reason the reason the allowed network type change is taking place
6094 * @return the allowed network types.
6095 */
6096 @Override
6097 public long getAllowedNetworkTypesForReason(int subId,
6098 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6099 TelephonyPermissions
6100 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6101 mApp, subId, "getAllowedNetworkTypesForReason");
6102 final long identity = Binder.clearCallingIdentity();
6103 try {
6104 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6105 } finally {
6106 Binder.restoreCallingIdentity(identity);
6107 }
6108 }
6109
6110 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006111 * Enable/Disable E-UTRA-NR Dual Connectivity
6112 * @param subId subscription id of the sim card
6113 * @param nrDualConnectivityState expected NR dual connectivity state
6114 * This can be passed following states
6115 * <ol>
6116 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6117 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6118 * <li>Disable NR dual connectivity and force secondary cell to be released
6119 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6120 * </ol>
6121 * @return operation result.
6122 */
6123 @Override
6124 public int setNrDualConnectivityState(int subId,
6125 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6127 mApp, subId, "enableNRDualConnectivity");
6128 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6129 final long identity = Binder.clearCallingIdentity();
6130 try {
6131 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6132 nrDualConnectivityState, subId,
6133 workSource);
6134 if (DBG) log("enableNRDualConnectivity result: " + result);
6135 return result;
6136 } finally {
6137 Binder.restoreCallingIdentity(identity);
6138 }
6139 }
6140
6141 /**
6142 * Is E-UTRA-NR Dual Connectivity enabled
6143 * @return true if dual connectivity is enabled else false
6144 */
6145 @Override
6146 public boolean isNrDualConnectivityEnabled(int subId) {
6147 TelephonyPermissions
6148 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6149 mApp, subId, "isNRDualConnectivityEnabled");
6150 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6151 final long identity = Binder.clearCallingIdentity();
6152 try {
6153 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6154 null, subId, workSource);
6155 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6156 return isEnabled;
6157 } finally {
6158 Binder.restoreCallingIdentity(identity);
6159 }
6160 }
6161
6162 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006163 * get carrier bandwidth per primary and secondary carrier
6164 * @param subId subscription id of the sim card
6165 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6166 */
6167 @Override
6168 public CarrierBandwidth getCarrierBandwidth(int subId) {
6169 TelephonyPermissions
6170 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6171 mApp, subId, "isNRDualConnectivityEnabled");
6172 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6173 final long identity = Binder.clearCallingIdentity();
6174 try {
6175 CarrierBandwidth carrierBandwidth =
6176 getPhoneFromSubId(subId).getCarrierBandwidth();
6177 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6178 return carrierBandwidth;
6179 } finally {
6180 Binder.restoreCallingIdentity(identity);
6181 }
6182 }
6183
6184 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006185 * Get the effective allowed network types on the device.
6186 * This API will return an intersection of allowed network types for all reasons,
6187 * including the configuration done through setAllowedNetworkTypes
6188 *
6189 * @param subId the id of the subscription.
6190 * @return the allowed network types
6191 */
6192 @Override
6193 public long getEffectiveAllowedNetworkTypes(int subId) {
6194 TelephonyPermissions
6195 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6196 mApp, subId, "getEffectiveAllowedNetworkTypes");
6197 final long identity = Binder.clearCallingIdentity();
6198 try {
6199 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6200 } finally {
6201 Binder.restoreCallingIdentity(identity);
6202 }
6203 }
6204
6205 /**
6206 * Set the allowed network types of the device and
6207 * provide the reason triggering the allowed network change.
6208 *
6209 * @param subId the id of the subscription.
6210 * @param reason the reason the allowed network type change is taking place
6211 * @param allowedNetworkTypes the allowed network types.
6212 * @return true on success; false on any failure.
6213 */
6214 @Override
6215 public boolean setAllowedNetworkTypesForReason(int subId,
6216 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6217 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6218 mApp, subId, "setAllowedNetworkTypesForReason");
6219 final long identity = Binder.clearCallingIdentity();
6220 try {
6221 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6222 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6223 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6224 RILConstants.PREFERRED_NETWORK_MODE);
6225 return setPreferredNetworkType(subId, preferredNetworkMode);
6226 } finally {
6227 Binder.restoreCallingIdentity(identity);
6228 }
6229 }
6230
6231 /**
Miaoa84611c2019-03-15 09:21:10 +08006232 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006233 *
Miaoa84611c2019-03-15 09:21:10 +08006234 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006235 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006236 * @hide
6237 */
6238 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006239 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006240 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006241 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006242 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006243 try {
Miaoa84611c2019-03-15 09:21:10 +08006244 if (phone != null) {
6245 return phone.hasMatchedTetherApnSetting();
6246 } else {
6247 return false;
6248 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006249 } finally {
6250 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006251 }
Junda Liu475951f2014-11-07 16:45:03 -08006252 }
6253
6254 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006255 * Enable or disable always reporting signal strength changes from radio.
6256 *
6257 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6258 */
6259 @Override
6260 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6261 enforceModifyPermission();
6262 enforceSystemCaller();
6263
6264 final long identity = Binder.clearCallingIdentity();
6265 final Phone phone = getPhone(subId);
6266 try {
6267 if (phone != null) {
6268 if (DBG) {
6269 log("setAlwaysReportSignalStrength: subId=" + subId
6270 + " isEnable=" + isEnable);
6271 }
6272 phone.setAlwaysReportSignalStrength(isEnable);
6273 } else {
6274 loge("setAlwaysReportSignalStrength: no phone found for subId="
6275 + subId);
6276 }
6277 } finally {
6278 Binder.restoreCallingIdentity(identity);
6279 }
6280 }
6281
6282 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006283 * Get the user enabled state of Mobile Data.
6284 *
6285 * TODO: remove and use isUserDataEnabled.
6286 * This can't be removed now because some vendor codes
6287 * calls through ITelephony directly while they should
6288 * use TelephonyManager.
6289 *
6290 * @return true on enabled
6291 */
6292 @Override
6293 public boolean getDataEnabled(int subId) {
6294 return isUserDataEnabled(subId);
6295 }
6296
6297 /**
6298 * Get whether mobile data is enabled per user setting.
6299 *
6300 * There are other factors deciding whether mobile data is actually enabled, but they are
6301 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006302 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006303 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006304 *
6305 * @return {@code true} if data is enabled else {@code false}
6306 */
6307 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006308 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006309 try {
6310 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6311 null);
6312 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006313 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6314 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006315 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006316
6317 final long identity = Binder.clearCallingIdentity();
6318 try {
6319 int phoneId = mSubscriptionController.getPhoneId(subId);
6320 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6321 Phone phone = PhoneFactory.getPhone(phoneId);
6322 if (phone != null) {
6323 boolean retVal = phone.isUserDataEnabled();
6324 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6325 return retVal;
6326 } else {
6327 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6328 return false;
6329 }
6330 } finally {
6331 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006332 }
6333 }
6334
6335 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006336 * Checks if the device is capable of mobile data by considering whether whether the
6337 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6338 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006339 *
Shuo Qian985d1232020-01-08 14:30:06 -08006340 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006341 */
6342 @Override
6343 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006344 try {
6345 try {
6346 mApp.enforceCallingOrSelfPermission(
6347 android.Manifest.permission.ACCESS_NETWORK_STATE,
6348 null);
6349 } catch (Exception e) {
6350 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6351 "isDataEnabled");
6352 }
6353 } catch (Exception e) {
6354 enforceReadPrivilegedPermission("isDataEnabled");
6355 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006356
6357 final long identity = Binder.clearCallingIdentity();
6358 try {
6359 int phoneId = mSubscriptionController.getPhoneId(subId);
6360 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6361 Phone phone = PhoneFactory.getPhone(phoneId);
6362 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006363 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006364 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6365 return retVal;
6366 } else {
6367 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6368 return false;
6369 }
6370 } finally {
6371 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006372 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006373 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006374
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006375 /**
6376 * Check if data is enabled for a specific reason
6377 * @param subId Subscription index
6378 * @param reason the reason the data enable change is taking place
6379 * @return {@code true} if the overall data is enabled; {@code false} if not.
6380 */
6381 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006382 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006383 @TelephonyManager.DataEnabledReason int reason) {
6384 try {
6385 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6386 null);
6387 } catch (Exception e) {
6388 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006389 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006390 }
6391
6392
6393 final long identity = Binder.clearCallingIdentity();
6394 try {
6395 int phoneId = mSubscriptionController.getPhoneId(subId);
6396 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006397 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006398 + " reason=" + reason);
6399 }
6400 Phone phone = PhoneFactory.getPhone(phoneId);
6401 if (phone != null) {
6402 boolean retVal;
6403 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6404 retVal = phone.isUserDataEnabled();
6405 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006406 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006407 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006408 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006409 return retVal;
6410 } else {
6411 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006412 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006413 + subId + " retVal=false");
6414 }
6415 return false;
6416 }
6417 } finally {
6418 Binder.restoreCallingIdentity(identity);
6419 }
6420 }
6421
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006422 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006423 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006424 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6425 // Skip the check if it's one of these special uids
6426 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6427 }
6428
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006429 //load access rules from carrier configs, and check those as well: b/139133814
6430 SubscriptionController subController = SubscriptionController.getInstance();
6431 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6432 || subController == null) return privilegeFromSim;
6433
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006434 PackageManager pkgMgr = phone.getContext().getPackageManager();
6435 String[] packages = pkgMgr.getPackagesForUid(uid);
6436
6437 final long identity = Binder.clearCallingIdentity();
6438 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006439 int subId = phone.getSubId();
6440 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6441 // A test override is in place for the privileges for this subId, so don't try to
6442 // read the subscription privileges.
6443 return privilegeFromSim;
6444 }
6445 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006446 SubscriptionManager subManager = (SubscriptionManager)
6447 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6448 for (String pkg : packages) {
6449 if (subManager.canManageSubscription(subInfo, pkg)) {
6450 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6451 }
6452 }
6453 return privilegeFromSim;
6454 } finally {
6455 Binder.restoreCallingIdentity(identity);
6456 }
6457 }
6458
6459 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6460 String pkgName) {
6461 //load access rules from carrier configs, and check those as well: b/139133814
6462 SubscriptionController subController = SubscriptionController.getInstance();
6463 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6464 || subController == null) return privilegeFromSim;
6465
6466 final long identity = Binder.clearCallingIdentity();
6467 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006468 int subId = phone.getSubId();
6469 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6470 // A test override is in place for the privileges for this subId, so don't try to
6471 // read the subscription privileges.
6472 return privilegeFromSim;
6473 }
6474 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006475 SubscriptionManager subManager = (SubscriptionManager)
6476 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6477 return subManager.canManageSubscription(subInfo, pkgName)
6478 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6479 } finally {
6480 Binder.restoreCallingIdentity(identity);
6481 }
6482 }
6483
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006484 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006485 public int getCarrierPrivilegeStatus(int subId) {
6486 final Phone phone = getPhone(subId);
6487 if (phone == null) {
6488 loge("getCarrierPrivilegeStatus: Invalid subId");
6489 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6490 }
6491 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006492 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006493 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006494 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6495 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006496
6497 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6498 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006499 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006500 }
Junda Liu29340342014-07-10 15:23:27 -07006501
6502 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006503 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006504 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006505 final Phone phone = getPhone(subId);
6506 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006507 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006508 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6509 }
6510 UiccProfile profile =
6511 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6512 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006513 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006514 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6515 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006516 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006517 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006518 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006519 }
6520
6521 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006522 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6523 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006524 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006525 }
6526
6527 int phoneId = SubscriptionManager.getPhoneId(subId);
6528 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006529 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006530 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006531 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6532 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006533 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6534 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6535 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006536 }
6537
6538 @Override
6539 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006540 if (TextUtils.isEmpty(pkgName))
6541 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006542 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6543 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6544 UiccCard card = UiccController.getInstance().getUiccCard(i);
6545 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006546 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006547 continue;
6548 }
6549
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006550 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6551 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6552 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006553 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6554 break;
6555 }
6556 }
6557
6558 return result;
Junda Liu29340342014-07-10 15:23:27 -07006559 }
Derek Tan89e89d42014-07-08 17:00:10 -07006560
6561 @Override
Junda Liue64de782015-04-16 17:19:16 -07006562 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6563 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6564 loge("phoneId " + phoneId + " is not valid.");
6565 return null;
6566 }
6567 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006568 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006569 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006570 return null ;
6571 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006572 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006573 }
6574
Amith Yamasani6e118872016-02-19 12:53:51 -08006575 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006576 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006577 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006578 List<String> privilegedPackages = new ArrayList<>();
6579 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006580 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6581 // has UICC in that slot.
6582 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006583 if (card.hasCarrierPrivilegeRules()) {
6584 if (packages == null) {
6585 // Only check packages in user 0 for now
6586 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006587 PackageManager.MATCH_DISABLED_COMPONENTS
6588 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006589 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006590 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006591 }
6592 for (int p = packages.size() - 1; p >= 0; p--) {
6593 PackageInfo pkgInfo = packages.get(p);
6594 if (pkgInfo != null && pkgInfo.packageName != null
6595 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006596 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006597 privilegedPackages.add(pkgInfo.packageName);
6598 }
6599 }
6600 }
6601 }
6602 return privilegedPackages;
6603 }
6604
chen xuf7e9fe82019-05-09 19:31:02 -07006605 @Override
6606 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006607 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6608
6609 final long identity = Binder.clearCallingIdentity();
6610
chen xuf7e9fe82019-05-09 19:31:02 -07006611 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006612 try {
6613 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6614 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6615 }
6616 } finally {
6617 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006618 }
6619 return privilegedPackages;
6620 }
6621
Wink Savilleb564aae2014-10-23 10:18:09 -07006622 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006623 final Phone phone = getPhone(subId);
6624 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006625 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006626 return null;
6627 }
6628 String iccId = card.getIccId();
6629 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006630 return null;
6631 }
6632 return iccId;
6633 }
6634
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006635 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006636 public void setCallComposerStatus(int subId, int status) {
6637 enforceModifyPermission();
6638
6639 final long identity = Binder.clearCallingIdentity();
6640 try {
6641 Phone phone = getPhone(subId);
6642 if (phone != null) {
6643 Phone defaultPhone = phone.getImsPhone();
6644 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6645 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6646 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006647 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6648 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006649 }
6650 }
Shuo Qiand8782462020-12-22 19:10:14 -08006651 } catch (ImsException e) {
6652 throw new ServiceSpecificException(e.getCode());
6653 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006654 Binder.restoreCallingIdentity(identity);
6655 }
6656 }
6657
6658 @Override
6659 public int getCallComposerStatus(int subId) {
6660 enforceReadPrivilegedPermission("getCallComposerStatus");
6661
6662 final long identity = Binder.clearCallingIdentity();
6663 try {
6664 Phone phone = getPhone(subId);
6665 if (phone != null) {
6666 Phone defaultPhone = phone.getImsPhone();
6667 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6668 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6669 return imsPhone.getCallComposerStatus();
6670 }
6671 }
6672 } finally {
6673 Binder.restoreCallingIdentity(identity);
6674 }
6675 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6676 }
6677
6678 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006679 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6680 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006681 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006682 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006683
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006684 final long identity = Binder.clearCallingIdentity();
6685 try {
6686 final String iccId = getIccId(subId);
6687 final Phone phone = getPhone(subId);
6688 if (phone == null) {
6689 return false;
6690 }
6691 final String subscriberId = phone.getSubscriberId();
6692
6693 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006694 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006695 + subscriberId + " to " + number);
6696 }
6697
6698 if (TextUtils.isEmpty(iccId)) {
6699 return false;
6700 }
6701
6702 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6703
6704 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6705 if (alphaTag == null) {
6706 editor.remove(alphaTagPrefKey);
6707 } else {
6708 editor.putString(alphaTagPrefKey, alphaTag);
6709 }
6710
6711 // Record both the line number and IMSI for this ICCID, since we need to
6712 // track all merged IMSIs based on line number
6713 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6714 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6715 if (number == null) {
6716 editor.remove(numberPrefKey);
6717 editor.remove(subscriberPrefKey);
6718 } else {
6719 editor.putString(numberPrefKey, number);
6720 editor.putString(subscriberPrefKey, subscriberId);
6721 }
6722
6723 editor.commit();
6724 return true;
6725 } finally {
6726 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006727 }
Derek Tan7226c842014-07-02 17:42:23 -07006728 }
6729
6730 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006731 public String getLine1NumberForDisplay(int subId, String callingPackage,
6732 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006733 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006734 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006735 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006736 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006737 return null;
6738 }
Derek Tan97ebb422014-09-05 16:55:38 -07006739
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006740 final long identity = Binder.clearCallingIdentity();
6741 try {
6742 String iccId = getIccId(subId);
6743 if (iccId != null) {
6744 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6745 if (DBG_MERGE) {
6746 log("getLine1NumberForDisplay returning "
6747 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6748 }
6749 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006750 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006751 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6752 return null;
6753 } finally {
6754 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006755 }
Derek Tan7226c842014-07-02 17:42:23 -07006756 }
6757
6758 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006759 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6760 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006761 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006762 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006763 return null;
6764 }
Derek Tan97ebb422014-09-05 16:55:38 -07006765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006766 final long identity = Binder.clearCallingIdentity();
6767 try {
6768 String iccId = getIccId(subId);
6769 if (iccId != null) {
6770 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6771 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6772 }
6773 return null;
6774 } finally {
6775 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006776 }
Derek Tan7226c842014-07-02 17:42:23 -07006777 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006778
6779 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006780 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6781 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006782 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6783 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006784 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006785 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006786 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006787 return null;
6788 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006789
Jordan Liub49b04b2019-05-06 14:45:15 -07006790 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6791 // the process, where TelephonyManager was instantiated.
6792 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006793 final long identity = Binder.clearCallingIdentity();
6794 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006795 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006796 final TelephonyManager tele = TelephonyManager.from(context);
6797 final SubscriptionManager sub = SubscriptionManager.from(context);
6798
6799 // Figure out what subscribers are currently active
6800 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006801
Jordan Liub49b04b2019-05-06 14:45:15 -07006802 // Only consider subs which match the current subId
6803 // This logic can be simplified. See b/131189269 for progress.
6804 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006805 activeSubscriberIds.add(tele.getSubscriberId(subId));
6806 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006807
6808 // First pass, find a number override for an active subscriber
6809 String mergeNumber = null;
6810 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6811 for (String key : prefs.keySet()) {
6812 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6813 final String subscriberId = (String) prefs.get(key);
6814 if (activeSubscriberIds.contains(subscriberId)) {
6815 final String iccId = key.substring(
6816 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6817 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6818 mergeNumber = (String) prefs.get(numberKey);
6819 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006820 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006821 + " for active subscriber " + subscriberId);
6822 }
6823 if (!TextUtils.isEmpty(mergeNumber)) {
6824 break;
6825 }
6826 }
6827 }
6828 }
6829
6830 // Shortcut when no active merged subscribers
6831 if (TextUtils.isEmpty(mergeNumber)) {
6832 return null;
6833 }
6834
6835 // Second pass, find all subscribers under that line override
6836 final ArraySet<String> result = new ArraySet<>();
6837 for (String key : prefs.keySet()) {
6838 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6839 final String number = (String) prefs.get(key);
6840 if (mergeNumber.equals(number)) {
6841 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6842 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6843 final String subscriberId = (String) prefs.get(subscriberKey);
6844 if (!TextUtils.isEmpty(subscriberId)) {
6845 result.add(subscriberId);
6846 }
6847 }
6848 }
6849 }
6850
6851 final String[] resultArray = result.toArray(new String[result.size()]);
6852 Arrays.sort(resultArray);
6853 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006854 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006855 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6856 }
6857 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006858 } finally {
6859 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006860 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006861 }
6862
6863 @Override
zoey chen38003472019-12-13 17:16:31 +08006864 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6865 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006866
6867 final long identity = Binder.clearCallingIdentity();
6868 try {
6869 final TelephonyManager telephonyManager = mApp.getSystemService(
6870 TelephonyManager.class);
6871 String subscriberId = telephonyManager.getSubscriberId(subId);
6872 if (subscriberId == null) {
6873 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006874 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006875 + subId);
6876 }
6877 return null;
6878 }
6879
6880 final SubscriptionInfo info = SubscriptionController.getInstance()
6881 .getSubscriptionInfo(subId);
6882 final ParcelUuid groupUuid = info.getGroupUuid();
6883 // If it doesn't belong to any group, return just subscriberId of itself.
6884 if (groupUuid == null) {
6885 return new String[]{subscriberId};
6886 }
6887
6888 // Get all subscriberIds from the group.
6889 final List<String> mergedSubscriberIds = new ArrayList<>();
6890 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006891 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006892 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006893 for (SubscriptionInfo subInfo : groupInfos) {
6894 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6895 if (subscriberId != null) {
6896 mergedSubscriberIds.add(subscriberId);
6897 }
6898 }
6899
6900 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6901 } finally {
6902 Binder.restoreCallingIdentity(identity);
6903
6904 }
6905 }
6906
6907 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006908 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006909 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006910 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006911
6912 final long identity = Binder.clearCallingIdentity();
6913 try {
6914 final Phone phone = getPhone(subId);
6915 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6916 } finally {
6917 Binder.restoreCallingIdentity(identity);
6918 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006919 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006920
6921 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006922 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006923 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6924 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006925 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6926 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006927
6928 final long identity = Binder.clearCallingIdentity();
6929 try {
6930 final Phone phone = getPhone(subId);
6931 if (phone == null) {
6932 return false;
6933 }
6934 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6935 cdmaNonRoamingList);
6936 } finally {
6937 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006938 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006939 }
6940
6941 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006942 @Deprecated
6943 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6944 enforceModifyPermission();
6945
6946 int returnValue = 0;
6947 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006948 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006949 if(result.exception == null) {
6950 if (result.result != null) {
6951 byte[] responseData = (byte[])(result.result);
6952 if(responseData.length > oemResp.length) {
6953 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6954 responseData.length + "bytes. Buffer Size is " +
6955 oemResp.length + "bytes.");
6956 }
6957 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6958 returnValue = responseData.length;
6959 }
6960 } else {
6961 CommandException ex = (CommandException) result.exception;
6962 returnValue = ex.getCommandError().ordinal();
6963 if(returnValue > 0) returnValue *= -1;
6964 }
6965 } catch (RuntimeException e) {
6966 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6967 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6968 if(returnValue > 0) returnValue *= -1;
6969 }
6970
6971 return returnValue;
6972 }
6973
6974 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006975 public void setRadioCapability(RadioAccessFamily[] rafs) {
6976 try {
6977 ProxyController.getInstance().setRadioCapability(rafs);
6978 } catch (RuntimeException e) {
6979 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6980 }
6981 }
6982
6983 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006984 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006985 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006986 try {
6987 TelephonyPermissions
6988 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6989 mApp, phone.getSubId(), "getRadioAccessFamily");
6990 } catch (SecurityException e) {
6991 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6992 throw e;
6993 }
chen xub97461a2018-10-26 14:17:57 -07006994 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006995 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006996 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006998 final long identity = Binder.clearCallingIdentity();
6999 try {
chen xub97461a2018-10-26 14:17:57 -07007000 TelephonyPermissions
7001 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7002 mApp, phone.getSubId(), "getRadioAccessFamily");
7003 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007004 } finally {
7005 Binder.restoreCallingIdentity(identity);
7006 }
chen xub97461a2018-10-26 14:17:57 -07007007 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007008 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007009
7010 @Override
7011 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007012 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007013 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007014
7015 final long identity = Binder.clearCallingIdentity();
7016 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007017 ImsManager.getInstance(defaultPhone.getContext(),
7018 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019 } finally {
7020 Binder.restoreCallingIdentity(identity);
7021 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007022 }
7023
7024 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007025 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007026 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007027 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7028 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007029 return false;
7030 }
Svet Ganovb320e182015-04-16 12:30:10 -07007031
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007032 final long identity = Binder.clearCallingIdentity();
7033 try {
7034 // Check the user preference and the system-level IMS setting. Even if the user has
7035 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7036 // In the long run, we may instead need to check if there exists a connection service
7037 // which can support video calling.
7038 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007039 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007040 return imsManager.isVtEnabledByPlatform()
7041 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7042 && imsManager.isVtEnabledByUser();
7043 } finally {
7044 Binder.restoreCallingIdentity(identity);
7045 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007046 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007047
Andrew Leea1239f22015-03-02 17:44:07 -08007048 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007049 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7050 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007052 mApp, subId, callingPackage, callingFeatureId,
7053 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007054 return false;
7055 }
7056
7057 final long identity = Binder.clearCallingIdentity();
7058 try {
7059 CarrierConfigManager configManager =
7060 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007061 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007062 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7063 } finally {
7064 Binder.restoreCallingIdentity(identity);
7065 }
Andrew Leea1239f22015-03-02 17:44:07 -08007066 }
7067
7068 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007069 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007070 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007071 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072 return false;
7073 }
7074
7075 final long identity = Binder.clearCallingIdentity();
7076 try {
7077 CarrierConfigManager configManager =
7078 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007079 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7081 } finally {
7082 Binder.restoreCallingIdentity(identity);
7083 }
Andrew Leea1239f22015-03-02 17:44:07 -08007084 }
7085
Andrew Lee9431b832015-03-09 18:46:45 -07007086 @Override
7087 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007088 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007089 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007090 }
7091
7092 @Override
7093 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007094 final long identity = Binder.clearCallingIdentity();
7095 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007096 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007097 } finally {
7098 Binder.restoreCallingIdentity(identity);
7099 }
Andrew Lee9431b832015-03-09 18:46:45 -07007100 }
7101
Hall Liuf6668912018-10-31 17:05:23 -07007102 /**
7103 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7104 * support for the feature and device firmware support.
7105 *
7106 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7107 */
7108 @Override
7109 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007110 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007111 final Phone phone = getPhone(subscriptionId);
7112 if (phone == null) {
7113 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7114 return false;
7115 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007116 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007117 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007118 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7119 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007120 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007121 return isCarrierSupported && isDeviceSupported;
7122 } finally {
7123 Binder.restoreCallingIdentity(identity);
7124 }
Hall Liu98187582018-01-22 19:15:32 -08007125 }
7126
Hall Liuf6668912018-10-31 17:05:23 -07007127 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007128 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7129 * RTT setting, will return true if the device and carrier both support RTT.
7130 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007131 */
7132 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007133 final long identity = Binder.clearCallingIdentity();
7134 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007135 boolean isRttSupported = isRttSupported(subscriptionId);
7136 boolean isUserRttSettingOn = Settings.Secure.getInt(
7137 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7138 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7139 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7140 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141 } finally {
7142 Binder.restoreCallingIdentity(identity);
7143 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007144 }
7145
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007146 @Deprecated
7147 @Override
7148 public String getDeviceId(String callingPackage) {
7149 return getDeviceIdWithFeature(callingPackage, null);
7150 }
7151
Sanket Padawe7310cc72015-01-14 09:53:20 -08007152 /**
7153 * Returns the unique device ID of phone, for example, the IMEI for
7154 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7155 *
7156 * <p>Requires Permission:
7157 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7158 */
7159 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007160 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007161 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007162 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007163 return null;
7164 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007165 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007166 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007167 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007168 return null;
7169 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007170
7171 final long identity = Binder.clearCallingIdentity();
7172 try {
7173 return phone.getDeviceId();
7174 } finally {
7175 Binder.restoreCallingIdentity(identity);
7176 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007177 }
7178
Ping Sunc67b7c22016-03-02 19:16:45 +08007179 /**
7180 * {@hide}
7181 * Returns the IMS Registration Status on a particular subid
7182 *
7183 * @param subId
7184 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007185 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007186 Phone phone = getPhone(subId);
7187 if (phone != null) {
7188 return phone.isImsRegistered();
7189 } else {
7190 return false;
7191 }
7192 }
7193
Santos Cordon7a1885b2015-02-03 11:15:19 -08007194 @Override
7195 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196 final long identity = Binder.clearCallingIdentity();
7197 try {
7198 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7199 } finally {
7200 Binder.restoreCallingIdentity(identity);
7201 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007202 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007203
Tyler Gunnf70ed162019-04-03 15:28:53 -07007204 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007205 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007206 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007207 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007208 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007209 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7210 }
7211 final long identity = Binder.clearCallingIdentity();
7212 try {
7213 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7214 } finally {
7215 Binder.restoreCallingIdentity(identity);
7216 }
7217 }
7218
7219 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007220 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007221 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7222 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007223 final long identity = Binder.clearCallingIdentity();
7224 try {
7225 Phone phone = getPhone(subscriptionId);
7226 if (phone == null) {
7227 return null;
7228 }
7229 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7230 } finally {
7231 Binder.restoreCallingIdentity(identity);
7232 }
7233 }
7234
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007235 /**
7236 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007237 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007238 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007239 final long identity = Binder.clearCallingIdentity();
7240 try {
7241 Phone phone = getPhone(subId);
7242 if (phone != null) {
7243 return phone.isWifiCallingEnabled();
7244 } else {
7245 return false;
7246 }
7247 } finally {
7248 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007249 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007250 }
7251
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007252 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007253 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007254 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007255 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007256 final long identity = Binder.clearCallingIdentity();
7257 try {
7258 Phone phone = getPhone(subId);
7259 if (phone != null) {
7260 return phone.isVideoEnabled();
7261 } else {
7262 return false;
7263 }
7264 } finally {
7265 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007266 }
7267 }
7268
7269 /**
7270 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7271 * defined in {@link ImsRegistrationImplBase}.
7272 */
7273 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007274 final long identity = Binder.clearCallingIdentity();
7275 try {
7276 Phone phone = getPhone(subId);
7277 if (phone != null) {
7278 return phone.getImsRegistrationTech();
7279 } else {
7280 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7281 }
7282 } finally {
7283 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007284 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007285 }
7286
Stuart Scott8eef64f2015-04-08 15:13:54 -07007287 @Override
7288 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007289 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007290 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7291 return;
7292 }
7293
Svet Ganovcc087f82015-05-12 20:35:54 -07007294 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007295
Svet Ganovcc087f82015-05-12 20:35:54 -07007296 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007297 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7298 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007299 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007300 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007301 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007302 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007303 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7304 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007305 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007306 // There has been issues when Sms raw table somehow stores orphan
7307 // fragments. They lead to garbled message when new fragments come
7308 // in and combined with those stale ones. In case this happens again,
7309 // user can reset all network settings which will clean up this table.
7310 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007311 // Clean up IMS settings as well here.
7312 int slotId = getSlotIndex(subId);
7313 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7314 ImsManager.getInstance(mApp, slotId).factoryReset();
7315 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007316
7317 // Erase modem config if erase modem on network setting is enabled.
7318 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7319 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7320 if (configValue != null && Boolean.parseBoolean(configValue)) {
7321 sendEraseModemConfig(getDefaultPhone());
7322 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007323 } finally {
7324 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007325 }
7326 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007327
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007328 private void cleanUpSmsRawTable(Context context) {
7329 ContentResolver resolver = context.getContentResolver();
7330 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7331 resolver.delete(uri, null, null);
7332 }
7333
Narayan Kamath1c496c22015-04-16 14:40:19 +01007334 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007335 public String getSimLocaleForSubscriber(int subId) {
7336 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7337 final Phone phone = getPhone(subId);
7338 if (phone == null) {
7339 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007340 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007341 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007342 final long identity = Binder.clearCallingIdentity();
7343 try {
chen xu5d3637b2019-01-21 23:31:38 -08007344 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007345 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007346 if (info == null) {
7347 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7348 return null;
7349 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007350 // Try and fetch the locale from the carrier properties or from the SIM language
7351 // preferences (EF-PL and EF-LI)...
7352 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007353 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007354 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7355 if (localeFromDefaultSim != null) {
7356 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7357 if (DBG) log("Using locale from subId: " + subId + " locale: "
7358 + localeFromDefaultSim);
7359 return localeFromDefaultSim.toLanguageTag();
7360 } else {
7361 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007362 }
7363 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007365 // The SIM language preferences only store a language (e.g. fr = French), not an
7366 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7367 // the SIM and carrier preferences does not include a country we add the country
7368 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007369 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007370 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007371 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372 return mccLocale.toLanguageTag();
7373 }
7374
7375 if (DBG) log("No locale found - returning null");
7376 return null;
7377 } finally {
7378 Binder.restoreCallingIdentity(identity);
7379 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007380 }
7381
7382 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007383 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007384 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007385 }
7386
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007387 /**
7388 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7389 */
7390 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007391 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007392 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007393 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007394
Chenjie Yu1ba97252018-01-11 18:16:20 -08007395 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007396 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007397
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007398 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007399 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7400 * representing the state of the modem.
7401 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007402 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7403 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007404 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007405 */
7406 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007407 public void requestModemActivityInfo(ResultReceiver result) {
7408 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007409 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007410
7411 final long identity = Binder.clearCallingIdentity();
7412 try {
sqian1a1be542020-03-05 11:37:28 -08007413 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007414 } finally {
7415 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007416 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007417 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007418
Siddharth Rayb8114062018-06-17 15:02:38 -07007419 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7420 // less than total activity duration.
7421 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7422 if (info == null) {
7423 return false;
7424 }
7425 int activityDurationMs =
7426 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7427 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007428 int[] txTimeMs = info.getTransmitTimeMillis();
7429 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7430 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007431 }
7432 return (info.isValid()
7433 && (info.getSleepTimeMillis() <= activityDurationMs)
7434 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007435 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007436 && (totalTxTimeMs <= activityDurationMs));
7437 }
7438
Jack Yu85bd38a2015-11-09 11:34:32 -08007439 /**
7440 * {@hide}
7441 * Returns the service state information on specified subscription.
7442 */
7443 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007444 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7445 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007446 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007447 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007448 return null;
7449 }
7450
Hall Liuf19c44f2018-11-27 14:38:17 -08007451 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7452 LocationAccessPolicy.checkLocationPermission(mApp,
7453 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7454 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007455 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007456 .setCallingPid(Binder.getCallingPid())
7457 .setCallingUid(Binder.getCallingUid())
7458 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007459 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007460 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7461 .build());
7462
7463 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7464 LocationAccessPolicy.checkLocationPermission(mApp,
7465 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7466 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007467 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007468 .setCallingPid(Binder.getCallingPid())
7469 .setCallingUid(Binder.getCallingUid())
7470 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007471 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007472 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7473 .build());
7474 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7475 boolean hasFinePermission =
7476 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7477 boolean hasCoarsePermission =
7478 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480 final long identity = Binder.clearCallingIdentity();
7481 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007482 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7483 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7484 Rlog.d(LOG_TAG,
7485 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7486 return null;
7487 }
7488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489 final Phone phone = getPhone(subId);
7490 if (phone == null) {
7491 return null;
7492 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007493
Hall Liuf19c44f2018-11-27 14:38:17 -08007494 ServiceState ss = phone.getServiceState();
7495
7496 // Scrub out the location info in ServiceState depending on what level of access
7497 // the caller has.
7498 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007499 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7500 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007501 } finally {
7502 Binder.restoreCallingIdentity(identity);
7503 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007504 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007505
7506 /**
7507 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7508 *
7509 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7510 * voicemail ringtone.
7511 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7512 * PhoneAccount.
7513 */
7514 @Override
7515 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007516 final long identity = Binder.clearCallingIdentity();
7517 try {
7518 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7519 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007520 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7524 } finally {
7525 Binder.restoreCallingIdentity(identity);
7526 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007527 }
7528
7529 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007530 * Sets the per-account voicemail ringtone.
7531 *
7532 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7533 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7534 *
7535 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7536 * voicemail ringtone.
7537 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7538 * PhoneAccount.
7539 */
7540 @Override
7541 public void setVoicemailRingtoneUri(String callingPackage,
7542 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007543 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007544 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007545 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7546 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7548 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7549 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007550 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007551
7552 final long identity = Binder.clearCallingIdentity();
7553 try {
7554 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7555 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007556 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007557 }
7558 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7559 } finally {
7560 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007561 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007562 }
7563
7564 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007565 * Returns whether vibration is set for voicemail notification in Phone settings.
7566 *
7567 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7568 * voicemail vibration setting.
7569 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7570 */
7571 @Override
7572 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007573 final long identity = Binder.clearCallingIdentity();
7574 try {
7575 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7576 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007577 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007578 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007579
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007580 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7581 } finally {
7582 Binder.restoreCallingIdentity(identity);
7583 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007584 }
7585
Youhan Wange64578a2016-05-02 15:32:42 -07007586 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007587 * Sets the per-account voicemail vibration.
7588 *
7589 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7590 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7591 *
7592 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7593 * voicemail vibration setting.
7594 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7595 * specific PhoneAccount.
7596 */
7597 @Override
7598 public void setVoicemailVibrationEnabled(String callingPackage,
7599 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007600 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007601 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007602 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7603 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7605 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7606 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007607 }
7608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007609 final long identity = Binder.clearCallingIdentity();
7610 try {
7611 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7612 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007613 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007614 }
7615 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7616 } finally {
7617 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007618 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007619 }
7620
7621 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007622 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7623 *
7624 * @throws SecurityException if the caller does not have the required permission
7625 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007626 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007627 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007628 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007629 }
7630
7631 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007632 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7633 * permission.
7634 *
7635 * @throws SecurityException if the caller does not have the required permission
7636 */
7637 private void enforceSendSmsPermission() {
7638 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7639 }
7640
7641 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007642 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007643 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007644 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007645 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007646 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007647 final long identity = Binder.clearCallingIdentity();
7648 try {
7649 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007650 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007651 if (componentName == null) {
7652 throw new SecurityException(
7653 "Caller not current active visual voicemail package[null]");
7654 }
7655 String vvmPackage = componentName.getPackageName();
7656 if (!callingPackage.equals(vvmPackage)) {
7657 throw new SecurityException("Caller not current active visual voicemail package["
7658 + vvmPackage + "]");
7659 }
7660 } finally {
7661 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007662 }
7663 }
7664
7665 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007666 * Return the application ID for the app type.
7667 *
7668 * @param subId the subscription ID that this request applies to.
7669 * @param appType the uicc app type.
7670 * @return Application ID for specificied app type, or null if no uicc.
7671 */
7672 @Override
7673 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007674 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007675 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007676
7677 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007678 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007679 if (phone == null) {
7680 return null;
7681 }
7682 String aid = null;
7683 try {
7684 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7685 .getApplicationByType(appType).getAid();
7686 } catch (Exception e) {
7687 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7688 }
7689 return aid;
7690 } finally {
7691 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007692 }
Youhan Wange64578a2016-05-02 15:32:42 -07007693 }
7694
Youhan Wang4001d252016-05-11 10:29:41 -07007695 /**
7696 * Return the Electronic Serial Number.
7697 *
7698 * @param subId the subscription ID that this request applies to.
7699 * @return ESN or null if error.
7700 */
7701 @Override
7702 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007703 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007704 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007705
7706 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007707 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007708 if (phone == null) {
7709 return null;
7710 }
7711 String esn = null;
7712 try {
7713 esn = phone.getEsn();
7714 } catch (Exception e) {
7715 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7716 }
7717 return esn;
7718 } finally {
7719 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007720 }
Youhan Wang4001d252016-05-11 10:29:41 -07007721 }
7722
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007723 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007724 * Return the Preferred Roaming List Version.
7725 *
7726 * @param subId the subscription ID that this request applies to.
7727 * @return PRLVersion or null if error.
7728 */
7729 @Override
7730 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007731 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007732 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007733
7734 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007735 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007736 if (phone == null) {
7737 return null;
7738 }
7739 String cdmaPrlVersion = null;
7740 try {
7741 cdmaPrlVersion = phone.getCdmaPrlVersion();
7742 } catch (Exception e) {
7743 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7744 }
7745 return cdmaPrlVersion;
7746 } finally {
7747 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007748 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007749 }
7750
7751 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007752 * Get snapshot of Telephony histograms
7753 * @return List of Telephony histograms
7754 * @hide
7755 */
7756 @Override
7757 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7759 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007760
7761 final long identity = Binder.clearCallingIdentity();
7762 try {
7763 return RIL.getTelephonyRILTimingHistograms();
7764 } finally {
7765 Binder.restoreCallingIdentity(identity);
7766 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007767 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007768
7769 /**
7770 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007771 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7772 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007773 * Require system privileges. In the future we may add this to carrier APIs.
7774 *
Michele Berionne482f8202018-11-27 18:57:59 -08007775 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007776 */
7777 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007778 @TelephonyManager.SetCarrierRestrictionResult
7779 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007780 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007781 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007782
Michele Berionne482f8202018-11-27 18:57:59 -08007783 if (carrierRestrictionRules == null) {
7784 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007785 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007787 final long identity = Binder.clearCallingIdentity();
7788 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007789 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007790 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007791 } finally {
7792 Binder.restoreCallingIdentity(identity);
7793 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007794 }
7795
7796 /**
7797 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007798 * Get the allowed carrier list and the excluded carrier list, including the priority between
7799 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007800 * Require system privileges. In the future we may add this to carrier APIs.
7801 *
Michele Berionne482f8202018-11-27 18:57:59 -08007802 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007803 */
7804 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007805 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007806 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007807 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007808
7809 final long identity = Binder.clearCallingIdentity();
7810 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007811 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7812 if (response instanceof CarrierRestrictionRules) {
7813 return (CarrierRestrictionRules) response;
7814 }
7815 // Response is an Exception of some kind,
7816 // which is signalled to the user as a NULL retval
7817 return null;
7818 } catch (Exception e) {
7819 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7820 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007821 } finally {
7822 Binder.restoreCallingIdentity(identity);
7823 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007824 }
7825
fionaxu59545b42016-05-25 15:53:37 -07007826 /**
fionaxu59545b42016-05-25 15:53:37 -07007827 * Action set from carrier signalling broadcast receivers to enable/disable radio
7828 * @param subId the subscription ID that this action applies to.
7829 * @param enabled control enable or disable radio.
7830 * {@hide}
7831 */
7832 @Override
7833 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7834 enforceModifyPermission();
7835 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007836
7837 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007838 if (phone == null) {
7839 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7840 return;
7841 }
7842 try {
7843 phone.carrierActionSetRadioEnabled(enabled);
7844 } catch (Exception e) {
7845 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007846 } finally {
7847 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007848 }
7849 }
7850
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007851 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007852 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7853 * network status based on which carrier apps could apply actions accordingly,
7854 * enable/disable default url handler for example.
7855 *
7856 * @param subId the subscription ID that this action applies to.
7857 * @param report control start/stop reporting the default network status.
7858 * {@hide}
7859 */
7860 @Override
7861 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7862 enforceModifyPermission();
7863 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007864
7865 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007866 if (phone == null) {
7867 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7868 return;
7869 }
7870 try {
7871 phone.carrierActionReportDefaultNetworkStatus(report);
7872 } catch (Exception e) {
7873 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007874 } finally {
7875 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007876 }
7877 }
7878
7879 /**
fionaxud9622282017-07-17 17:51:30 -07007880 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7881 * @param subId the subscription ID that this action applies to.
7882 * {@hide}
7883 */
7884 @Override
7885 public void carrierActionResetAll(int subId) {
7886 enforceModifyPermission();
7887 final Phone phone = getPhone(subId);
7888 if (phone == null) {
7889 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7890 return;
7891 }
7892 try {
7893 phone.carrierActionResetAll();
7894 } catch (Exception e) {
7895 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7896 }
7897 }
7898
7899 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007900 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7901 * bug report is being generated.
7902 */
7903 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007904 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007905 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7906 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007907 writer.println("Permission Denial: can't dump Phone from pid="
7908 + Binder.getCallingPid()
7909 + ", uid=" + Binder.getCallingUid()
7910 + "without permission "
7911 + android.Manifest.permission.DUMP);
7912 return;
7913 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007914 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007915 }
Jack Yueb89b242016-06-22 13:27:47 -07007916
Brad Ebingerdac2f002018-04-03 15:17:52 -07007917 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007918 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7919 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7920 @NonNull String[] args) {
7921 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7922 this, in.getFileDescriptor(), out.getFileDescriptor(),
7923 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007924 }
7925
Jack Yueb89b242016-06-22 13:27:47 -07007926 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007927 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007928 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007929 * @param reason the reason the data enable change is taking place
7930 * @param enabled True if enabling the data, otherwise disabling.
7931 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007932 */
7933 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007934 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007935 boolean enabled) {
7936 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7937 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7938 try {
7939 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007940 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007941 } catch (SecurityException se) {
7942 enforceModifyPermission();
7943 }
7944 } else {
7945 enforceModifyPermission();
7946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007947
7948 final long identity = Binder.clearCallingIdentity();
7949 try {
7950 Phone phone = getPhone(subId);
7951 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007952 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7953 phone.carrierActionSetMeteredApnsEnabled(enabled);
7954 } else {
7955 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007957 }
7958 } finally {
7959 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007960 }
7961 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007962
7963 /**
7964 * Get Client request stats
7965 * @return List of Client Request Stats
7966 * @hide
7967 */
7968 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007969 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7970 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007971 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007972 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007973 return null;
7974 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007975 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007976
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007977 final long identity = Binder.clearCallingIdentity();
7978 try {
7979 if (phone != null) {
7980 return phone.getClientRequestStats();
7981 }
7982
7983 return null;
7984 } finally {
7985 Binder.restoreCallingIdentity(identity);
7986 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007987 }
7988
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007989 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007990 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007991 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007992 }
Jack Yueb4124c2017-02-16 15:32:43 -08007993
7994 /**
Grace Chen70990072017-03-24 17:21:30 -07007995 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007996 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007997 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007998 * @param state State of SIM (power down, power up, pass through)
7999 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8000 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8001 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008002 *
8003 **/
8004 @Override
Grace Chen70990072017-03-24 17:21:30 -07008005 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008006 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008007 Phone phone = PhoneFactory.getPhone(slotIndex);
8008
vagdeviaf9a5b92018-08-15 16:01:53 -07008009 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8010
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008011 final long identity = Binder.clearCallingIdentity();
8012 try {
8013 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08008014 phone.setSimPowerState(state, null, workSource);
8015 }
8016 } finally {
8017 Binder.restoreCallingIdentity(identity);
8018 }
8019 }
8020
8021 /**
8022 * Set SIM card power state.
8023 *
8024 * @param slotIndex SIM slot id.
8025 * @param state State of SIM (power down, power up, pass through)
8026 * @param callback callback to trigger after success or failure
8027 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8028 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8029 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8030 *
8031 **/
8032 @Override
8033 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8034 IIntegerConsumer callback) {
8035 enforceModifyPermission();
8036 Phone phone = PhoneFactory.getPhone(slotIndex);
8037
8038 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8039
8040 final long identity = Binder.clearCallingIdentity();
8041 try {
8042 if (phone != null) {
8043 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8044 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008045 }
8046 } finally {
8047 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008048 }
8049 }
Shuo Qiandd210312017-04-12 22:11:33 +00008050
Tyler Gunn65d45c22017-06-05 11:22:26 -07008051 private boolean isUssdApiAllowed(int subId) {
8052 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008053 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008054 if (configManager == null) {
8055 return false;
8056 }
8057 PersistableBundle pb = configManager.getConfigForSubId(subId);
8058 if (pb == null) {
8059 return false;
8060 }
8061 return pb.getBoolean(
8062 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8063 }
8064
Shuo Qiandd210312017-04-12 22:11:33 +00008065 /**
8066 * Check if phone is in emergency callback mode
8067 * @return true if phone is in emergency callback mode
8068 * @param subId sub id
8069 */
goneil9c5f4872017-12-05 14:07:56 -08008070 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008071 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008072 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008073 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008074
8075 final long identity = Binder.clearCallingIdentity();
8076 try {
8077 if (phone != null) {
8078 return phone.isInEcm();
8079 } else {
8080 return false;
8081 }
8082 } finally {
8083 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008084 }
8085 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008086
8087 /**
8088 * Get the current signal strength information for the given subscription.
8089 * Because this information is not updated when the device is in a low power state
8090 * it should not be relied-upon to be current.
8091 * @param subId Subscription index
8092 * @return the most recent cached signal strength info from the modem
8093 */
8094 @Override
8095 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008096 final long identity = Binder.clearCallingIdentity();
8097 try {
8098 Phone p = getPhone(subId);
8099 if (p == null) {
8100 return null;
8101 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008102
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008103 return p.getSignalStrength();
8104 } finally {
8105 Binder.restoreCallingIdentity(identity);
8106 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008107 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008108
Pengquan Meng77b7f132018-08-22 14:49:57 -07008109 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008110 * Get the current modem radio state for the given slot.
8111 * @param slotIndex slot index.
8112 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008113 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008114 * @return the current radio power state from the modem
8115 */
8116 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008117 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008118 Phone phone = PhoneFactory.getPhone(slotIndex);
8119 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008120 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8121 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008122 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8123 }
8124
8125 final long identity = Binder.clearCallingIdentity();
8126 try {
8127 return phone.getRadioPowerState();
8128 } finally {
8129 Binder.restoreCallingIdentity(identity);
8130 }
8131 }
8132 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8133 }
8134
8135 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008136 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8137 *
8138 * <p>Requires one of the following permissions:
8139 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8140 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8141 * privileges.
8142 *
8143 * @param subId subscription id
8144 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8145 * {@code false}.
8146 */
8147 @Override
8148 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008149 try {
8150 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8151 null);
8152 } catch (Exception e) {
8153 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8154 mApp, subId, "isDataRoamingEnabled");
8155 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008156
Pengquan Menga1bb6272018-09-06 09:59:22 -07008157 boolean isEnabled = false;
8158 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008159 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008160 Phone phone = getPhone(subId);
8161 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008162 } finally {
8163 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008164 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008165 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008166 }
8167
8168
8169 /**
8170 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8171 *
8172 * <p> Requires permission:
8173 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8174 * privileges.
8175 *
8176 * @param subId subscription id
8177 * @param isEnabled {@code true} means enable, {@code false} means disable.
8178 */
8179 @Override
8180 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008181 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8182 mApp, subId, "setDataRoamingEnabled");
8183
Pengquan Menga1bb6272018-09-06 09:59:22 -07008184 final long identity = Binder.clearCallingIdentity();
8185 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008186 Phone phone = getPhone(subId);
8187 if (phone != null) {
8188 phone.setDataRoamingEnabled(isEnabled);
8189 }
8190 } finally {
8191 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008192 }
8193 }
8194
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008195 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008196 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008197 TelephonyPermissions
8198 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008199 mApp, subId, "isManualNetworkSelectionAllowed");
8200
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008201 boolean isAllowed = true;
8202 final long identity = Binder.clearCallingIdentity();
8203 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008204 Phone phone = getPhone(subId);
8205 if (phone != null) {
8206 isAllowed = phone.isCspPlmnEnabled();
8207 }
8208 } finally {
8209 Binder.restoreCallingIdentity(identity);
8210 }
8211 return isAllowed;
8212 }
8213
8214 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008215 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008216 // Verify that tha callingPackage belongs to the calling UID
8217 mApp.getSystemService(AppOpsManager.class)
8218 .checkPackage(Binder.getCallingUid(), callingPackage);
8219
Jordan Liu1e142fc2019-04-22 15:10:43 -07008220 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008221 try {
8222 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008223 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008224 } catch (SecurityException e) {
8225 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8226 // has carrier privileges on an active UICC
8227 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8228 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008229 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008230 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008231 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008232
8233 final long identity = Binder.clearCallingIdentity();
8234 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008235 UiccController uiccController = UiccController.getInstance();
8236 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008237 if (hasReadPermission) {
8238 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008239 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008240
8241 // Remove private info if the caller doesn't have access
8242 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8243 for (UiccCardInfo cardInfo : cardInfos) {
8244 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8245 // is available
8246 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8247 if (card == null || card.getUiccProfile() == null) {
8248 // assume no access if the card or profile is unavailable
8249 filteredInfos.add(cardInfo.getUnprivileged());
8250 continue;
8251 }
8252 UiccProfile profile = card.getUiccProfile();
8253 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8254 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8255 filteredInfos.add(cardInfo);
8256 } else {
8257 filteredInfos.add(cardInfo.getUnprivileged());
8258 }
8259 }
8260 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008261 } finally {
8262 Binder.restoreCallingIdentity(identity);
8263 }
8264 }
8265
8266 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008267 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008268 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008269
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008270 final long identity = Binder.clearCallingIdentity();
8271 try {
8272 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8273 if (slots == null) {
8274 Rlog.i(LOG_TAG, "slots is null.");
8275 return null;
8276 }
8277
8278 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8279 for (int i = 0; i < slots.length; i++) {
8280 UiccSlot slot = slots[i];
8281 if (slot == null) {
8282 continue;
8283 }
8284
Jordan Liu7be7e652019-05-06 18:55:02 +00008285 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008286 UiccCard card = slot.getUiccCard();
8287 if (card != null) {
8288 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008289 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008290 cardId = slot.getEid();
8291 if (TextUtils.isEmpty(cardId)) {
8292 cardId = slot.getIccId();
8293 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008294 }
8295
Jordan Liu857451f2019-05-09 16:35:35 -07008296 if (cardId != null) {
8297 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8298 // if cardId is an EID, it's all digits so this is fine
8299 cardId = IccUtils.stripTrailingFs(cardId);
8300 }
8301
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008302 int cardState = 0;
8303 switch (slot.getCardState()) {
8304 case CARDSTATE_ABSENT:
8305 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8306 break;
8307 case CARDSTATE_PRESENT:
8308 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8309 break;
8310 case CARDSTATE_ERROR:
8311 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8312 break;
8313 case CARDSTATE_RESTRICTED:
8314 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8315 break;
8316 default:
8317 break;
8318
8319 }
8320
8321 infos[i] = new UiccSlotInfo(
8322 slot.isActive(),
8323 slot.isEuicc(),
8324 cardId,
8325 cardState,
8326 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008327 slot.isExtendedApduSupported(),
8328 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008329 }
8330 return infos;
8331 } finally {
8332 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008333 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008334 }
8335
8336 @Override
8337 public boolean switchSlots(int[] physicalSlots) {
8338 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008339
8340 final long identity = Binder.clearCallingIdentity();
8341 try {
8342 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8343 } finally {
8344 Binder.restoreCallingIdentity(identity);
8345 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008346 }
Jack Yu4c988042018-02-27 15:30:01 -08008347
8348 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008349 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008350 final long identity = Binder.clearCallingIdentity();
8351 try {
8352 return UiccController.getInstance().getCardIdForDefaultEuicc();
8353 } finally {
8354 Binder.restoreCallingIdentity(identity);
8355 }
8356 }
8357
Pengquan Meng85728fb2018-03-12 16:31:21 -07008358 /**
goneil47ffb6e2018-04-06 15:40:58 -07008359 * A test API to reload the UICC profile.
8360 *
8361 * <p>Requires that the calling app has permission
8362 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8363 * @hide
8364 */
8365 @Override
8366 public void refreshUiccProfile(int subId) {
8367 enforceModifyPermission();
8368
8369 final long identity = Binder.clearCallingIdentity();
8370 try {
8371 Phone phone = getPhone(subId);
8372 if (phone == null) {
8373 return;
8374 }
8375 UiccCard uiccCard = phone.getUiccCard();
8376 if (uiccCard == null) {
8377 return;
8378 }
8379 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8380 if (uiccProfile == null) {
8381 return;
8382 }
8383 uiccProfile.refresh();
8384 } finally {
8385 Binder.restoreCallingIdentity(identity);
8386 }
8387 }
8388
8389 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008390 * Returns false if the mobile data is disabled by default, otherwise return true.
8391 */
8392 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008393 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008394 }
8395
8396 /**
8397 * Returns true if the data roaming is enabled by default, i.e the system property
8398 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8399 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8400 */
8401 private boolean getDefaultDataRoamingEnabled(int subId) {
8402 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008403 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008404 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008405 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8406 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8407 return isDataRoamingEnabled;
8408 }
8409
8410 /**
8411 * Returns the default network type for the given {@code subId}, if the default network type is
8412 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8413 */
8414 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008415 List<Integer> list = TelephonyProperties.default_network();
8416 int phoneId = mSubscriptionController.getPhoneId(subId);
8417 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8418 return list.get(phoneId);
8419 }
8420 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008421 }
fionaxua13278b2018-03-21 00:08:13 -07008422
8423 @Override
8424 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008425 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008426 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008427
8428 final long identity = Binder.clearCallingIdentity();
8429 try {
8430 final Phone phone = getPhone(subId);
8431 if (phone == null) {
8432 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8433 return;
8434 }
chen xueaba88a2019-03-15 13:15:10 -07008435 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8436 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008437 if (carrierPrivilegeRules == null) {
8438 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8439 } else {
8440 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8441 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008442 } finally {
8443 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008444 }
fionaxua13278b2018-03-21 00:08:13 -07008445 }
8446
8447 @Override
8448 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008449 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008450
8451 final long identity = Binder.clearCallingIdentity();
8452 try {
8453 final Phone phone = getPhone(subId);
8454 if (phone == null) {
8455 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8456 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8457 }
8458 return phone.getCarrierIdListVersion();
8459 } finally {
8460 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008461 }
fionaxua13278b2018-03-21 00:08:13 -07008462 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008463
8464 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008465 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8466 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008467 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008468 mApp, subId, callingPackage, callingFeatureId,
8469 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008470 return -1;
8471 }
8472
8473 final long identity = Binder.clearCallingIdentity();
8474 try {
8475 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8476 } finally {
8477 Binder.restoreCallingIdentity(identity);
8478 }
8479 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008480
8481 @Override
8482 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008483 TelephonyPermissions
8484 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008485 mApp, subId, "getCdmaRoamingMode");
8486
8487 final long identity = Binder.clearCallingIdentity();
8488 try {
8489 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8490 } finally {
8491 Binder.restoreCallingIdentity(identity);
8492 }
8493 }
8494
8495 @Override
8496 public boolean setCdmaRoamingMode(int subId, int mode) {
8497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8498 mApp, subId, "setCdmaRoamingMode");
8499
8500 final long identity = Binder.clearCallingIdentity();
8501 try {
8502 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8503 } finally {
8504 Binder.restoreCallingIdentity(identity);
8505 }
8506 }
8507
8508 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008509 public int getCdmaSubscriptionMode(int subId) {
8510 TelephonyPermissions
8511 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8512 mApp, subId, "getCdmaSubscriptionMode");
8513
8514 final long identity = Binder.clearCallingIdentity();
8515 try {
8516 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8517 } finally {
8518 Binder.restoreCallingIdentity(identity);
8519 }
8520 }
8521
8522 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008523 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8524 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8525 mApp, subId, "setCdmaSubscriptionMode");
8526
8527 final long identity = Binder.clearCallingIdentity();
8528 try {
8529 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8530 } finally {
8531 Binder.restoreCallingIdentity(identity);
8532 }
8533 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008534
sqianc5eccab2018-10-19 18:46:41 -07008535 @Override
sqian8c685422019-02-22 15:55:18 -08008536 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008537 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008538 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008539 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8540 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008541 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8542 }
8543 final long identity = Binder.clearCallingIdentity();
8544 try {
sqian854d44b2018-12-12 16:48:18 -08008545 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8546 for (Phone phone: PhoneFactory.getPhones()) {
8547 if (phone.getEmergencyNumberTracker() != null
8548 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8549 emergencyNumberListInternal.put(
8550 phone.getSubId(),
8551 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8552 }
sqian11b7a0e2018-12-05 18:48:28 -08008553 }
sqian854d44b2018-12-12 16:48:18 -08008554 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008555 } finally {
8556 Binder.restoreCallingIdentity(identity);
8557 }
sqianc5eccab2018-10-19 18:46:41 -07008558 }
8559
8560 @Override
sqian8c685422019-02-22 15:55:18 -08008561 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008562 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008563 if (!exactMatch) {
8564 TelephonyPermissions
8565 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008566 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008567 }
8568 final long identity = Binder.clearCallingIdentity();
8569 try {
sqian854d44b2018-12-12 16:48:18 -08008570 for (Phone phone: PhoneFactory.getPhones()) {
8571 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008572 && phone.getEmergencyNumberTracker()
8573 .isEmergencyNumber(number, exactMatch)) {
8574 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008575 }
sqian11b7a0e2018-12-05 18:48:28 -08008576 }
8577 return false;
8578 } finally {
8579 Binder.restoreCallingIdentity(identity);
8580 }
8581 }
8582
sqianf4ca7ed2019-01-15 18:32:07 -08008583 /**
8584 * Update emergency number list for test mode.
8585 */
8586 @Override
8587 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8588 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8589 "updateEmergencyNumberListTestMode");
8590
8591 final long identity = Binder.clearCallingIdentity();
8592 try {
8593 for (Phone phone: PhoneFactory.getPhones()) {
8594 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8595 if (tracker != null) {
8596 tracker.executeEmergencyNumberTestModeCommand(action, num);
8597 }
8598 }
8599 } finally {
8600 Binder.restoreCallingIdentity(identity);
8601 }
8602 }
8603
8604 /**
8605 * Get the full emergency number list for test mode.
8606 */
8607 @Override
8608 public List<String> getEmergencyNumberListTestMode() {
8609 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8610 "getEmergencyNumberListTestMode");
8611
8612 final long identity = Binder.clearCallingIdentity();
8613 try {
8614 Set<String> emergencyNumbers = new HashSet<>();
8615 for (Phone phone: PhoneFactory.getPhones()) {
8616 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8617 if (tracker != null) {
8618 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8619 emergencyNumbers.add(num.getNumber());
8620 }
8621 }
8622 }
8623 return new ArrayList<>(emergencyNumbers);
8624 } finally {
8625 Binder.restoreCallingIdentity(identity);
8626 }
8627 }
8628
chen xud6b45bd2018-10-30 22:27:10 -07008629 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008630 public int getEmergencyNumberDbVersion(int subId) {
8631 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8632
8633 final long identity = Binder.clearCallingIdentity();
8634 try {
8635 final Phone phone = getPhone(subId);
8636 if (phone == null) {
8637 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8638 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8639 }
8640 return phone.getEmergencyNumberDbVersion();
8641 } finally {
8642 Binder.restoreCallingIdentity(identity);
8643 }
8644 }
8645
8646 @Override
8647 public void notifyOtaEmergencyNumberDbInstalled() {
8648 enforceModifyPermission();
8649
8650 final long identity = Binder.clearCallingIdentity();
8651 try {
8652 for (Phone phone: PhoneFactory.getPhones()) {
8653 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8654 if (tracker != null) {
8655 tracker.updateOtaEmergencyNumberDatabase();
8656 }
8657 }
8658 } finally {
8659 Binder.restoreCallingIdentity(identity);
8660 }
8661 }
8662
8663 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008664 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008665 enforceActiveEmergencySessionPermission();
8666
8667 final long identity = Binder.clearCallingIdentity();
8668 try {
8669 for (Phone phone: PhoneFactory.getPhones()) {
8670 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8671 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008672 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8673 }
8674 }
8675 } finally {
8676 Binder.restoreCallingIdentity(identity);
8677 }
8678 }
8679
8680 @Override
8681 public void resetOtaEmergencyNumberDbFilePath() {
8682 enforceActiveEmergencySessionPermission();
8683
8684 final long identity = Binder.clearCallingIdentity();
8685 try {
8686 for (Phone phone: PhoneFactory.getPhones()) {
8687 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8688 if (tracker != null) {
8689 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008690 }
8691 }
8692 } finally {
8693 Binder.restoreCallingIdentity(identity);
8694 }
8695 }
8696
8697 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008698 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8699 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8700 Phone phone = getPhone(subId);
8701 if (phone == null) {
8702 return null;
8703 }
8704 final long identity = Binder.clearCallingIdentity();
8705 try {
8706 UiccProfile profile = UiccController.getInstance()
8707 .getUiccProfileForPhone(phone.getPhoneId());
8708 if (profile != null) {
8709 return profile.getCertsFromCarrierPrivilegeAccessRules();
8710 }
8711 } finally {
8712 Binder.restoreCallingIdentity(identity);
8713 }
8714 return null;
8715 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008716
8717 /**
8718 * Enable or disable a modem stack.
8719 */
8720 @Override
8721 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8722 enforceModifyPermission();
8723
8724 final long identity = Binder.clearCallingIdentity();
8725 try {
8726 Phone phone = PhoneFactory.getPhone(slotIndex);
8727 if (phone == null) {
8728 return false;
8729 } else {
8730 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8731 }
8732 } finally {
8733 Binder.restoreCallingIdentity(identity);
8734 }
8735 }
Michelecea4cf22018-12-21 15:00:11 -08008736
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008737 /**
8738 * Whether a modem stack is enabled or not.
8739 */
8740 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008741 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8742 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008743 Phone phone = PhoneFactory.getPhone(slotIndex);
8744 if (phone == null) return false;
8745
8746 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008747 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8748 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008749 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8750 }
8751
8752 final long identity = Binder.clearCallingIdentity();
8753 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008754 try {
8755 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8756 } catch (NoSuchElementException ex) {
8757 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8758 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008759 } finally {
8760 Binder.restoreCallingIdentity(identity);
8761 }
8762 }
8763
Michelecea4cf22018-12-21 15:00:11 -08008764 @Override
Michele0ea7d782019-03-19 14:58:42 -07008765 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008766 enforceModifyPermission();
8767
8768 final long identity = Binder.clearCallingIdentity();
8769 try {
8770 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008771 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008772 .commit();
8773 } finally {
8774 Binder.restoreCallingIdentity(identity);
8775 }
8776 }
8777
8778 @Override
Michele0ea7d782019-03-19 14:58:42 -07008779 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008780 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008781 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008782 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8783 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008784 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008785 }
Michelecea4cf22018-12-21 15:00:11 -08008786
8787 final long identity = Binder.clearCallingIdentity();
8788 try {
Michele0ea7d782019-03-19 14:58:42 -07008789 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008790 } finally {
8791 Binder.restoreCallingIdentity(identity);
8792 }
8793 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008794
Michele0ea7d782019-03-19 14:58:42 -07008795 @TelephonyManager.IsMultiSimSupportedResult
8796 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008797 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8798 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8799 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008800 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8801 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008802 }
8803 // Check if the hardware supports multisim functionality. If usage of multisim is not
8804 // supported by the modem, indicate that it is restricted.
8805 PhoneCapability staticCapability =
8806 mPhoneConfigurationManager.getStaticPhoneCapability();
8807 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008808 loge("isMultiSimSupportedInternal: no static configuration available");
8809 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008810 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008811 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008812 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8813 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008814 }
8815 // Check if support of multiple SIMs is restricted by carrier
8816 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008817 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008818 }
8819
Michele0ea7d782019-03-19 14:58:42 -07008820 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008821 }
8822
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008823 /**
8824 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008825 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8826 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8827 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008828 * @param numOfSims number of active sims we want to switch to
8829 */
8830 @Override
8831 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008832 if (numOfSims == 1) {
8833 enforceModifyPermission();
8834 } else {
8835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8836 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8837 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008838 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008839
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008840 try {
Michele30b57b22019-03-01 12:01:14 -08008841 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008842 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008843 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8844 return;
8845 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008846 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8847 } finally {
8848 Binder.restoreCallingIdentity(identity);
8849 }
8850 }
8851
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008852 @Override
8853 public boolean isApplicationOnUicc(int subId, int appType) {
8854 enforceReadPrivilegedPermission("isApplicationOnUicc");
8855 Phone phone = getPhone(subId);
8856 if (phone == null) {
8857 return false;
8858 }
8859 final long identity = Binder.clearCallingIdentity();
8860 try {
8861 UiccCard uiccCard = phone.getUiccCard();
8862 if (uiccCard == null) {
8863 return false;
8864 }
8865 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8866 if (uiccProfile == null) {
8867 return false;
8868 }
8869 if (TelephonyManager.APPTYPE_SIM <= appType
8870 && appType <= TelephonyManager.APPTYPE_ISIM) {
8871 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8872 }
8873 return false;
8874 } finally {
8875 Binder.restoreCallingIdentity(identity);
8876 }
8877 }
8878
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008879 /**
chen xub4baa772019-04-03 10:23:41 -07008880 * Get whether making changes to modem configurations will trigger reboot.
8881 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008882 */
8883 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008884 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8885 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008886 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008887 mApp, subId, callingPackage, callingFeatureId,
8888 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008889 return false;
8890 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008891 final long identity = Binder.clearCallingIdentity();
8892 try {
8893 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8894 } finally {
8895 Binder.restoreCallingIdentity(identity);
8896 }
8897 }
8898
Nathan Harold29f5f052019-02-15 13:41:57 -08008899 private void updateModemStateMetrics() {
8900 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8901 // TODO: check the state for each modem if the api is ready.
8902 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8903 }
8904
Pengquan Meng3889a572019-01-23 11:16:29 -08008905 @Override
8906 public int[] getSlotsMapping() {
8907 enforceReadPrivilegedPermission("getSlotsMapping");
8908
8909 final long identity = Binder.clearCallingIdentity();
8910 try {
8911 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8912 // All logical slots should have a mapping to a physical slot.
8913 int[] logicalSlotsMapping = new int[phoneCount];
8914 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8915 for (int i = 0; i < slotInfos.length; i++) {
8916 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8917 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8918 }
8919 }
8920 return logicalSlotsMapping;
8921 } finally {
8922 Binder.restoreCallingIdentity(identity);
8923 }
8924 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008925
8926 /**
8927 * Get the IRadio HAL Version
8928 */
8929 @Override
8930 public int getRadioHalVersion() {
8931 Phone phone = getDefaultPhone();
8932 if (phone == null) return -1;
8933 HalVersion hv = phone.getHalVersion();
8934 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8935 return hv.major * 100 + hv.minor;
8936 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008937
8938 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008939 * Get the current calling package name.
8940 * @return the current calling package name
8941 */
8942 @Override
8943 public String getCurrentPackageName() {
8944 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8945 }
8946
8947 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008948 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8949 * corresponding network requests on a subId.
8950 *
8951 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008952 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008953 * 2) APN is un-metered for this subscription, or
8954 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008955 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008956 *
8957 * @return whether data is allowed for a apn type.
8958 *
8959 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008960 */
8961 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008962 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008963 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8964 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008965
8966 // Now that all security checks passes, perform the operation as ourselves.
8967 final long identity = Binder.clearCallingIdentity();
8968 try {
8969 Phone phone = getPhone(subId);
8970 if (phone == null) return false;
8971
Jack Yu41407ee2019-05-13 16:54:09 -07008972 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008973 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8974 } finally {
8975 Binder.restoreCallingIdentity(identity);
8976 }
8977 }
8978
8979 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008980 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008981 enforceReadPrivilegedPermission("isApnMetered");
8982
8983 // Now that all security checks passes, perform the operation as ourselves.
8984 final long identity = Binder.clearCallingIdentity();
8985 try {
8986 Phone phone = getPhone(subId);
8987 if (phone == null) return true; // By default return true.
8988
Jack Yu41407ee2019-05-13 16:54:09 -07008989 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008990 } finally {
8991 Binder.restoreCallingIdentity(identity);
8992 }
8993 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008994
8995 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008996 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8997 int subscriptionId, IBooleanConsumer resultCallback) {
8998 enforceModifyPermission();
8999 long token = Binder.clearCallingIdentity();
9000 try {
9001 Phone phone = getPhone(subscriptionId);
9002 if (phone == null) {
9003 try {
9004 if (resultCallback != null) {
9005 resultCallback.accept(false);
9006 }
9007 } catch (RemoteException e) {
9008 // ignore
9009 }
9010 return;
9011 }
9012 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9013 Pair.create(specifiers, (x) -> {
9014 try {
9015 if (resultCallback != null) {
9016 resultCallback.accept(x);
9017 }
9018 } catch (RemoteException e) {
9019 // ignore
9020 }
9021 });
9022 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9023 } finally {
9024 Binder.restoreCallingIdentity(token);
9025 }
9026 }
9027
9028 @Override
Sarah Chincc055732020-11-18 13:39:35 -08009029 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9030 TelephonyPermissions
9031 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9032 mApp, subId, "getSystemSelectionChannels");
9033 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9034 final long identity = Binder.clearCallingIdentity();
9035 try {
9036 List<RadioAccessSpecifier> specifiers =
9037 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9038 null, subId, workSource);
9039 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9040 return specifiers;
9041 } finally {
9042 Binder.restoreCallingIdentity(identity);
9043 }
9044 }
9045
9046 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009047 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009048 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009049 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9050 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9051 if (iccRecords == null) {
9052 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9053 return false;
9054 }
9055 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9056 }
9057
9058 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009059 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9060 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009061 if (callingPackage == null) {
9062 callingPackage = getCurrentPackageName();
9063 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009064 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9065 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009066 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9067 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009068 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9069 }
9070 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9071 Intent intent = new Intent();
9072 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9073 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9074 // Bring up choose default SMS subscription dialog right now
9075 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9076 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9077 mApp.startActivity(intent);
9078 }
chen xud5ca2d52019-05-28 15:20:57 -07009079
9080 @Override
9081 public String getMmsUAProfUrl(int subId) {
9082 //TODO investigate if this API should require proper permission check in R b/133791609
9083 final long identity = Binder.clearCallingIdentity();
9084 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009085 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9086 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9087 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9088 return carrierUAProfUrl;
9089 }
chen xud5ca2d52019-05-28 15:20:57 -07009090 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9091 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9092 } finally {
9093 Binder.restoreCallingIdentity(identity);
9094 }
9095 }
9096
9097 @Override
9098 public String getMmsUserAgent(int subId) {
9099 //TODO investigate if this API should require proper permission check in R b/133791609
9100 final long identity = Binder.clearCallingIdentity();
9101 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009102 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9103 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9104 if (!TextUtils.isEmpty(carrierUserAgent)) {
9105 return carrierUserAgent;
9106 }
chen xud5ca2d52019-05-28 15:20:57 -07009107 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9108 .getString(com.android.internal.R.string.config_mms_user_agent);
9109 } finally {
9110 Binder.restoreCallingIdentity(identity);
9111 }
9112 }
Jack Yub07d4972019-05-28 16:12:25 -07009113
9114 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009115 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9116 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9117
9118 final long identity = Binder.clearCallingIdentity();
9119 try {
9120 Phone phone = getPhone(subscriptionId);
9121 if (phone == null) return false;
9122
9123 switch (policy) {
9124 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9125 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9126 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9127 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9128 default:
9129 throw new IllegalArgumentException(policy + " is not a valid policy");
9130 }
9131 } finally {
9132 Binder.restoreCallingIdentity(identity);
9133 }
9134 }
9135
9136 @Override
9137 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9138 boolean enabled) {
9139 enforceModifyPermission();
9140
9141 final long identity = Binder.clearCallingIdentity();
9142 try {
9143 Phone phone = getPhone(subscriptionId);
9144 if (phone == null) return;
9145
9146 switch (policy) {
9147 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9148 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9149 break;
9150 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9151 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9152 break;
9153 default:
9154 throw new IllegalArgumentException(policy + " is not a valid policy");
9155 }
9156 } finally {
9157 Binder.restoreCallingIdentity(identity);
9158 }
9159 }
9160
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009161 /**
Hall Liub48cf452020-09-25 11:13:49 -07009162 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009163 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9164 * otherwise.
9165 */
9166 @Override
9167 public void setCepEnabled(boolean isCepEnabled) {
9168 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9169
9170 final long identity = Binder.clearCallingIdentity();
9171 try {
9172 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9173 for (Phone phone : PhoneFactory.getPhones()) {
9174 Phone defaultPhone = phone.getImsPhone();
9175 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9176 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9177 ImsPhoneCallTracker imsPhoneCallTracker =
9178 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9179 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9180 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9181 + imsPhone.getMsisdn());
9182 }
9183 }
9184 } finally {
9185 Binder.restoreCallingIdentity(identity);
9186 }
9187 }
allenwtsu46dcc572020-01-08 18:24:03 +08009188
9189 /**
9190 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9191 *
9192 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9193 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9194 * before being read.
9195 */
9196 @Override
9197 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9198 isCompressed) {
9199 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9200 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009201 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9202 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9203 }
9204 if (!isImsAvailableOnDevice()) {
9205 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9206 "IMS not available on device.");
9207 }
9208
9209 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009210 try {
Hui Wang068ab862020-10-31 05:12:53 +00009211 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9212 } finally {
9213 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009214 }
9215 }
zoey chenf95ca592019-12-30 16:11:23 +08009216
9217 @Override
9218 public boolean isIccLockEnabled(int subId) {
9219 enforceReadPrivilegedPermission("isIccLockEnabled");
9220
9221 // Now that all security checks passes, perform the operation as ourselves.
9222 final long identity = Binder.clearCallingIdentity();
9223 try {
9224 Phone phone = getPhone(subId);
9225 if (phone != null && phone.getIccCard() != null) {
9226 return phone.getIccCard().getIccLockEnabled();
9227 } else {
9228 return false;
9229 }
9230 } finally {
9231 Binder.restoreCallingIdentity(identity);
9232 }
9233 }
9234
9235 /**
zoey chene02881a2019-12-30 16:11:23 +08009236 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009237 *
zoey chene02881a2019-12-30 16:11:23 +08009238 * @return an integer representing the status of IccLock enabled or disabled in the following
9239 * three cases:
9240 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9241 * successfully.
9242 * - Positive number and zero for remaining password attempts.
9243 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009244 *
9245 */
9246 @Override
9247 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9248 enforceModifyPermission();
9249
9250 Phone phone = getPhone(subId);
9251 if (phone == null) {
9252 return 0;
9253 }
9254 // Now that all security checks passes, perform the operation as ourselves.
9255 final long identity = Binder.clearCallingIdentity();
9256 try {
9257 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9258 new Pair<Boolean, String>(enabled, password), phone, null);
9259 return attemptsRemaining;
9260
9261 } catch (Exception e) {
9262 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9263 } finally {
9264 Binder.restoreCallingIdentity(identity);
9265 }
9266 return 0;
9267 }
9268
9269 /**
9270 * Change the ICC password used in ICC pin lock.
9271 *
zoey chene02881a2019-12-30 16:11:23 +08009272 * @return an integer representing the status of IccLock changed in the following three cases:
9273 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9274 * - Positive number and zero for remaining password attempts.
9275 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009276 *
9277 */
9278 @Override
9279 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9280 enforceModifyPermission();
9281
9282 Phone phone = getPhone(subId);
9283 if (phone == null) {
9284 return 0;
9285 }
9286 // Now that all security checks passes, perform the operation as ourselves.
9287 final long identity = Binder.clearCallingIdentity();
9288 try {
9289 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9290 new Pair<String, String>(oldPassword, newPassword), phone, null);
9291 return attemptsRemaining;
9292
9293 } catch (Exception e) {
9294 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9295 } finally {
9296 Binder.restoreCallingIdentity(identity);
9297 }
9298 return 0;
9299 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009300
Peter Wangdafb9ac2020-01-15 14:13:38 -08009301 /**
9302 * Request for receiving user activity notification
9303 */
9304 @Override
9305 public void requestUserActivityNotification() {
9306 if (!mNotifyUserActivity.get()
9307 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9308 mNotifyUserActivity.set(true);
9309 }
9310 }
9311
9312 /**
9313 * Called when userActivity is signalled in the power manager.
9314 * This is safe to call from any thread, with any window manager locks held or not.
9315 */
9316 @Override
9317 public void userActivity() {
9318 // ***************************************
9319 // * Inherited from PhoneWindowManager *
9320 // ***************************************
9321 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9322 // WITH ITS LOCKS HELD.
9323 //
9324 // This code must be VERY careful about the locks
9325 // it acquires.
9326 // In fact, the current code acquires way too many,
9327 // and probably has lurking deadlocks.
9328
9329 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9330 throw new SecurityException("Only the OS may call notifyUserActivity()");
9331 }
9332
9333 if (mNotifyUserActivity.getAndSet(false)) {
9334 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9335 USER_ACTIVITY_NOTIFICATION_DELAY);
9336 }
9337 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009338
Malcolm Chen884180b2020-04-13 11:59:40 -07009339 @Override
9340 public boolean canConnectTo5GInDsdsMode() {
9341 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9342 }
Jack Yud10cdd42020-09-28 20:28:01 -07009343
9344 @Override
9345 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9346 String callingFeatureId) {
9347 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9348 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9349 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9350 }
9351
9352 Phone phone = getPhone(subId);
9353 if (phone == null) {
9354 throw new RuntimeException("phone is not available");
9355 }
9356 // Now that all security checks passes, perform the operation as ourselves.
9357 final long identity = Binder.clearCallingIdentity();
9358 try {
9359 return phone.getEquivalentHomePlmns();
9360 } finally {
9361 Binder.restoreCallingIdentity(identity);
9362 }
9363 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009364
Hui Wang0866fcc2020-10-12 12:14:23 -07009365 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009366 public boolean isRadioInterfaceCapabilitySupported(
9367 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009368 Set<String> radioInterfaceCapabilities =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009369 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9370 if (radioInterfaceCapabilities == null) {
9371 throw new RuntimeException("radio interface capabilities are not available");
9372 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009373 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009374 }
9375 }
9376
9377 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009378 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9379 UaSecurityProtocolIdentifier securityProtocol,
9380 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9381 throws RemoteException {
9382 enforceModifyPermission();
9383 if (DBG) {
9384 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9385 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9386 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9387 }
9388
9389 if (!SubscriptionManager.isValidSubscriptionId(subId)
9390 || appType < TelephonyManager.APPTYPE_UNKNOWN
9391 || appType > TelephonyManager.APPTYPE_ISIM
9392 || nafUrl == null || securityProtocol == null || callback == null) {
9393 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9394 if (callback != null) {
9395 try {
9396 callback.onAuthenticationFailure(
9397 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9398 } catch (RemoteException exception) {
9399 log("Fail to notify onAuthenticationFailure due to " + exception);
9400 }
9401 return;
9402 }
9403 }
9404
9405 final long token = Binder.clearCallingIdentity();
9406 try {
9407 getGbaManager(subId).bootstrapAuthenticationRequest(
9408 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9409 forceBootStrapping, callback));
9410 } finally {
9411 Binder.restoreCallingIdentity(token);
9412 }
9413 }
9414
Jack Nudelman24d51a52020-11-24 12:08:04 -08009415 /**
9416 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9417 * requested radio power state will actually be set. See {@link
9418 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9419 *
9420 * @param subId the subscription ID of the phone requesting to set the radio power state.
9421 * @param enable {@code true} if trying to turn radio on.
9422 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9423 * false}.
9424 */
9425 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9426 Phone phone = getPhone(subId);
9427 if (phone != null) {
9428 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9429 return true;
9430 }
9431 return false;
9432 }
9433
9434 private int handleDataThrottlingRequest(int subId,
9435 DataThrottlingRequest dataThrottlingRequest) {
9436 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9437 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9438 if (!setRadioPowerForThermal(subId, true)) {
9439 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9440 }
9441
9442 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9443
9444 int thermalMitigationResult =
9445 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9446 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9447 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9448 }
9449 return thermalMitigationResult;
9450 }
9451
9452 /**
9453 * Thermal mitigation request to control functionalities at modem.
9454 *
9455 * @param subId the id of the subscription.
9456 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9457 *
9458 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9459 */
9460 @Override
9461 @ThermalMitigationResult
9462 public int sendThermalMitigationRequest(
9463 int subId,
9464 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9465 enforceModifyPermission();
9466
9467 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9468 final long identity = Binder.clearCallingIdentity();
9469
9470 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9471 try {
9472 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9473 switch (thermalMitigationAction) {
9474 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9475 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009476 handleDataThrottlingRequest(subId,
9477 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009478 break;
9479 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9480 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9481 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9482 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9483 }
9484
9485 // Ensure that radio is on. If not able to power on due to phone being
9486 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9487 if (!setRadioPowerForThermal(subId, true)) {
9488 thermalMitigationResult =
9489 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9490 break;
9491 }
9492
9493 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9494 false);
9495 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9496 break;
9497 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9498 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9499 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9500 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9501 }
9502
9503 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9504 if (registry != null) {
9505 TelephonyConnectionService service =
9506 registry.getTelephonyConnectionService();
9507 Phone phone = getPhone(subId);
9508 if (phone == null) {
9509 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009510 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009511 break;
9512 }
9513
9514 if (PhoneConstantConversions.convertCallState(phone.getState())
Daniel Bright74f1ca82020-11-13 11:49:37 -08009515 != TelephonyManager.CALL_STATE_IDLE
9516 || phone.isInEmergencySmsMode() || phone.isInEcm()
9517 || (service != null && service.isEmergencyCallPending())) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009518 String errorMessage = "Phone state is not valid. call state = "
9519 + PhoneConstantConversions.convertCallState(phone.getState())
9520 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9521 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9522 errorMessage += service == null
9523 ? " TelephonyConnectionService is null"
9524 : " isEmergencyCallPending = "
9525 + service.isEmergencyCallPending();
9526 Log.e(LOG_TAG, errorMessage);
9527 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009528 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009529 break;
9530 }
9531 } else {
9532 thermalMitigationResult =
9533 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9534 break;
9535 }
9536
9537 // Turn radio off. If not able to power off due to phone being unavailable,
9538 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9539 if (!setRadioPowerForThermal(subId, false)) {
9540 thermalMitigationResult =
9541 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9542 break;
9543 }
9544 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009545 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009546 break;
9547 default:
9548 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9549 + "not exist. Requested action: " + thermalMitigationAction);
9550 }
9551 } catch (IllegalArgumentException e) {
9552 throw e;
9553 } catch (Exception e) {
9554 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9555 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9556 } finally {
9557 Binder.restoreCallingIdentity(identity);
9558 }
9559
9560 if (DBG) {
9561 log("thermalMitigationRequest returning with thermalMitigationResult: "
9562 + thermalMitigationResult);
9563 }
9564
9565 return thermalMitigationResult;
9566 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009567
9568 /**
9569 * Set the GbaService Package Name that Telephony will bind to.
9570 *
9571 * @param subId The sim that the GbaService is associated with.
9572 * @param packageName The name of the package to be replaced with.
9573 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9574 */
9575 @Override
9576 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9577 enforceModifyPermission();
9578
9579 final long identity = Binder.clearCallingIdentity();
9580 try {
9581 return getGbaManager(subId).overrideServicePackage(packageName);
9582 } finally {
9583 Binder.restoreCallingIdentity(identity);
9584 }
9585 }
9586
9587 /**
9588 * Return the package name of the currently bound GbaService.
9589 *
9590 * @param subId The sim that the GbaService is associated with.
9591 * @return the package name of the GbaService configuration, null if GBA is not supported.
9592 */
9593 @Override
9594 public String getBoundGbaService(int subId) {
9595 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9596
9597 final long identity = Binder.clearCallingIdentity();
9598 try {
9599 return getGbaManager(subId).getServicePackage();
9600 } finally {
9601 Binder.restoreCallingIdentity(identity);
9602 }
9603 }
9604
9605 /**
9606 * Set the release time for telephony to unbind GbaService.
9607 *
9608 * @param subId The sim that the GbaService is associated with.
9609 * @param interval The release time to unbind GbaService by millisecond.
9610 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9611 */
9612 @Override
9613 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9614 enforceModifyPermission();
9615
9616 final long identity = Binder.clearCallingIdentity();
9617 try {
9618 return getGbaManager(subId).overrideReleaseTime(interval);
9619 } finally {
9620 Binder.restoreCallingIdentity(identity);
9621 }
9622 }
9623
9624 /**
9625 * Return the release time for telephony to unbind GbaService.
9626 *
9627 * @param subId The sim that the GbaService is associated with.
9628 * @return The release time to unbind GbaService by millisecond.
9629 */
9630 @Override
9631 public int getGbaReleaseTime(int subId) {
9632 enforceReadPrivilegedPermission("getGbaReleaseTime");
9633
9634 final long identity = Binder.clearCallingIdentity();
9635 try {
9636 return getGbaManager(subId).getReleaseTime();
9637 } finally {
9638 Binder.restoreCallingIdentity(identity);
9639 }
9640 }
9641
9642 private GbaManager getGbaManager(int subId) {
9643 GbaManager instance = GbaManager.getInstance(subId);
9644 if (instance == null) {
9645 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9646 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9647 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9648 }
9649 return instance;
9650 }
Hui Wang068ab862020-10-31 05:12:53 +00009651
9652 /**
9653 * indicate whether the device and the carrier can support
9654 * RCS VoLTE single registration.
9655 */
9656 @Override
9657 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9658 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9659
9660 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9661 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9662 }
9663
9664 final long identity = Binder.clearCallingIdentity();
9665 try {
9666 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9667 if (rpm != null) {
9668 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9669 }
9670 return false;
9671 } finally {
9672 Binder.restoreCallingIdentity(identity);
9673 }
9674 }
9675
9676 /**
9677 * Register RCS provisioning callback.
9678 */
9679 @Override
9680 public void registerRcsProvisioningChangedCallback(int subId,
9681 IRcsConfigCallback callback) {
9682 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9683
9684 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9685 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9686 }
9687 if (!isImsAvailableOnDevice()) {
9688 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9689 "IMS not available on device.");
9690 }
9691
9692 final long identity = Binder.clearCallingIdentity();
9693 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009694 if (!RcsProvisioningMonitor.getInstance()
9695 .registerRcsProvisioningChangedCallback(subId, callback)) {
9696 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9697 "Service not available for the subscription.");
9698 }
Hui Wang068ab862020-10-31 05:12:53 +00009699 } finally {
9700 Binder.restoreCallingIdentity(identity);
9701 }
9702 }
9703
9704 /**
9705 * Unregister RCS provisioning callback.
9706 */
9707 @Override
9708 public void unregisterRcsProvisioningChangedCallback(int subId,
9709 IRcsConfigCallback callback) {
9710 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9711
9712 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9713 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9714 }
9715 if (!isImsAvailableOnDevice()) {
9716 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9717 "IMS not available on device.");
9718 }
9719
9720 final long identity = Binder.clearCallingIdentity();
9721 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009722 RcsProvisioningMonitor.getInstance()
9723 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009724 } finally {
9725 Binder.restoreCallingIdentity(identity);
9726 }
9727 }
9728
9729 /**
9730 * trigger RCS reconfiguration.
9731 */
9732 public void triggerRcsReconfiguration(int subId) {
9733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9734 mApp, subId, "triggerRcsReconfiguration");
9735
9736 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9737 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9738 }
9739 if (!isImsAvailableOnDevice()) {
9740 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9741 "IMS not available on device.");
9742 }
9743
9744 final long identity = Binder.clearCallingIdentity();
9745 try {
9746 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9747 } finally {
9748 Binder.restoreCallingIdentity(identity);
9749 }
9750 }
9751
9752 /**
9753 * Provide the client configuration parameters of the RCS application.
9754 */
9755 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9756 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9757 mApp, subId, "setRcsClientConfiguration");
9758
9759 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9760 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9761 }
9762 if (!isImsAvailableOnDevice()) {
9763 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9764 "IMS not available on device.");
9765 }
9766
9767 final long identity = Binder.clearCallingIdentity();
9768
9769 try {
9770 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9771 if (configBinder == null) {
9772 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9773 } else {
9774 configBinder.setRcsClientConfiguration(rcc);
9775 }
9776 } catch (RemoteException e) {
9777 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9778 } finally {
9779 Binder.restoreCallingIdentity(identity);
9780 }
9781 }
9782
9783 /**
9784 * Overrides the config of RCS VoLTE single registration enabled for the device.
9785 */
9786 @Override
9787 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9788 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9789 "setDeviceSingleRegistrationEnabledOverride");
9790 enforceModifyPermission();
9791
9792 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9793 : Boolean.parseBoolean(enabledStr);
9794 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009795 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009796 }
9797
9798 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009799 * Sends a device to device communication message. Only usable via shell.
9800 * @param message message to send.
9801 * @param value message value.
9802 */
9803 @Override
9804 public void sendDeviceToDeviceMessage(int message, int value) {
9805 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9806 "setCarrierSingleRegistrationEnabledOverride");
9807 enforceModifyPermission();
9808
9809 final long identity = Binder.clearCallingIdentity();
9810 try {
9811 TelephonyConnectionService service =
9812 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9813 if (service == null) {
9814 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9815 return;
9816 }
9817 service.sendTestDeviceToDeviceMessage(message, value);
9818 } finally {
9819 Binder.restoreCallingIdentity(identity);
9820 }
9821 }
9822
9823
9824 /**
Hui Wang068ab862020-10-31 05:12:53 +00009825 * Gets the config of RCS VoLTE single registration enabled for the device.
9826 */
9827 @Override
9828 public boolean getDeviceSingleRegistrationEnabled() {
9829 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9830 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9831 }
9832
9833 /**
9834 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9835 */
9836 @Override
9837 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9838 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9839 "setCarrierSingleRegistrationEnabledOverride");
9840 enforceModifyPermission();
9841
9842 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9843 : Boolean.parseBoolean(enabledStr);
9844 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9845 subId, enabled);
9846 }
9847
9848 /**
9849 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9850 */
9851 @Override
9852 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9853 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9854 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9855 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009856
9857 /**
9858 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9859 * their mobile plan.
9860 */
9861 @Override
9862 public String getMobileProvisioningUrl() {
9863 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9864 final long identity = Binder.clearCallingIdentity();
9865 try {
9866 return getDefaultPhone().getMobileProvisioningUrl();
9867 } finally {
9868 Binder.restoreCallingIdentity(identity);
9869 }
9870 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009871
James.cf Linbcdf8b32021-01-14 16:44:13 +08009872 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009873 * Get the EAB contact from the EAB database.
9874 */
9875 @Override
9876 public String getContactFromEab(String contact) {
9877 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9878 enforceModifyPermission();
9879 final long identity = Binder.clearCallingIdentity();
9880 try {
9881 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9882 } finally {
9883 Binder.restoreCallingIdentity(identity);
9884 }
9885 }
9886
9887 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009888 * Remove the EAB contacts from the EAB database.
9889 */
9890 @Override
9891 public int removeContactFromEab(int subId, String contacts) {
9892 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9893 enforceModifyPermission();
9894 final long identity = Binder.clearCallingIdentity();
9895 try {
9896 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9897 } finally {
9898 Binder.restoreCallingIdentity(identity);
9899 }
9900 }
9901
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009902 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +08009903 public boolean getDeviceUceEnabled() {
9904 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
9905 final long identity = Binder.clearCallingIdentity();
9906 try {
9907 return mApp.getDeviceUceEnabled();
9908 } finally {
9909 Binder.restoreCallingIdentity(identity);
9910 }
9911 }
9912
9913 @Override
9914 public void setDeviceUceEnabled(boolean isEnabled) {
9915 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
9916 final long identity = Binder.clearCallingIdentity();
9917 try {
9918 mApp.setDeviceUceEnabled(isEnabled);
9919 } finally {
9920 Binder.restoreCallingIdentity(identity);
9921 }
9922 }
9923
9924 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009925 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9926 String callingPackage) {
9927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9928 mApp, subId, "setSignalStrengthUpdateRequest");
9929
9930 final int callingUid = Binder.getCallingUid();
9931 // Verify that tha callingPackage belongs to the calling UID
9932 mApp.getSystemService(AppOpsManager.class)
9933 .checkPackage(callingUid, callingPackage);
9934
9935 validateSignalStrengthUpdateRequest(request, callingUid);
9936
9937 final long identity = Binder.clearCallingIdentity();
9938 try {
9939 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
9940 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9941
9942 if (result instanceof IllegalStateException) {
9943 throw (IllegalStateException) result;
9944 }
9945 } finally {
9946 Binder.restoreCallingIdentity(identity);
9947 }
9948 }
9949
9950 @Override
9951 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9952 String callingPackage) {
9953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9954 mApp, subId, "clearSignalStrengthUpdateRequest");
9955
9956 final int callingUid = Binder.getCallingUid();
9957 // Verify that tha callingPackage belongs to the calling UID
9958 mApp.getSystemService(AppOpsManager.class)
9959 .checkPackage(callingUid, callingPackage);
9960
9961 final long identity = Binder.clearCallingIdentity();
9962 try {
9963 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
9964 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9965
9966 if (result instanceof IllegalStateException) {
9967 throw (IllegalStateException) result;
9968 }
9969 } finally {
9970 Binder.restoreCallingIdentity(identity);
9971 }
9972 }
9973
9974 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
9975 int callingUid) {
9976 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
9977 // phone/system process do not have further restriction on request
9978 return;
9979 }
9980
9981 // Applications has restrictions on how to use the request:
9982 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
9983 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
9984 // This is not system caller which has been checked above
9985 throw new IllegalArgumentException(
9986 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
9987 }
9988
9989 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
9990 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
9991 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
9992 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
9993 || info.isEnabled()) {
9994 throw new IllegalArgumentException(
9995 "Only system can set hide fields in SignalThresholdInfo");
9996 }
9997
9998 // Thresholds length for each RAN need in range. This has been validated in
9999 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10000 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10001 final int[] thresholds = info.getThresholds();
10002 Objects.requireNonNull(thresholds);
10003 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10004 || thresholds.length
10005 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10006 throw new IllegalArgumentException(
10007 "thresholds length is out of range: " + thresholds.length);
10008 }
10009 }
10010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010011}