blob: eac13bb8c460d2c9f3988fc1eae8641411713224 [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;
Michele Berionned9fbae52020-11-13 02:36:59 +0000324 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700325
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800326 // Parameters of select command.
327 private static final int SELECT_COMMAND = 0xA4;
328 private static final int SELECT_P1 = 0x04;
329 private static final int SELECT_P2 = 0;
330 private static final int SELECT_P3 = 0x10;
331
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332 /** The singleton instance. */
333 private static PhoneInterfaceManager sInstance;
334
Wink Saville3ab207e2014-11-20 13:07:20 -0800335 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800336 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800337 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700338 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800339 private AppOpsManager mAppOps;
340 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800341 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800342 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700343 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344
Peter Wangdafb9ac2020-01-15 14:13:38 -0800345 /** User Activity */
346 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800347 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
348
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700349 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
350
Derek Tan97ebb422014-09-05 16:55:38 -0700351 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
352 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800353 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800354 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700355
Michelecea4cf22018-12-21 15:00:11 -0800356 // String to store multi SIM allowed
357 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
358
Derek Tan740e1672017-06-27 14:56:27 -0700359 // The AID of ISD-R.
360 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
361
yinxub1bed742017-04-17 11:45:04 -0700362 private NetworkScanRequestTracker mNetworkScanRequestTracker;
363
David Kelly5e06a7f2018-03-12 14:10:59 +0000364 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
365 private static final int MANUFACTURER_CODE_LENGTH = 8;
366
Jack Nudelman24d51a52020-11-24 12:08:04 -0800367 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
368
Derek Tan89e89d42014-07-08 17:00:10 -0700369 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700370 * Experiment flag to enable erase modem config on reset network, default value is false
371 */
372 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
373 "reset_network_erase_modem_config_enabled";
374
Rambo Wang0f050d82021-02-12 11:43:36 -0800375 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
376
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700377 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700378 * A request object to use for transmitting data to an ICC.
379 */
380 private static final class IccAPDUArgument {
381 public int channel, cla, command, p1, p2, p3;
382 public String data;
383
384 public IccAPDUArgument(int channel, int cla, int command,
385 int p1, int p2, int p3, String data) {
386 this.channel = channel;
387 this.cla = cla;
388 this.command = command;
389 this.p1 = p1;
390 this.p2 = p2;
391 this.p3 = p3;
392 this.data = data;
393 }
394 }
395
396 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700397 * A request object to use for transmitting data to an ICC.
398 */
399 private static final class ManualNetworkSelectionArgument {
400 public OperatorInfo operatorInfo;
401 public boolean persistSelection;
402
403 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
404 this.operatorInfo = operatorInfo;
405 this.persistSelection = persistSelection;
406 }
407 }
408
409 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
411 * request after sending. The main thread will notify the request when it is complete.
412 */
413 private static final class MainThreadRequest {
414 /** The argument to use for the request */
415 public Object argument;
416 /** The result of the request that is run on the main thread */
417 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800418 // The subscriber id that this request applies to. Defaults to
419 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
420 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421
Nathan Harold92bed182018-10-12 18:16:49 -0700422 // In cases where subId is unavailable, the caller needs to specify the phone.
423 public Phone phone;
424
vagdeviaf9a5b92018-08-15 16:01:53 -0700425 public WorkSource workSource;
426
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427 public MainThreadRequest(Object argument) {
428 this.argument = argument;
429 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800430
Nathan Harold92bed182018-10-12 18:16:49 -0700431 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
432 this.argument = argument;
433 if (phone != null) {
434 this.phone = phone;
435 }
436 this.workSource = workSource;
437 }
438
vagdeviaf9a5b92018-08-15 16:01:53 -0700439 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800440 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800441 if (subId != null) {
442 this.subId = subId;
443 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700444 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800445 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446 }
447
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800448 private static final class IncomingThirdPartyCallArgs {
449 public final ComponentName component;
450 public final String callId;
451 public final String callerDisplayName;
452
453 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
454 String callerDisplayName) {
455 this.component = component;
456 this.callId = callId;
457 this.callerDisplayName = callerDisplayName;
458 }
459 }
460
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700461 /**
462 * A handler that processes messages on the main thread in the phone process. Since many
463 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
464 * inbound binder threads to the main thread in the phone process. The Binder thread
465 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
466 * on, which will be notified when the operation completes and will contain the result of the
467 * request.
468 *
469 * <p>If a MainThreadRequest object is provided in the msg.obj field,
470 * note that request.result must be set to something non-null for the calling thread to
471 * unblock.
472 */
473 private final class MainThreadHandler extends Handler {
474 @Override
475 public void handleMessage(Message msg) {
476 MainThreadRequest request;
477 Message onCompleted;
478 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800479 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800481 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700482
483 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700484 case CMD_HANDLE_USSD_REQUEST: {
485 request = (MainThreadRequest) msg.obj;
486 final Phone phone = getPhoneFromRequest(request);
487 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
488 String ussdRequest = ussdObject.first;
489 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700490
Pengquan Menga1bb6272018-09-06 09:59:22 -0700491 if (!isUssdApiAllowed(request.subId)) {
492 // Carrier does not support use of this API, return failure.
493 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
494 UssdResponse response = new UssdResponse(ussdRequest, null);
495 Bundle returnData = new Bundle();
496 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
497 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700498
Pengquan Menga1bb6272018-09-06 09:59:22 -0700499 request.result = true;
500 notifyRequester(request);
501 return;
502 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700503
Pengquan Menga1bb6272018-09-06 09:59:22 -0700504 try {
505 request.result = phone != null
506 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
507 } catch (CallStateException cse) {
508 request.result = false;
509 }
510 // Wake up the requesting thread
511 notifyRequester(request);
512 break;
pkanwar32d516d2016-10-14 19:37:38 -0700513 }
514
Yorke Lee716f67e2015-06-17 15:39:16 -0700515 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700516 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700517 final Phone phone = getPhoneFromRequest(request);
518 request.result = phone != null ?
519 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
520 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700523 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700525
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700527 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800529 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700530 if (uiccCard == null) {
531 loge("iccTransmitApduLogicalChannel: No UICC");
532 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700534 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700535 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
536 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700537 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 iccArgument.channel, iccArgument.cla, iccArgument.command,
539 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700540 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700541 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700542 break;
543
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700544 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700545 ar = (AsyncResult) msg.obj;
546 request = (MainThreadRequest) ar.userObj;
547 if (ar.exception == null && ar.result != null) {
548 request.result = ar.result;
549 } else {
550 request.result = new IccIoResult(0x6F, 0, (byte[])null);
551 if (ar.result == null) {
552 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800553 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800555 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700556 } else {
557 loge("iccTransmitApduLogicalChannel: Unknown exception");
558 }
559 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 break;
562
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
564 request = (MainThreadRequest) msg.obj;
565 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800566 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 if (uiccCard == null) {
568 loge("iccTransmitApduBasicChannel: No UICC");
569 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700570 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 } else {
572 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
573 request);
574 uiccCard.iccTransmitApduBasicChannel(
575 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
576 iccArgument.p3, iccArgument.data, onCompleted);
577 }
578 break;
579
580 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
581 ar = (AsyncResult) msg.obj;
582 request = (MainThreadRequest) ar.userObj;
583 if (ar.exception == null && ar.result != null) {
584 request.result = ar.result;
585 } else {
586 request.result = new IccIoResult(0x6F, 0, (byte[])null);
587 if (ar.result == null) {
588 loge("iccTransmitApduBasicChannel: Empty response");
589 } else if (ar.exception instanceof CommandException) {
590 loge("iccTransmitApduBasicChannel: CommandException: " +
591 ar.exception);
592 } else {
593 loge("iccTransmitApduBasicChannel: Unknown exception");
594 }
595 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700596 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 break;
598
599 case CMD_EXCHANGE_SIM_IO:
600 request = (MainThreadRequest) msg.obj;
601 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800602 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 if (uiccCard == null) {
604 loge("iccExchangeSimIO: No UICC");
605 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700606 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700607 } else {
608 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
609 request);
610 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
611 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
612 iccArgument.data, onCompleted);
613 }
614 break;
615
616 case EVENT_EXCHANGE_SIM_IO_DONE:
617 ar = (AsyncResult) msg.obj;
618 request = (MainThreadRequest) ar.userObj;
619 if (ar.exception == null && ar.result != null) {
620 request.result = ar.result;
621 } else {
622 request.result = new IccIoResult(0x6f, 0, (byte[])null);
623 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 break;
626
Derek Tan4d5e5c12014-02-04 11:54:58 -0800627 case CMD_SEND_ENVELOPE:
628 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800629 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700630 if (uiccCard == null) {
631 loge("sendEnvelopeWithStatus: No UICC");
632 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700633 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700634 } else {
635 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
636 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
637 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800638 break;
639
640 case EVENT_SEND_ENVELOPE_DONE:
641 ar = (AsyncResult) msg.obj;
642 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700643 if (ar.exception == null && ar.result != null) {
644 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800645 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700646 request.result = new IccIoResult(0x6F, 0, (byte[])null);
647 if (ar.result == null) {
648 loge("sendEnvelopeWithStatus: Empty response");
649 } else if (ar.exception instanceof CommandException) {
650 loge("sendEnvelopeWithStatus: CommandException: " +
651 ar.exception);
652 } else {
653 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
654 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800655 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800657 break;
658
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 case CMD_OPEN_CHANNEL:
660 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800661 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800662 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700663 if (uiccCard == null) {
664 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800665 request.result = new IccOpenLogicalChannelResponse(-1,
666 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700667 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700668 } else {
669 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800670 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
671 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700672 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 break;
674
675 case EVENT_OPEN_CHANNEL_DONE:
676 ar = (AsyncResult) msg.obj;
677 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700678 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700680 int[] result = (int[]) ar.result;
681 int channelId = result[0];
682 byte[] selectResponse = null;
683 if (result.length > 1) {
684 selectResponse = new byte[result.length - 1];
685 for (int i = 1; i < result.length; ++i) {
686 selectResponse[i - 1] = (byte) result[i];
687 }
688 }
689 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700690 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 if (ar.result == null) {
693 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700695 if (ar.exception != null) {
696 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
697 }
698
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700699 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700700 if (ar.exception instanceof CommandException) {
701 CommandException.Error error =
702 ((CommandException) (ar.exception)).getCommandError();
703 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700704 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700705 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700706 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 }
708 }
709 openChannelResp = new IccOpenLogicalChannelResponse(
710 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700711 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700712 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700713 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 break;
715
716 case CMD_CLOSE_CHANNEL:
717 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800718 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700719 if (uiccCard == null) {
720 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900721 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700722 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700723 } else {
724 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
725 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
726 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700727 break;
728
729 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800730 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
731 break;
732
733 case CMD_NV_READ_ITEM:
734 request = (MainThreadRequest) msg.obj;
735 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800736 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
737 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800738 break;
739
740 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 ar = (AsyncResult) msg.obj;
742 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800743 if (ar.exception == null && ar.result != null) {
744 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700745 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800746 request.result = "";
747 if (ar.result == null) {
748 loge("nvReadItem: Empty response");
749 } else if (ar.exception instanceof CommandException) {
750 loge("nvReadItem: CommandException: " +
751 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700752 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800753 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700754 }
755 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700756 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700757 break;
758
Jake Hambye994d462014-02-03 13:10:13 -0800759 case CMD_NV_WRITE_ITEM:
760 request = (MainThreadRequest) msg.obj;
761 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
762 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800763 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700764 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800765 break;
766
767 case EVENT_NV_WRITE_ITEM_DONE:
768 handleNullReturnEvent(msg, "nvWriteItem");
769 break;
770
771 case CMD_NV_WRITE_CDMA_PRL:
772 request = (MainThreadRequest) msg.obj;
773 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800774 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800775 break;
776
777 case EVENT_NV_WRITE_CDMA_PRL_DONE:
778 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
779 break;
780
chen xu6dac5ab2018-10-26 17:39:23 -0700781 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800782 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700783 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800784 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800785 break;
786
chen xu6dac5ab2018-10-26 17:39:23 -0700787 case EVENT_RESET_MODEM_CONFIG_DONE:
788 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800789 break;
790
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700791 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
792 request = (MainThreadRequest) msg.obj;
793 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
794 request);
795 Phone phone = getPhoneFromRequest(request);
796 if (phone != null) {
797 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
798 } else {
799 loge("isNRDualConnectivityEnabled: No phone object");
800 request.result = false;
801 notifyRequester(request);
802 }
803 break;
804 }
805
806 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
807 ar = (AsyncResult) msg.obj;
808 request = (MainThreadRequest) ar.userObj;
809 if (ar.exception == null && ar.result != null) {
810 request.result = ar.result;
811 } else {
812 // request.result must be set to something non-null
813 // for the calling thread to unblock
814 if (request.result != null) {
815 request.result = ar.result;
816 } else {
817 request.result = false;
818 }
819 if (ar.result == null) {
820 loge("isNRDualConnectivityEnabled: Empty response");
821 } else if (ar.exception instanceof CommandException) {
822 loge("isNRDualConnectivityEnabled: CommandException: "
823 + ar.exception);
824 } else {
825 loge("isNRDualConnectivityEnabled: Unknown exception");
826 }
827 }
828 notifyRequester(request);
829 break;
830
831 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
832 request = (MainThreadRequest) msg.obj;
833 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
834 Phone phone = getPhoneFromRequest(request);
835 if (phone != null) {
836 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
837 request.workSource);
838 } else {
839 loge("enableNrDualConnectivity: No phone object");
840 request.result =
841 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
842 notifyRequester(request);
843 }
844 break;
845 }
846
847 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
848 ar = (AsyncResult) msg.obj;
849 request = (MainThreadRequest) ar.userObj;
850 if (ar.exception == null) {
851 request.result =
852 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
853 } else {
854 request.result =
855 TelephonyManager
856 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
857 if (ar.exception instanceof CommandException) {
858 CommandException.Error error =
859 ((CommandException) (ar.exception)).getCommandError();
860 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
861 request.result =
862 TelephonyManager
863 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
864 }
865 loge("enableNrDualConnectivity" + ": CommandException: "
866 + ar.exception);
867 } else {
868 loge("enableNrDualConnectivity" + ": Unknown exception");
869 }
870 }
871 notifyRequester(request);
872 break;
873 }
874
Jake Hamby7c27be32014-03-03 13:25:59 -0800875 case CMD_GET_PREFERRED_NETWORK_TYPE:
876 request = (MainThreadRequest) msg.obj;
877 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700878 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800879 break;
880
881 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
882 ar = (AsyncResult) msg.obj;
883 request = (MainThreadRequest) ar.userObj;
884 if (ar.exception == null && ar.result != null) {
885 request.result = ar.result; // Integer
886 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530887 // request.result must be set to something non-null
888 // for the calling thread to unblock
889 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800890 if (ar.result == null) {
891 loge("getPreferredNetworkType: Empty response");
892 } else if (ar.exception instanceof CommandException) {
893 loge("getPreferredNetworkType: CommandException: " +
894 ar.exception);
895 } else {
896 loge("getPreferredNetworkType: Unknown exception");
897 }
898 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700899 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800900 break;
901
902 case CMD_SET_PREFERRED_NETWORK_TYPE:
903 request = (MainThreadRequest) msg.obj;
904 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
905 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700906 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800907 break;
908
909 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
910 handleNullReturnEvent(msg, "setPreferredNetworkType");
911 break;
912
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000913 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
914 request = (MainThreadRequest)msg.obj;
915 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800916 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000917 break;
918
919 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
920 ar = (AsyncResult)msg.obj;
921 request = (MainThreadRequest)ar.userObj;
922 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700923 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000924 break;
925
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800926 case CMD_SET_VOICEMAIL_NUMBER:
927 request = (MainThreadRequest) msg.obj;
928 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
929 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800930 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
931 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800932 break;
933
934 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
935 handleNullReturnEvent(msg, "setVoicemailNumber");
936 break;
937
Stuart Scott54788802015-03-30 13:18:01 -0700938 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
939 request = (MainThreadRequest) msg.obj;
940 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
941 request);
942 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
943 break;
944
945 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
946 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
947 break;
948
Shishir Agrawal302c8692015-06-19 13:49:39 -0700949 case CMD_PERFORM_NETWORK_SCAN:
950 request = (MainThreadRequest) msg.obj;
951 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
952 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
953 break;
954
Hall Liua1acea22020-09-18 19:04:59 -0700955 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800956 request = (MainThreadRequest) msg.obj;
957 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700958 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
959 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
960 request.argument;
961 int callForwardingReason = args.first;
962 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800963 break;
Hall Liua1acea22020-09-18 19:04:59 -0700964 }
965 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800966 ar = (AsyncResult) msg.obj;
967 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700968 TelephonyManager.CallForwardingInfoCallback callback =
969 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
970 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800971 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700972 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800973 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
974 for (CallForwardInfo callForwardInfo : callForwardInfos) {
975 // Service Class is a bit mask per 3gpp 27.007. Search for
976 // any service for voice call.
977 if ((callForwardInfo.serviceClass
978 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700979 callForwardingInfo = new CallForwardingInfo(true,
980 callForwardInfo.reason,
981 callForwardInfo.number,
982 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800983 break;
984 }
985 }
986 // Didn't find a call forward info for voice call.
987 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700988 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
989 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800990 }
Hall Liua1acea22020-09-18 19:04:59 -0700991 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -0800992 } else {
993 if (ar.result == null) {
994 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
995 }
996 if (ar.exception != null) {
997 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
998 }
Hall Liuae527aa2020-09-29 17:10:18 -0700999 int errorCode = TelephonyManager
1000 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001001 if (ar.exception instanceof CommandException) {
1002 CommandException.Error error =
1003 ((CommandException) (ar.exception)).getCommandError();
1004 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001005 errorCode = TelephonyManager
1006 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001007 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001008 errorCode = TelephonyManager
1009 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001010 }
1011 }
Hall Liua1acea22020-09-18 19:04:59 -07001012 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001013 }
sqian80370722020-01-29 15:02:51 -08001014 break;
Hall Liua1acea22020-09-18 19:04:59 -07001015 }
sqian80370722020-01-29 15:02:51 -08001016
Hall Liua1acea22020-09-18 19:04:59 -07001017 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001018 request = (MainThreadRequest) msg.obj;
1019 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001020 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001021 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001022 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1023 request.argument).first;
1024 request.phone.setCallForwardingOption(
1025 callForwardingInfoToSet.isEnabled()
1026 ? CommandsInterface.CF_ACTION_ENABLE
1027 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001028 callForwardingInfoToSet.getReason(),
1029 callForwardingInfoToSet.getNumber(),
1030 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1031 break;
Hall Liua1acea22020-09-18 19:04:59 -07001032 }
sqian80370722020-01-29 15:02:51 -08001033
Hall Liua1acea22020-09-18 19:04:59 -07001034 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001035 ar = (AsyncResult) msg.obj;
1036 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001037 Consumer<Integer> callback =
1038 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1039 request.argument).second;
1040 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001041 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001042 int errorCode = TelephonyManager.CallForwardingInfoCallback
1043 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001044 if (ar.exception instanceof CommandException) {
1045 CommandException.Error error =
1046 ((CommandException) (ar.exception)).getCommandError();
1047 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001048 errorCode = TelephonyManager.CallForwardingInfoCallback
1049 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001050 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001051 errorCode = TelephonyManager.CallForwardingInfoCallback
1052 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001053 }
1054 }
1055 callback.accept(errorCode);
1056 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001057 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001058 }
sqian80370722020-01-29 15:02:51 -08001059 break;
Hall Liua1acea22020-09-18 19:04:59 -07001060 }
sqian80370722020-01-29 15:02:51 -08001061
Hall Liua1acea22020-09-18 19:04:59 -07001062 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001063 request = (MainThreadRequest) msg.obj;
1064 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1065 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1066 break;
Hall Liua1acea22020-09-18 19:04:59 -07001067 }
sqian80370722020-01-29 15:02:51 -08001068
Hall Liua1acea22020-09-18 19:04:59 -07001069 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001070 ar = (AsyncResult) msg.obj;
1071 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001072 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001073 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1074 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001075 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001076 // Service Class is a bit mask per 3gpp 27.007.
1077 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001078 if (callForwardResults.length > 1
1079 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001080 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001081 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001082 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1083 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001084 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001085 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001086 }
1087 } else {
1088 if (ar.result == null) {
1089 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1090 }
1091 if (ar.exception != null) {
1092 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1093 }
1094 if (ar.exception instanceof CommandException) {
1095 CommandException.Error error =
1096 ((CommandException) (ar.exception)).getCommandError();
1097 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1098 callForwardingStatus =
1099 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1100 }
1101 }
1102 }
Hall Liua1acea22020-09-18 19:04:59 -07001103 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001104 break;
Hall Liua1acea22020-09-18 19:04:59 -07001105 }
sqian80370722020-01-29 15:02:51 -08001106
Hall Liua1acea22020-09-18 19:04:59 -07001107 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001108 request = (MainThreadRequest) msg.obj;
1109 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001110 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1111 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001112 break;
Hall Liua1acea22020-09-18 19:04:59 -07001113 }
sqian80370722020-01-29 15:02:51 -08001114
Hall Liua1acea22020-09-18 19:04:59 -07001115 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001116 ar = (AsyncResult) msg.obj;
1117 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001118 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1119 Consumer<Integer> callback =
1120 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1121 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001122 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001123 if (ar.exception instanceof CommandException) {
1124 CommandException.Error error =
1125 ((CommandException) (ar.exception)).getCommandError();
1126 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1127 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1128 } else {
1129 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1130 }
1131 } else {
1132 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1133 }
1134 } else {
1135 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1136 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001137 }
sqian80370722020-01-29 15:02:51 -08001138 break;
Hall Liua1acea22020-09-18 19:04:59 -07001139 }
sqian80370722020-01-29 15:02:51 -08001140
Shishir Agrawal302c8692015-06-19 13:49:39 -07001141 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1142 ar = (AsyncResult) msg.obj;
1143 request = (MainThreadRequest) ar.userObj;
1144 CellNetworkScanResult cellScanResult;
1145 if (ar.exception == null && ar.result != null) {
1146 cellScanResult = new CellNetworkScanResult(
1147 CellNetworkScanResult.STATUS_SUCCESS,
1148 (List<OperatorInfo>) ar.result);
1149 } else {
1150 if (ar.result == null) {
1151 loge("getCellNetworkScanResults: Empty response");
1152 }
1153 if (ar.exception != null) {
1154 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1155 }
1156 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1157 if (ar.exception instanceof CommandException) {
1158 CommandException.Error error =
1159 ((CommandException) (ar.exception)).getCommandError();
1160 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1161 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1162 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1163 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1164 }
1165 }
1166 cellScanResult = new CellNetworkScanResult(errorCode, null);
1167 }
1168 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001169 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001170 break;
1171
1172 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1173 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001174 ManualNetworkSelectionArgument selArg =
1175 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001176 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1177 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001178 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1179 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001180 break;
1181
1182 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001183 ar = (AsyncResult) msg.obj;
1184 request = (MainThreadRequest) ar.userObj;
1185 if (ar.exception == null) {
1186 request.result = true;
1187 } else {
1188 request.result = false;
1189 loge("setNetworkSelectionModeManual " + ar.exception);
1190 }
1191 notifyRequester(request);
1192 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001193 break;
1194
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001195 case CMD_GET_MODEM_ACTIVITY_INFO:
1196 request = (MainThreadRequest) msg.obj;
1197 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001198 if (defaultPhone != null) {
1199 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001200 } else {
1201 ResultReceiver result = (ResultReceiver) request.argument;
1202 Bundle bundle = new Bundle();
1203 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1204 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1205 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001206 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001207 break;
1208
1209 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1210 ar = (AsyncResult) msg.obj;
1211 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001212 ResultReceiver result = (ResultReceiver) request.argument;
1213
1214 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001215 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001216 // Update the last modem activity info and the result of the request.
1217 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1218 if (isModemActivityInfoValid(info)) {
1219 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1220 int[] txTimeMs = info.getTransmitTimeMillis();
1221 int[] lastModemTxTimeMs = mLastModemActivityInfo
1222 .getTransmitTimeMillis();
1223 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1224 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1225 }
1226 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1227 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1228 + mLastModemActivityInfo.getSleepTimeMillis());
1229 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1230 + mLastModemActivityInfo.getIdleTimeMillis());
1231 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1232 mLastModemActivityInfo.setReceiveTimeMillis(
1233 info.getReceiveTimeMillis()
1234 + mLastModemActivityInfo.getReceiveTimeMillis());
1235 }
1236 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1237 mLastModemActivityInfo.getSleepTimeMillis(),
1238 mLastModemActivityInfo.getIdleTimeMillis(),
1239 mLastModemActivityInfo.getTransmitTimeMillis(),
1240 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001241 } else {
1242 if (ar.result == null) {
1243 loge("queryModemActivityInfo: Empty response");
1244 } else if (ar.exception instanceof CommandException) {
1245 loge("queryModemActivityInfo: CommandException: " +
1246 ar.exception);
1247 } else {
1248 loge("queryModemActivityInfo: Unknown exception");
1249 }
1250 }
sqian1a1be542020-03-05 11:37:28 -08001251 Bundle bundle = new Bundle();
1252 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1253 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001254 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001255 break;
1256
Meng Wang1a7c35a2016-05-05 20:56:15 -07001257 case CMD_SET_ALLOWED_CARRIERS:
1258 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001259 CarrierRestrictionRules argument =
1260 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001261 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001262 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001263 break;
1264
1265 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1266 ar = (AsyncResult) msg.obj;
1267 request = (MainThreadRequest) ar.userObj;
1268 if (ar.exception == null && ar.result != null) {
1269 request.result = ar.result;
1270 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001271 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1272 if (ar.exception instanceof CommandException) {
1273 loge("setAllowedCarriers: CommandException: " + ar.exception);
1274 CommandException.Error error =
1275 ((CommandException) (ar.exception)).getCommandError();
1276 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1277 request.result =
1278 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1279 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001280 } else {
1281 loge("setAllowedCarriers: Unknown exception");
1282 }
1283 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001284 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001285 break;
1286
1287 case CMD_GET_ALLOWED_CARRIERS:
1288 request = (MainThreadRequest) msg.obj;
1289 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001290 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001291 break;
1292
1293 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1294 ar = (AsyncResult) msg.obj;
1295 request = (MainThreadRequest) ar.userObj;
1296 if (ar.exception == null && ar.result != null) {
1297 request.result = ar.result;
1298 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001299 request.result = new IllegalStateException(
1300 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001301 if (ar.result == null) {
1302 loge("getAllowedCarriers: Empty response");
1303 } else if (ar.exception instanceof CommandException) {
1304 loge("getAllowedCarriers: CommandException: " +
1305 ar.exception);
1306 } else {
1307 loge("getAllowedCarriers: Unknown exception");
1308 }
1309 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001310 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001311 break;
1312
Nathan Haroldb3014052017-01-25 15:57:32 -08001313 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1314 ar = (AsyncResult) msg.obj;
1315 request = (MainThreadRequest) ar.userObj;
1316 if (ar.exception == null && ar.result != null) {
1317 request.result = ar.result;
1318 } else {
1319 request.result = new IllegalArgumentException(
1320 "Failed to retrieve Forbidden Plmns");
1321 if (ar.result == null) {
1322 loge("getForbiddenPlmns: Empty response");
1323 } else {
1324 loge("getForbiddenPlmns: Unknown exception");
1325 }
1326 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001327 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001328 break;
1329
1330 case CMD_GET_FORBIDDEN_PLMNS:
1331 request = (MainThreadRequest) msg.obj;
1332 uiccCard = getUiccCardFromRequest(request);
1333 if (uiccCard == null) {
1334 loge("getForbiddenPlmns() UiccCard is null");
1335 request.result = new IllegalArgumentException(
1336 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001337 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001338 break;
1339 }
1340 Integer appType = (Integer) request.argument;
1341 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1342 if (uiccApp == null) {
1343 loge("getForbiddenPlmns() no app with specified type -- "
1344 + appType);
1345 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001346 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001347 break;
1348 } else {
1349 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1350 + " specified type -- " + appType);
1351 }
1352 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1353 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1354 onCompleted);
1355 break;
1356
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001357 case CMD_SWITCH_SLOTS:
1358 request = (MainThreadRequest) msg.obj;
1359 int[] physicalSlots = (int[]) request.argument;
1360 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1361 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1362 break;
1363
1364 case EVENT_SWITCH_SLOTS_DONE:
1365 ar = (AsyncResult) msg.obj;
1366 request = (MainThreadRequest) ar.userObj;
1367 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001368 notifyRequester(request);
1369 break;
1370 case CMD_GET_NETWORK_SELECTION_MODE:
1371 request = (MainThreadRequest) msg.obj;
1372 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1373 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1374 break;
1375
1376 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1377 ar = (AsyncResult) msg.obj;
1378 request = (MainThreadRequest) ar.userObj;
1379 if (ar.exception != null) {
1380 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1381 } else {
1382 int mode = ((int[]) ar.result)[0];
1383 if (mode == 0) {
1384 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1385 } else {
1386 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1387 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001388 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001389 notifyRequester(request);
1390 break;
1391 case CMD_GET_CDMA_ROAMING_MODE:
1392 request = (MainThreadRequest) msg.obj;
1393 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1394 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1395 break;
1396 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1397 ar = (AsyncResult) msg.obj;
1398 request = (MainThreadRequest) ar.userObj;
1399 if (ar.exception != null) {
1400 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1401 } else {
1402 request.result = ((int[]) ar.result)[0];
1403 }
1404 notifyRequester(request);
1405 break;
1406 case CMD_SET_CDMA_ROAMING_MODE:
1407 request = (MainThreadRequest) msg.obj;
1408 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1409 int mode = (int) request.argument;
1410 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1411 break;
1412 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1413 ar = (AsyncResult) msg.obj;
1414 request = (MainThreadRequest) ar.userObj;
1415 request.result = ar.exception == null;
1416 notifyRequester(request);
1417 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001418 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1419 request = (MainThreadRequest) msg.obj;
1420 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1421 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1422 break;
1423 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1424 ar = (AsyncResult) msg.obj;
1425 request = (MainThreadRequest) ar.userObj;
1426 if (ar.exception != null) {
1427 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1428 } else {
1429 request.result = ((int[]) ar.result)[0];
1430 }
1431 notifyRequester(request);
1432 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001433 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1434 request = (MainThreadRequest) msg.obj;
1435 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1436 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001437 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1438 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001439 break;
1440 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1441 ar = (AsyncResult) msg.obj;
1442 request = (MainThreadRequest) ar.userObj;
1443 request.result = ar.exception == null;
1444 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001445 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001446 case CMD_GET_ALL_CELL_INFO:
1447 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001448 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001449 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001450 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001451 case EVENT_GET_ALL_CELL_INFO_DONE:
1452 ar = (AsyncResult) msg.obj;
1453 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001454 // If a timeout occurs, the response will be null
1455 request.result = (ar.exception == null && ar.result != null)
1456 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001457 synchronized (request) {
1458 request.notifyAll();
1459 }
1460 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001461 case CMD_REQUEST_CELL_INFO_UPDATE:
1462 request = (MainThreadRequest) msg.obj;
1463 request.phone.requestCellInfoUpdate(request.workSource,
1464 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1465 break;
1466 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1467 ar = (AsyncResult) msg.obj;
1468 request = (MainThreadRequest) ar.userObj;
1469 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1470 try {
1471 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001472 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001473 cb.onError(
1474 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1475 ar.exception.getClass().getName(),
1476 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001477 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001478 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001479 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001480 } else {
1481 // use the result as returned
1482 cb.onCellInfo((List<CellInfo>) ar.result);
1483 }
1484 } catch (RemoteException re) {
1485 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1486 }
1487 break;
Sarah Chincc055732020-11-18 13:39:35 -08001488 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001489 request = (MainThreadRequest) msg.obj;
1490 WorkSource ws = (WorkSource) request.argument;
1491 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001492 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001493 break;
Sarah Chincc055732020-11-18 13:39:35 -08001494 }
1495 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001496 ar = (AsyncResult) msg.obj;
1497 request = (MainThreadRequest) ar.userObj;
1498 if (ar.exception == null) {
1499 request.result = ar.result;
1500 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001501 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001502 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001503 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001504 }
1505
1506 synchronized (request) {
1507 request.notifyAll();
1508 }
1509 break;
Sarah Chincc055732020-11-18 13:39:35 -08001510 }
chen xu6dac5ab2018-10-26 17:39:23 -07001511 case CMD_MODEM_REBOOT:
1512 request = (MainThreadRequest) msg.obj;
1513 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001514 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001515 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001516 case EVENT_CMD_MODEM_REBOOT_DONE:
1517 handleNullReturnEvent(msg, "rebootModem");
1518 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001519 case CMD_REQUEST_ENABLE_MODEM:
1520 request = (MainThreadRequest) msg.obj;
1521 boolean enable = (boolean) request.argument;
1522 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001523 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001524 PhoneConfigurationManager.getInstance()
1525 .enablePhone(request.phone, enable, onCompleted);
1526 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001527 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001528 ar = (AsyncResult) msg.obj;
1529 request = (MainThreadRequest) ar.userObj;
1530 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001531 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001532 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001533 if ((boolean) request.result) {
1534 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1535 updateModemStateMetrics();
1536 } else {
1537 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1538 + ar.exception);
1539 }
1540 notifyRequester(request);
1541 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001542 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001543 case CMD_GET_MODEM_STATUS:
1544 request = (MainThreadRequest) msg.obj;
1545 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1546 PhoneConfigurationManager.getInstance()
1547 .getPhoneStatusFromModem(request.phone, onCompleted);
1548 break;
1549 case EVENT_GET_MODEM_STATUS_DONE:
1550 ar = (AsyncResult) msg.obj;
1551 request = (MainThreadRequest) ar.userObj;
1552 int id = request.phone.getPhoneId();
1553 if (ar.exception == null && ar.result != null) {
1554 request.result = ar.result;
1555 //update the cache as modem status has changed
1556 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1557 (boolean) request.result);
1558 } else {
1559 // Return true if modem status cannot be retrieved. For most cases,
1560 // modem status is on. And for older version modems, GET_MODEM_STATUS
1561 // and disable modem are not supported. Modem is always on.
1562 // TODO: this should be fixed in R to support a third
1563 // status UNKNOWN b/131631629
1564 request.result = true;
1565 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1566 + ar.exception);
1567 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001568 notifyRequester(request);
1569 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001570 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1571 request = (MainThreadRequest) msg.obj;
1572 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1573 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1574 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1575 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1576 break;
1577 }
1578 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1579 ar = (AsyncResult) msg.obj;
1580 request = (MainThreadRequest) ar.userObj;
1581 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1582 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1583 args.second.accept(ar.exception == null);
1584 notifyRequester(request);
1585 break;
1586 }
Sarah Chincc055732020-11-18 13:39:35 -08001587 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1588 request = (MainThreadRequest) msg.obj;
1589 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1590 Phone phone = getPhoneFromRequest(request);
1591 if (phone != null) {
1592 phone.getSystemSelectionChannels(onCompleted);
1593 } else {
1594 loge("getSystemSelectionChannels: No phone object");
1595 request.result = new ArrayList<RadioAccessSpecifier>();
1596 notifyRequester(request);
1597 }
1598 break;
1599 }
1600 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1601 ar = (AsyncResult) msg.obj;
1602 request = (MainThreadRequest) ar.userObj;
1603 if (ar.exception == null && ar.result != null) {
1604 request.result = ar.result;
1605 } else {
1606 request.result = new IllegalArgumentException(
1607 "Failed to retrieve system selection channels");
1608 if (ar.result == null) {
1609 loge("getSystemSelectionChannels: Empty response");
1610 } else {
1611 loge("getSystemSelectionChannels: Unknown exception");
1612 }
1613 }
1614 notifyRequester(request);
1615 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001616 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1617 ar = (AsyncResult) msg.obj;
1618 request = (MainThreadRequest) ar.userObj;
1619 if (ar.exception == null && ar.result != null) {
1620 request.result = ar.result;
1621 } else {
1622 request.result = -1;
1623 loge("Failed to set Forbidden Plmns");
1624 if (ar.result == null) {
1625 loge("setForbidenPlmns: Empty response");
1626 } else if (ar.exception != null) {
1627 loge("setForbiddenPlmns: Exception: " + ar.exception);
1628 request.result = -1;
1629 } else {
1630 loge("setForbiddenPlmns: Unknown exception");
1631 }
1632 }
1633 notifyRequester(request);
1634 break;
1635 case CMD_SET_FORBIDDEN_PLMNS:
1636 request = (MainThreadRequest) msg.obj;
1637 uiccCard = getUiccCardFromRequest(request);
1638 if (uiccCard == null) {
1639 loge("setForbiddenPlmns: UiccCard is null");
1640 request.result = -1;
1641 notifyRequester(request);
1642 break;
1643 }
1644 Pair<Integer, List<String>> setFplmnsArgs =
1645 (Pair<Integer, List<String>>) request.argument;
1646 appType = setFplmnsArgs.first;
1647 List<String> fplmns = setFplmnsArgs.second;
1648 uiccApp = uiccCard.getApplicationByType(appType);
1649 if (uiccApp == null) {
1650 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1651 request.result = -1;
1652 loge("Failed to get UICC App");
1653 notifyRequester(request);
1654 } else {
1655 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1656 ((SIMRecords) uiccApp.getIccRecords())
1657 .setForbiddenPlmns(onCompleted, fplmns);
1658 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001659 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001660 case CMD_ERASE_MODEM_CONFIG:
1661 request = (MainThreadRequest) msg.obj;
1662 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1663 defaultPhone.eraseModemConfig(onCompleted);
1664 break;
1665 case EVENT_ERASE_MODEM_CONFIG_DONE:
1666 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001667 break;
zoey chenf95ca592019-12-30 16:11:23 +08001668
1669 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1670 request = (MainThreadRequest) msg.obj;
1671 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1672 Pair<String, String> changed = (Pair<String, String>) request.argument;
1673 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1674 changed.first, changed.second, onCompleted);
1675 break;
1676 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1677 ar = (AsyncResult) msg.obj;
1678 request = (MainThreadRequest) ar.userObj;
1679 if (ar.exception == null) {
1680 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001681 // If the operation is successful, update the PIN storage
1682 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1683 int phoneId = getPhoneFromRequest(request).getPhoneId();
1684 UiccController.getInstance().getPinStorage()
1685 .storePin(passwords.second, phoneId);
zoey chenf95ca592019-12-30 16:11:23 +08001686 } else {
1687 request.result = msg.arg1;
1688 }
1689 notifyRequester(request);
1690 break;
1691
Michele Berionned9fbae52020-11-13 02:36:59 +00001692 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001693 request = (MainThreadRequest) msg.obj;
1694 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1695 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1696 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1697 enabled.first, enabled.second, onCompleted);
1698 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001699 }
zoey chenf95ca592019-12-30 16:11:23 +08001700 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1701 ar = (AsyncResult) msg.obj;
1702 request = (MainThreadRequest) ar.userObj;
1703 if (ar.exception == null) {
1704 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001705 // If the operation is successful, update the PIN storage
1706 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1707 int phoneId = getPhoneFromRequest(request).getPhoneId();
1708 if (enabled.first) {
1709 UiccController.getInstance().getPinStorage()
1710 .storePin(enabled.second, phoneId);
1711 } else {
1712 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1713 }
zoey chenf95ca592019-12-30 16:11:23 +08001714 } else {
1715 request.result = msg.arg1;
1716 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001717
1718
zoey chenf95ca592019-12-30 16:11:23 +08001719 notifyRequester(request);
1720 break;
1721
Peter Wangdafb9ac2020-01-15 14:13:38 -08001722 case MSG_NOTIFY_USER_ACTIVITY:
1723 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001724 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001725 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1726 getDefaultPhone().getContext().sendBroadcastAsUser(
1727 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1728 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001729
1730 case CMD_SET_DATA_THROTTLING: {
1731 request = (MainThreadRequest) msg.obj;
1732 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1733 DataThrottlingRequest dataThrottlingRequest =
1734 (DataThrottlingRequest) request.argument;
1735 Phone phone = getPhoneFromRequest(request);
1736 if (phone != null) {
1737 phone.setDataThrottling(onCompleted,
1738 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1739 dataThrottlingRequest.getCompletionDurationMillis());
1740 } else {
1741 loge("setDataThrottling: No phone object");
1742 request.result =
1743 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1744 notifyRequester(request);
1745 }
1746
1747 break;
1748 }
1749 case EVENT_SET_DATA_THROTTLING_DONE:
1750 ar = (AsyncResult) msg.obj;
1751 request = (MainThreadRequest) ar.userObj;
1752
1753 if (ar.exception == null) {
1754 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1755 } else if (ar.exception instanceof CommandException) {
1756 loge("setDataThrottling: CommandException: " + ar.exception);
1757 CommandException.Error error =
1758 ((CommandException) (ar.exception)).getCommandError();
1759
1760 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1761 request.result = TelephonyManager
1762 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1763 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1764 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1765 } else {
1766 request.result =
1767 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1768 }
1769 } else {
1770 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1771 }
1772 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1773 notifyRequester(request);
1774 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001775
1776 case CMD_SET_SIM_POWER: {
1777 request = (MainThreadRequest) msg.obj;
1778 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1779 request = (MainThreadRequest) msg.obj;
1780 int stateToSet =
1781 ((Pair<Integer, IIntegerConsumer>)
1782 request.argument).first;
1783 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1784 break;
1785 }
1786 case EVENT_SET_SIM_POWER_DONE: {
1787 ar = (AsyncResult) msg.obj;
1788 request = (MainThreadRequest) ar.userObj;
1789 IIntegerConsumer callback =
1790 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1791 if (ar.exception != null) {
1792 loge("setSimPower exception: " + ar.exception);
1793 int errorCode = TelephonyManager.CallForwardingInfoCallback
1794 .RESULT_ERROR_UNKNOWN;
1795 if (ar.exception instanceof CommandException) {
1796 CommandException.Error error =
1797 ((CommandException) (ar.exception)).getCommandError();
1798 if (error == CommandException.Error.SIM_ERR) {
1799 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1800 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1801 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1802 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1803 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1804 } else {
1805 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1806 }
1807 }
1808 try {
1809 callback.accept(errorCode);
1810 } catch (RemoteException e) {
1811 // Ignore if the remote process is no longer available to call back.
1812 Log.w(LOG_TAG, "setSimPower: callback not available.");
1813 }
1814 } else {
1815 try {
1816 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1817 } catch (RemoteException e) {
1818 // Ignore if the remote process is no longer available to call back.
1819 Log.w(LOG_TAG, "setSimPower: callback not available.");
1820 }
1821 }
1822 break;
1823 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001824 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1825 request = (MainThreadRequest) msg.obj;
1826
1827 final Phone phone = getPhoneFromRequest(request);
1828 if (phone == null || phone.getServiceStateTracker() == null) {
1829 request.result = new IllegalStateException("Phone or SST is null");
1830 notifyRequester(request);
1831 break;
1832 }
1833
1834 Pair<Integer, SignalStrengthUpdateRequest> pair =
1835 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1836 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1837 request);
1838 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1839 request.subId, pair.first /*callingUid*/,
1840 pair.second /*request*/, onCompleted);
1841 break;
1842 }
1843 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1844 ar = (AsyncResult) msg.obj;
1845 request = (MainThreadRequest) ar.userObj;
1846 // request.result will be the exception of ar if present, true otherwise.
1847 // Be cautious not to leave result null which will wait() forever
1848 request.result = ar.exception != null ? ar.exception : true;
1849 notifyRequester(request);
1850 break;
1851 }
1852 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1853 request = (MainThreadRequest) msg.obj;
1854
1855 Phone phone = getPhoneFromRequest(request);
1856 if (phone == null || phone.getServiceStateTracker() == null) {
1857 request.result = new IllegalStateException("Phone or SST is null");
1858 notifyRequester(request);
1859 break;
1860 }
1861
1862 Pair<Integer, SignalStrengthUpdateRequest> pair =
1863 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1864 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1865 request);
1866 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1867 request.subId, pair.first /*callingUid*/,
1868 pair.second /*request*/, onCompleted);
1869 break;
1870 }
1871 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1872 ar = (AsyncResult) msg.obj;
1873 request = (MainThreadRequest) ar.userObj;
1874 request.result = ar.exception != null ? ar.exception : true;
1875 notifyRequester(request);
1876 break;
1877 }
Jordan Liud5366d92020-11-24 14:50:34 -08001878
Michele Berionned9fbae52020-11-13 02:36:59 +00001879 case CMD_PREPARE_UNATTENDED_REBOOT:
1880 request = (MainThreadRequest) msg.obj;
1881 request.result =
1882 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1883 notifyRequester(request);
1884 break;
1885
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001886 default:
1887 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1888 break;
1889 }
1890 }
Jake Hambye994d462014-02-03 13:10:13 -08001891
Pengquan Menga1bb6272018-09-06 09:59:22 -07001892 private void notifyRequester(MainThreadRequest request) {
1893 synchronized (request) {
1894 request.notifyAll();
1895 }
1896 }
1897
Jake Hambye994d462014-02-03 13:10:13 -08001898 private void handleNullReturnEvent(Message msg, String command) {
1899 AsyncResult ar = (AsyncResult) msg.obj;
1900 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1901 if (ar.exception == null) {
1902 request.result = true;
1903 } else {
1904 request.result = false;
1905 if (ar.exception instanceof CommandException) {
1906 loge(command + ": CommandException: " + ar.exception);
1907 } else {
1908 loge(command + ": Unknown exception");
1909 }
1910 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001911 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001912 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001913 }
1914
1915 /**
1916 * Posts the specified command to be executed on the main thread,
1917 * waits for the request to complete, and returns the result.
1918 * @see #sendRequestAsync
1919 */
1920 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001921 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1922 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001923 }
1924
1925 /**
1926 * Posts the specified command to be executed on the main thread,
1927 * waits for the request to complete, and returns the result.
1928 * @see #sendRequestAsync
1929 */
1930 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1931 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001932 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001933 }
1934
1935 /**
1936 * Posts the specified command to be executed on the main thread,
1937 * waits for the request to complete, and returns the result.
1938 * @see #sendRequestAsync
1939 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001940 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001941 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1942 }
1943
1944 /**
1945 * Posts the specified command to be executed on the main thread,
1946 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1947 * if not timeout or null otherwise.
1948 * @see #sendRequestAsync
1949 */
1950 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1951 long timeoutInMs) {
1952 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001953 }
1954
1955 /**
1956 * Posts the specified command to be executed on the main thread,
1957 * waits for the request to complete, and returns the result.
1958 * @see #sendRequestAsync
1959 */
Nathan Harold92bed182018-10-12 18:16:49 -07001960 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001961 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001962 }
1963
1964 /**
1965 * Posts the specified command to be executed on the main thread,
1966 * waits for the request to complete, and returns the result.
1967 * @see #sendRequestAsync
1968 */
1969 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001970 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1971 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001972 }
1973
1974 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08001975 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
1976 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
1977 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07001978 * @see #sendRequestAsync
1979 */
Rambo Wang0f050d82021-02-12 11:43:36 -08001980 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
1981 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1983 throw new RuntimeException("This method will deadlock if called from the main thread.");
1984 }
1985
Nathan Harold92bed182018-10-12 18:16:49 -07001986 MainThreadRequest request = null;
1987 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1988 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1989 } else if (phone != null) {
1990 request = new MainThreadRequest(argument, phone, workSource);
1991 } else {
1992 request = new MainThreadRequest(argument, subId, workSource);
1993 }
1994
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995 Message msg = mMainThreadHandler.obtainMessage(command, request);
1996 msg.sendToTarget();
1997
Rambo Wang0f050d82021-02-12 11:43:36 -08001998
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002000 if (timeoutInMs >= 0) {
2001 // Wait for at least timeoutInMs before returning null request result
2002 long now = SystemClock.elapsedRealtime();
2003 long deadline = now + timeoutInMs;
2004 while (request == null && now < deadline) {
2005 try {
2006 request.wait(deadline - now);
2007 } catch (InterruptedException e) {
2008 // Do nothing, go back and check if request is completed or timeout
2009 } finally {
2010 now = SystemClock.elapsedRealtime();
2011 }
2012 }
2013 } else {
2014 // Wait for the request to complete
2015 while (request.result == null) {
2016 try {
2017 request.wait();
2018 } catch (InterruptedException e) {
2019 // Do nothing, go back and wait until the request is complete
2020 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002021 }
2022 }
2023 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002024 if (request.result == null) {
2025 Log.wtf(LOG_TAG,
2026 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002028 return request.result;
2029 }
2030
2031 /**
2032 * Asynchronous ("fire and forget") version of sendRequest():
2033 * Posts the specified command to be executed on the main thread, and
2034 * returns immediately.
2035 * @see #sendRequest
2036 */
2037 private void sendRequestAsync(int command) {
2038 mMainThreadHandler.sendEmptyMessage(command);
2039 }
2040
2041 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002042 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002043 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002044 */
2045 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002046 sendRequestAsync(command, argument, null, null);
2047 }
2048
2049 /**
2050 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2051 * @see {@link #sendRequest(int,Object)}
2052 */
2053 private void sendRequestAsync(
2054 int command, Object argument, Phone phone, WorkSource workSource) {
2055 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002056 Message msg = mMainThreadHandler.obtainMessage(command, request);
2057 msg.sendToTarget();
2058 }
2059
2060 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002061 * Initialize the singleton PhoneInterfaceManager instance.
2062 * This is only done once, at startup, from PhoneApp.onCreate().
2063 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002064 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002065 synchronized (PhoneInterfaceManager.class) {
2066 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002067 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002068 } else {
2069 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2070 }
2071 return sInstance;
2072 }
2073 }
2074
2075 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002076 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002077 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002078 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08002079 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002080 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002081 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2082 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002083 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002084 mTelephonySharedPreferences =
2085 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002086 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002087 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002088 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002089
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 publish();
2091 }
2092
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002093 private Phone getDefaultPhone() {
2094 Phone thePhone = getPhone(getDefaultSubscription());
2095 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2096 }
2097
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 private void publish() {
2099 if (DBG) log("publish: " + this);
2100
Peter Wangc035ce42020-01-08 21:00:22 -08002101 TelephonyFrameworkInitializer
2102 .getTelephonyServiceManager()
2103 .getTelephonyServiceRegisterer()
2104 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002105 }
2106
Stuart Scott584921c2015-01-15 17:10:34 -08002107 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002108 if (request.phone != null) {
2109 return request.phone;
2110 } else {
2111 return getPhoneFromSubId(request.subId);
2112 }
2113 }
2114
2115 private Phone getPhoneFromSubId(int subId) {
2116 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2117 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002118 }
2119
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002120 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2121 Phone phone = getPhoneFromRequest(request);
2122 return phone == null ? null :
2123 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2124 }
2125
Wink Saville36469e72014-06-11 15:17:00 -07002126 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002127 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002128 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002129 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002130
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002131 private void sendEraseModemConfig(Phone phone) {
2132 if (phone != null) {
2133 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2134 mApp, phone.getSubId(), "eraseModemConfig");
2135 final long identity = Binder.clearCallingIdentity();
2136 try {
2137 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2138 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2139 } finally {
2140 Binder.restoreCallingIdentity(identity);
2141 }
2142 }
2143 }
2144
Peter Wang050bb052020-01-13 23:33:09 -08002145 private boolean isImsAvailableOnDevice() {
2146 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2147 if (pm == null) {
2148 // For some reason package manger is not available.. This will fail internally anyway,
2149 // so do not throw error and allow.
2150 return true;
2151 }
2152 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2153 }
2154
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002156 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002157 }
2158
Wink Savilleb564aae2014-10-23 10:18:09 -07002159 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 if (DBG) log("dial: " + number);
2161 // No permission check needed here: This is just a wrapper around the
2162 // ACTION_DIAL intent, which is available to any app since it puts up
2163 // the UI before it does anything.
2164
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002165 final long identity = Binder.clearCallingIdentity();
2166 try {
2167 String url = createTelUrl(number);
2168 if (url == null) {
2169 return;
2170 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002172 // PENDING: should we just silently fail if phone is offhook or ringing?
2173 PhoneConstants.State state = mCM.getState(subId);
2174 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2175 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2176 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2177 mApp.startActivity(intent);
2178 }
2179 } finally {
2180 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 }
2182 }
2183
2184 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002185 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002186 }
2187
Wink Savilleb564aae2014-10-23 10:18:09 -07002188 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 if (DBG) log("call: " + number);
2190
2191 // This is just a wrapper around the ACTION_CALL intent, but we still
2192 // need to do a permission check since we're calling startActivity()
2193 // from the context of the phone app.
2194 enforceCallPermission();
2195
Jordan Liu1617b712019-07-10 15:06:26 -07002196 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 != AppOpsManager.MODE_ALLOWED) {
2198 return;
2199 }
2200
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002201 final long identity = Binder.clearCallingIdentity();
2202 try {
2203 String url = createTelUrl(number);
2204 if (url == null) {
2205 return;
2206 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002207
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002208 boolean isValid = false;
2209 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2210 if (slist != null) {
2211 for (SubscriptionInfo subInfoRecord : slist) {
2212 if (subInfoRecord.getSubscriptionId() == subId) {
2213 isValid = true;
2214 break;
2215 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002216 }
Wink Saville08874612014-08-31 19:19:58 -07002217 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002218 if (!isValid) {
2219 return;
2220 }
Wink Saville08874612014-08-31 19:19:58 -07002221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002222 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2223 intent.putExtra(SUBSCRIPTION_KEY, subId);
2224 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2225 mApp.startActivity(intent);
2226 } finally {
2227 Binder.restoreCallingIdentity(identity);
2228 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229 }
2230
Wink Savilleb564aae2014-10-23 10:18:09 -07002231 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002232 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002233 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2234 }
2235
Wink Savilleb564aae2014-10-23 10:18:09 -07002236 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002237 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002238 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2239 }
2240
Wink Savilleb564aae2014-10-23 10:18:09 -07002241 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002243
2244 final long identity = Binder.clearCallingIdentity();
2245 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002246 Phone phone = getPhone(subId);
2247 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002248 checkSimPin.start();
2249 return checkSimPin.unlockSim(null, pin);
2250 } finally {
2251 Binder.restoreCallingIdentity(identity);
2252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 }
2254
Wink Savilleb564aae2014-10-23 10:18:09 -07002255 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002257
2258 final long identity = Binder.clearCallingIdentity();
2259 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002260 Phone phone = getPhone(subId);
2261 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002262 checkSimPuk.start();
2263 return checkSimPuk.unlockSim(puk, pin);
2264 } finally {
2265 Binder.restoreCallingIdentity(identity);
2266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 }
2268
2269 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002270 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 * a synchronous one.
2272 */
2273 private static class UnlockSim extends Thread {
2274
2275 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002276 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277
2278 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002279 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2280 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281
2282 // For replies from SimCard interface
2283 private Handler mHandler;
2284
2285 // For async handler to identify request type
2286 private static final int SUPPLY_PIN_COMPLETE = 100;
2287
Michele Berionned9fbae52020-11-13 02:36:59 +00002288 UnlockSim(int phoneId, IccCard simCard) {
2289 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002290 mSimCard = simCard;
2291 }
2292
2293 @Override
2294 public void run() {
2295 Looper.prepare();
2296 synchronized (UnlockSim.this) {
2297 mHandler = new Handler() {
2298 @Override
2299 public void handleMessage(Message msg) {
2300 AsyncResult ar = (AsyncResult) msg.obj;
2301 switch (msg.what) {
2302 case SUPPLY_PIN_COMPLETE:
2303 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2304 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002305 mRetryCount = msg.arg1;
2306 if (ar.exception != null) {
2307 if (ar.exception instanceof CommandException &&
2308 ((CommandException)(ar.exception)).getCommandError()
2309 == CommandException.Error.PASSWORD_INCORRECT) {
2310 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002311 } //When UiccCardApp dispose,handle message and return exception
2312 else if (ar.exception instanceof CommandException &&
2313 ((CommandException) (ar.exception)).getCommandError()
2314 == CommandException.Error.ABORTED) {
2315 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002316 } else {
2317 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2318 }
2319 } else {
2320 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2321 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002322 mDone = true;
2323 UnlockSim.this.notifyAll();
2324 }
2325 break;
2326 }
2327 }
2328 };
2329 UnlockSim.this.notifyAll();
2330 }
2331 Looper.loop();
2332 }
2333
2334 /*
2335 * Use PIN or PUK to unlock SIM card
2336 *
2337 * If PUK is null, unlock SIM card with PIN
2338 *
2339 * If PUK is not null, unlock SIM card with PUK and set PIN code
2340 */
Wink Saville9de0f752013-10-22 19:04:03 -07002341 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342
2343 while (mHandler == null) {
2344 try {
2345 wait();
2346 } catch (InterruptedException e) {
2347 Thread.currentThread().interrupt();
2348 }
2349 }
2350 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2351
2352 if (puk == null) {
2353 mSimCard.supplyPin(pin, callback);
2354 } else {
2355 mSimCard.supplyPuk(puk, pin, callback);
2356 }
2357
2358 while (!mDone) {
2359 try {
2360 Log.d(LOG_TAG, "wait for done");
2361 wait();
2362 } catch (InterruptedException e) {
2363 // Restore the interrupted status
2364 Thread.currentThread().interrupt();
2365 }
2366 }
2367 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002368 int[] resultArray = new int[2];
2369 resultArray[0] = mResult;
2370 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002371
2372 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2373 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2374 }
2375
Wink Saville9de0f752013-10-22 19:04:03 -07002376 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 }
2378 }
2379
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002380 /**
2381 * This method has been removed due to privacy and stability concerns.
2382 */
2383 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002384 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002385 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2386 return;
Wink Saville36469e72014-06-11 15:17:00 -07002387 }
2388
Nathan Harold1f889d82020-06-04 17:05:26 -07002389 @Override
2390 public void updateServiceLocationWithPackageName(String callingPackage) {
2391 mApp.getSystemService(AppOpsManager.class)
2392 .checkPackage(Binder.getCallingUid(), callingPackage);
2393
Nathan Haroldf096d982020-11-18 17:18:06 -08002394 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002395 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2396 // Callers targeting S have no business invoking this method.
2397 return;
2398 }
2399
2400 LocationAccessPolicy.LocationPermissionResult locationResult =
2401 LocationAccessPolicy.checkLocationPermission(mApp,
2402 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2403 .setCallingPackage(callingPackage)
2404 .setCallingFeatureId(null)
2405 .setCallingPid(Binder.getCallingPid())
2406 .setCallingUid(Binder.getCallingUid())
2407 .setMethod("updateServiceLocation")
2408 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2409 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2410 .build());
2411 // Apps that lack location permission have no business calling this method;
2412 // however, because no permission was declared in the public API, denials must
2413 // all be "soft".
2414 switch (locationResult) {
2415 case DENIED_HARD: /* fall through */
2416 case DENIED_SOFT:
2417 return;
2418 }
2419
2420 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002421 final long identity = Binder.clearCallingIdentity();
2422 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002423 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002424 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002425 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002426 }
2427 } finally {
2428 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002429 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 }
2431
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002432 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002433 @Override
2434 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002435 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002436 }
2437
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002438
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002439 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002440 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2441 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2442 callingFeatureId);
2443 }
2444
2445 @Deprecated
2446 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002447 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002448 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2449 }
2450
2451 @Override
2452 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2453 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002454 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002455 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002456 return false;
2457 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002458
2459 final long identity = Binder.clearCallingIdentity();
2460 try {
2461 return isRadioOnForSubscriber(subId);
2462 } finally {
2463 Binder.restoreCallingIdentity(identity);
2464 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002465 }
2466
2467 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002468 final long identity = Binder.clearCallingIdentity();
2469 try {
2470 final Phone phone = getPhone(subId);
2471 if (phone != null) {
2472 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2473 } else {
2474 return false;
2475 }
2476 } finally {
2477 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002478 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 }
2480
2481 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002482 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 }
Wink Saville36469e72014-06-11 15:17:00 -07002484
Wink Savilleb564aae2014-10-23 10:18:09 -07002485 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002487
2488 final long identity = Binder.clearCallingIdentity();
2489 try {
2490 final Phone phone = getPhone(subId);
2491 if (phone != null) {
2492 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2493 }
2494 } finally {
2495 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002496 }
Wink Saville36469e72014-06-11 15:17:00 -07002497 }
2498
2499 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002500 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002501 }
2502
Wink Savilleb564aae2014-10-23 10:18:09 -07002503 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002504 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505
2506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 final Phone phone = getPhone(subId);
2509 if (phone == null) {
2510 return false;
2511 }
2512 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2513 toggleRadioOnOffForSubscriber(subId);
2514 }
2515 return true;
2516 } finally {
2517 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 }
Wink Saville36469e72014-06-11 15:17:00 -07002520
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002521 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002522 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002523 /*
2524 * If any of the Radios are available, it will need to be
2525 * shutdown. So return true if any Radio is available.
2526 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002527 final long identity = Binder.clearCallingIdentity();
2528 try {
2529 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2530 Phone phone = PhoneFactory.getPhone(i);
2531 if (phone != null && phone.isRadioAvailable()) return true;
2532 }
2533 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2534 return false;
2535 } finally {
2536 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002537 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002538 }
2539
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002540 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002541 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002542 enforceModifyPermission();
2543
2544 final long identity = Binder.clearCallingIdentity();
2545 try {
2546 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2547 logv("Shutting down Phone " + i);
2548 shutdownRadioUsingPhoneId(i);
2549 }
2550 } finally {
2551 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002552 }
2553 }
2554
2555 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002556 Phone phone = PhoneFactory.getPhone(phoneId);
2557 if (phone != null && phone.isRadioAvailable()) {
2558 phone.shutdownRadio();
2559 }
2560 }
2561
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002562 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002563 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564
2565 final long identity = Binder.clearCallingIdentity();
2566 try {
2567 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2568 if (defaultPhone != null) {
2569 defaultPhone.setRadioPower(turnOn);
2570 return true;
2571 } else {
2572 loge("There's no default phone.");
2573 return false;
2574 }
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002577 }
Wink Saville36469e72014-06-11 15:17:00 -07002578 }
2579
Wink Savilleb564aae2014-10-23 10:18:09 -07002580 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002582
2583 final long identity = Binder.clearCallingIdentity();
2584 try {
2585 final Phone phone = getPhone(subId);
2586 if (phone != null) {
2587 phone.setRadioPower(turnOn);
2588 return true;
2589 } else {
2590 return false;
2591 }
2592 } finally {
2593 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002594 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002595 }
2596
Wink Saville36469e72014-06-11 15:17:00 -07002597 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002598 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002599 public boolean enableDataConnectivity() {
2600 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601
2602 final long identity = Binder.clearCallingIdentity();
2603 try {
2604 int subId = mSubscriptionController.getDefaultDataSubId();
2605 final Phone phone = getPhone(subId);
2606 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002607 phone.getDataEnabledSettings().setDataEnabled(
2608 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609 return true;
2610 } else {
2611 return false;
2612 }
2613 } finally {
2614 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002615 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002616 }
2617
Wink Saville36469e72014-06-11 15:17:00 -07002618 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002619 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002620 public boolean disableDataConnectivity() {
2621 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622
2623 final long identity = Binder.clearCallingIdentity();
2624 try {
2625 int subId = mSubscriptionController.getDefaultDataSubId();
2626 final Phone phone = getPhone(subId);
2627 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002628 phone.getDataEnabledSettings().setDataEnabled(
2629 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002630 return true;
2631 } else {
2632 return false;
2633 }
2634 } finally {
2635 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002636 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002637 }
2638
Sanket Padawe356d7632015-06-22 14:03:32 -07002639 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002640 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641 final long identity = Binder.clearCallingIdentity();
2642 try {
2643 final Phone phone = getPhone(subId);
2644 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002645 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002646 } else {
2647 return false;
2648 }
2649 } finally {
2650 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002652 }
2653
2654 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002655 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002656 }
2657
pkanwarae03a6b2016-11-06 20:37:09 -08002658 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 enforceCallPermission();
2660
2661 final long identity = Binder.clearCallingIdentity();
2662 try {
2663 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2664 return;
2665 }
2666 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2667 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2668 } finally {
2669 Binder.restoreCallingIdentity(identity);
2670 }
pkanwar32d516d2016-10-14 19:37:38 -07002671 };
2672
Wink Savilleb564aae2014-10-23 10:18:09 -07002673 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002675
2676 final long identity = Binder.clearCallingIdentity();
2677 try {
2678 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2679 return false;
2680 }
2681 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2682 } finally {
2683 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002684 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002685 }
2686
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002687 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002688 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002689 }
2690
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002691 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002692 final long identity = Binder.clearCallingIdentity();
2693 try {
2694 Phone phone = PhoneFactory.getPhone(slotIndex);
2695 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2696 PhoneConstantConversions.convertCallState(phone.getState());
2697 } finally {
2698 Binder.restoreCallingIdentity(identity);
2699 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 }
2701
Sanket Padawe356d7632015-06-22 14:03:32 -07002702 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002703 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002704 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2705 }
2706
2707 @Override
2708 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002709 final long identity = Binder.clearCallingIdentity();
2710 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002711 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002712 if (phone != null) {
2713 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2714 } else {
2715 return PhoneConstantConversions.convertDataState(
2716 PhoneConstants.DataState.DISCONNECTED);
2717 }
2718 } finally {
2719 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002720 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002721 }
2722
Sanket Padawe356d7632015-06-22 14:03:32 -07002723 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002724 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002725 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2726 }
2727
2728 @Override
2729 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002730 final long identity = Binder.clearCallingIdentity();
2731 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002732 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002733 if (phone != null) {
2734 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2735 } else {
2736 return TelephonyManager.DATA_ACTIVITY_NONE;
2737 }
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002740 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741 }
2742
2743 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002744 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002745 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002746 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002747
2748 LocationAccessPolicy.LocationPermissionResult locationResult =
2749 LocationAccessPolicy.checkLocationPermission(mApp,
2750 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2751 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002752 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002753 .setCallingPid(Binder.getCallingPid())
2754 .setCallingUid(Binder.getCallingUid())
2755 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002756 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002757 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2758 .build());
2759 switch (locationResult) {
2760 case DENIED_HARD:
2761 throw new SecurityException("Not allowed to access cell location");
2762 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002763 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2764 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002765 }
2766
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002767 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002768 final long identity = Binder.clearCallingIdentity();
2769 try {
2770 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002771 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002772 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002773 } finally {
2774 Binder.restoreCallingIdentity(identity);
2775 }
Svetoslav64fad262015-04-14 14:35:21 -07002776 }
2777
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 @Override
Jack Yu01425032020-02-22 19:38:58 -08002779 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002780 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2781 // registered cell info, so return a NULL country instead.
2782 final long identity = Binder.clearCallingIdentity();
2783 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002784 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2785 // Get default phone in this case.
2786 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2787 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002788 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002789 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002790 if (phone == null) return "";
2791 ServiceStateTracker sst = phone.getServiceStateTracker();
2792 if (sst == null) return "";
2793 LocaleTracker lt = sst.getLocaleTracker();
2794 if (lt == null) return "";
2795 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2796 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2797 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002798 } finally {
2799 Binder.restoreCallingIdentity(identity);
2800 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002801 }
2802
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002803 /**
2804 * This method was removed due to potential issues caused by performing partial
2805 * updates of service state, and lack of a credible use case.
2806 *
2807 * This has the ability to break the telephony implementation by disabling notification of
2808 * changes in device connectivity. DO NOT USE THIS!
2809 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002810 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002811 public void enableLocationUpdates() {
2812 mApp.enforceCallingOrSelfPermission(
2813 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002814 }
2815
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002816 /**
2817 * This method was removed due to potential issues caused by performing partial
2818 * updates of service state, and lack of a credible use case.
2819 *
2820 * This has the ability to break the telephony implementation by disabling notification of
2821 * changes in device connectivity. DO NOT USE THIS!
2822 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002823 @Override
2824 public void disableLocationUpdates() {
2825 mApp.enforceCallingOrSelfPermission(
2826 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002827 }
2828
2829 @Override
2830 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002831 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2832 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002833 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002834 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2835 throw new SecurityException(
2836 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2837 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002838
Jordan Liu1617b712019-07-10 15:06:26 -07002839 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002840 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2841 return null;
2842 }
Svetoslav64fad262015-04-14 14:35:21 -07002843
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002844 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002845
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002846 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002847 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002848
Nathan Haroldf180aac2018-06-01 18:43:55 -07002849 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2850 for (CellInfo ci : info) {
2851 if (ci instanceof CellInfoGsm) {
2852 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2853 } else if (ci instanceof CellInfoWcdma) {
2854 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2855 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002856 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002857 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002858 }
2859
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002860 private List<CellInfo> getCachedCellInfo() {
2861 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2862 for (Phone phone : PhoneFactory.getPhones()) {
2863 List<CellInfo> info = phone.getAllCellInfo();
2864 if (info != null) cellInfos.addAll(info);
2865 }
2866 return cellInfos;
2867 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002868
2869 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002870 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002871 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002872 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002873
2874 LocationAccessPolicy.LocationPermissionResult locationResult =
2875 LocationAccessPolicy.checkLocationPermission(mApp,
2876 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2877 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002878 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002879 .setCallingPid(Binder.getCallingPid())
2880 .setCallingUid(Binder.getCallingUid())
2881 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002882 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002883 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2884 .build());
2885 switch (locationResult) {
2886 case DENIED_HARD:
2887 throw new SecurityException("Not allowed to access cell info");
2888 case DENIED_SOFT:
2889 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002890 }
2891
Nathan Haroldf096d982020-11-18 17:18:06 -08002892 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002893 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2894 return getCachedCellInfo();
2895 }
2896
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002897 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002898 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002899 final long identity = Binder.clearCallingIdentity();
2900 try {
2901 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2902 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002903 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002904 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 if (info != null) cellInfos.addAll(info);
2906 }
2907 return cellInfos;
2908 } finally {
2909 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002910 }
2911 }
2912
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002913 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002914 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2915 String callingFeatureId) {
2916 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2917 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002918 }
2919
2920 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002921 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2922 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002923 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002924 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002925 }
2926
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002927 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2928 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002929 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002930 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002931
2932 LocationAccessPolicy.LocationPermissionResult locationResult =
2933 LocationAccessPolicy.checkLocationPermission(mApp,
2934 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2935 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002936 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002937 .setCallingPid(Binder.getCallingPid())
2938 .setCallingUid(Binder.getCallingUid())
2939 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002940 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2941 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002942 .build());
2943 switch (locationResult) {
2944 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002945 if (TelephonyPermissions
2946 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002947 // Safetynet logging for b/154934934
2948 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2949 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002950 throw new SecurityException("Not allowed to access cell info");
2951 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002952 if (TelephonyPermissions
2953 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002954 // Safetynet logging for b/154934934
2955 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2956 }
Nathan Harold5320c422019-05-09 10:26:08 -07002957 try {
2958 cb.onCellInfo(new ArrayList<CellInfo>());
2959 } catch (RemoteException re) {
2960 // Drop without consequences
2961 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002962 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002963 }
2964
Nathan Harolda939a962019-05-09 10:13:47 -07002965
2966 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002967 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2968
2969 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2970 }
2971
2972 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002973 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002974 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002975 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002976
2977 final long identity = Binder.clearCallingIdentity();
2978 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002979 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980 } finally {
2981 Binder.restoreCallingIdentity(identity);
2982 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002983 }
2984
Shishir Agrawala9f32182016-04-12 12:00:16 -07002985 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002986 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002987 Phone phone = PhoneFactory.getPhone(slotIndex);
2988 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002989 return null;
2990 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002991 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002992 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002993 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002994 return null;
2995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002996
2997 final long identity = Binder.clearCallingIdentity();
2998 try {
2999 return phone.getImei();
3000 } finally {
3001 Binder.restoreCallingIdentity(identity);
3002 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003003 }
3004
3005 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003006 public String getTypeAllocationCodeForSlot(int slotIndex) {
3007 Phone phone = PhoneFactory.getPhone(slotIndex);
3008 String tac = null;
3009 if (phone != null) {
3010 String imei = phone.getImei();
3011 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3012 }
3013 return tac;
3014 }
3015
3016 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003017 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003018 Phone phone = PhoneFactory.getPhone(slotIndex);
3019 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003020 return null;
3021 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003022
Jeff Davidson913390f2018-02-23 17:11:49 -08003023 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003024 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003025 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003026 return null;
3027 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003028
3029 final long identity = Binder.clearCallingIdentity();
3030 try {
3031 return phone.getMeid();
3032 } finally {
3033 Binder.restoreCallingIdentity(identity);
3034 }
Jack Yu2af8d712017-03-15 17:14:14 -07003035 }
3036
3037 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003038 public String getManufacturerCodeForSlot(int slotIndex) {
3039 Phone phone = PhoneFactory.getPhone(slotIndex);
3040 String manufacturerCode = null;
3041 if (phone != null) {
3042 String meid = phone.getMeid();
3043 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3044 }
3045 return manufacturerCode;
3046 }
3047
3048 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003049 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3050 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003051 Phone phone = PhoneFactory.getPhone(slotIndex);
3052 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003053 return null;
3054 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003055 int subId = phone.getSubId();
3056 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003057 mApp, subId, callingPackage, callingFeatureId,
3058 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003059 return null;
3060 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003061
3062 final long identity = Binder.clearCallingIdentity();
3063 try {
3064 return phone.getDeviceSvn();
3065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003068 }
3069
fionaxu43304da2017-11-27 22:51:16 -08003070 @Override
3071 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003072 final long identity = Binder.clearCallingIdentity();
3073 try {
3074 final Phone phone = getPhone(subId);
3075 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3076 } finally {
3077 Binder.restoreCallingIdentity(identity);
3078 }
fionaxu43304da2017-11-27 22:51:16 -08003079 }
3080
3081 @Override
3082 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003083 final long identity = Binder.clearCallingIdentity();
3084 try {
3085 final Phone phone = getPhone(subId);
3086 return phone == null ? null : phone.getCarrierName();
3087 } finally {
3088 Binder.restoreCallingIdentity(identity);
3089 }
fionaxu43304da2017-11-27 22:51:16 -08003090 }
3091
calvinpanffe225e2018-11-01 19:43:06 +08003092 @Override
chen xu0026ca62019-03-06 15:28:50 -08003093 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003094 final long identity = Binder.clearCallingIdentity();
3095 try {
3096 final Phone phone = getPhone(subId);
3097 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003098 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003099 } finally {
3100 Binder.restoreCallingIdentity(identity);
3101 }
3102 }
3103
3104 @Override
chen xu0026ca62019-03-06 15:28:50 -08003105 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003106 final long identity = Binder.clearCallingIdentity();
3107 try {
3108 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003109 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003110 } finally {
3111 Binder.restoreCallingIdentity(identity);
3112 }
3113 }
3114
chen xu651eec72018-11-11 19:03:44 -08003115 @Override
chen xu864e11c2018-12-06 22:10:03 -08003116 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3117 if (!isSubscriptionMccMnc) {
3118 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3119 }
chen xu651eec72018-11-11 19:03:44 -08003120 final Phone phone = PhoneFactory.getPhone(slotIndex);
3121 if (phone == null) {
3122 return TelephonyManager.UNKNOWN_CARRIER_ID;
3123 }
3124 final long identity = Binder.clearCallingIdentity();
3125 try {
3126 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3127 } finally {
3128 Binder.restoreCallingIdentity(identity);
3129 }
3130 }
3131
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003132 //
3133 // Internal helper methods.
3134 //
3135
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003136 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003137 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3138 *
3139 * @throws SecurityException if the caller does not have the required permission
3140 */
3141 private void enforceModifyPermission() {
3142 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3143 }
3144
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003145 /**
3146 * Make sure the caller is system.
3147 *
3148 * @throws SecurityException if the caller is not system.
3149 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003150 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003151 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3152 throw new SecurityException("Caller must be system");
3153 }
3154 }
3155
Shuo Qianf2b2df42019-11-13 17:43:31 -08003156 private void enforceActiveEmergencySessionPermission() {
3157 mApp.enforceCallingOrSelfPermission(
3158 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3159 }
3160
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003161 /**
3162 * Make sure the caller has the CALL_PHONE permission.
3163 *
3164 * @throws SecurityException if the caller does not have the required permission
3165 */
3166 private void enforceCallPermission() {
3167 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3168 }
3169
paulhu423b5f22019-08-23 19:17:33 +08003170 private void enforceSettingsPermission() {
3171 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003172 }
3173
Michele Berionned9fbae52020-11-13 02:36:59 +00003174 private void enforceRebootPermission() {
3175 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3176 }
3177
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003178 private String createTelUrl(String number) {
3179 if (TextUtils.isEmpty(number)) {
3180 return null;
3181 }
3182
Jake Hambye994d462014-02-03 13:10:13 -08003183 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003184 }
3185
Ihab Awadf9e92732013-12-05 18:02:52 -08003186 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003187 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3188 }
3189
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003190 private static void logv(String msg) {
3191 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3192 }
3193
Ihab Awadf9e92732013-12-05 18:02:52 -08003194 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003195 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3196 }
3197
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003198 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003199 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003200 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003201 }
3202
Sanket Padawe356d7632015-06-22 14:03:32 -07003203 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003204 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205 final long identity = Binder.clearCallingIdentity();
3206 try {
3207 final Phone phone = PhoneFactory.getPhone(slotIndex);
3208 if (phone == null) {
3209 return PhoneConstants.PHONE_TYPE_NONE;
3210 } else {
3211 return phone.getPhoneType();
3212 }
3213 } finally {
3214 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003216 }
3217
3218 /**
3219 * Returns the CDMA ERI icon index to display
3220 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003221 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003222 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3223 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3224 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003225 }
3226
Sanket Padawe356d7632015-06-22 14:03:32 -07003227 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003228 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3229 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003230 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003231 mApp, subId, callingPackage, callingFeatureId,
3232 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003233 return -1;
3234 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003235
3236 final long identity = Binder.clearCallingIdentity();
3237 try {
3238 final Phone phone = getPhone(subId);
3239 if (phone != null) {
3240 return phone.getCdmaEriIconIndex();
3241 } else {
3242 return -1;
3243 }
3244 } finally {
3245 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003246 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003247 }
3248
3249 /**
3250 * Returns the CDMA ERI icon mode,
3251 * 0 - ON
3252 * 1 - FLASHING
3253 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003254 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003255 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3256 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3257 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003258 }
3259
Sanket Padawe356d7632015-06-22 14:03:32 -07003260 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003261 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3262 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003263 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003264 mApp, subId, callingPackage, callingFeatureId,
3265 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003266 return -1;
3267 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003268
3269 final long identity = Binder.clearCallingIdentity();
3270 try {
3271 final Phone phone = getPhone(subId);
3272 if (phone != null) {
3273 return phone.getCdmaEriIconMode();
3274 } else {
3275 return -1;
3276 }
3277 } finally {
3278 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003280 }
3281
3282 /**
3283 * Returns the CDMA ERI text,
3284 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003285 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003286 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3287 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3288 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003289 }
3290
Sanket Padawe356d7632015-06-22 14:03:32 -07003291 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003292 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3293 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003294 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003295 mApp, subId, callingPackage, callingFeatureId,
3296 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003297 return null;
3298 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003299
3300 final long identity = Binder.clearCallingIdentity();
3301 try {
3302 final Phone phone = getPhone(subId);
3303 if (phone != null) {
3304 return phone.getCdmaEriText();
3305 } else {
3306 return null;
3307 }
3308 } finally {
3309 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003310 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003311 }
3312
3313 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003314 * Returns the CDMA MDN.
3315 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003316 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003317 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3319 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003320
3321 final long identity = Binder.clearCallingIdentity();
3322 try {
3323 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003324 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003325 return phone.getLine1Number();
3326 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003327 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003328 return null;
3329 }
3330 } finally {
3331 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003332 }
3333 }
3334
3335 /**
3336 * Returns the CDMA MIN.
3337 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003338 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003339 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3341 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003342
3343 final long identity = Binder.clearCallingIdentity();
3344 try {
3345 final Phone phone = getPhone(subId);
3346 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3347 return phone.getCdmaMin();
3348 } else {
3349 return null;
3350 }
3351 } finally {
3352 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003353 }
3354 }
3355
Hall Liud892bec2018-11-30 14:51:45 -08003356 @Override
3357 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3358 INumberVerificationCallback callback, String callingPackage) {
3359 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3360 != PERMISSION_GRANTED) {
3361 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3362 }
3363 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3364
3365 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3366 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003367 throw new SecurityException("Calling package must be configured in the device config: "
3368 + "calling package: " + callingPackage
3369 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003370 }
3371
3372 if (range == null) {
3373 throw new NullPointerException("Range must be non-null");
3374 }
3375
3376 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003377 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003378
3379 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3380 }
3381
Junda Liuca05d5d2014-08-14 22:36:34 -07003382 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003383 * Returns true if CDMA provisioning needs to run.
3384 */
3385 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003386 final long identity = Binder.clearCallingIdentity();
3387 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003388 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003389 } finally {
3390 Binder.restoreCallingIdentity(identity);
3391 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003392 }
3393
3394 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003395 * Sets the voice mail number of a given subId.
3396 */
3397 @Override
3398 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003399 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3400 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003401
3402 final long identity = Binder.clearCallingIdentity();
3403 try {
3404 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3405 new Pair<String, String>(alphaTag, number), new Integer(subId));
3406 return success;
3407 } finally {
3408 Binder.restoreCallingIdentity(identity);
3409 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003410 }
3411
Ta-wei Yen87c49842016-05-13 21:19:52 -07003412 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003413 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3414 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003415 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3416 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003417 if (!TextUtils.equals(callingPackage, systemDialer)) {
3418 throw new SecurityException("caller must be system dialer");
3419 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003420
3421 final long identity = Binder.clearCallingIdentity();
3422 try {
3423 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3424 if (phoneAccountHandle == null) {
3425 return null;
3426 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003427 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003428 } finally {
3429 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003430 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003431 }
3432
3433 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003434 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3435 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003436 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003437 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003438 mApp, subId, callingPackage, callingFeatureId,
3439 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003440 return null;
3441 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003442
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003443 final long identity = Binder.clearCallingIdentity();
3444 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003445 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003446 } finally {
3447 Binder.restoreCallingIdentity(identity);
3448 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003449 }
3450
3451 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003452 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3453 VisualVoicemailSmsFilterSettings settings) {
3454 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003455
3456 final long identity = Binder.clearCallingIdentity();
3457 try {
3458 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003459 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003460 } finally {
3461 Binder.restoreCallingIdentity(identity);
3462 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003463 }
3464
3465 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003466 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3467 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003468
3469 final long identity = Binder.clearCallingIdentity();
3470 try {
3471 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003472 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003473 } finally {
3474 Binder.restoreCallingIdentity(identity);
3475 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003476 }
3477
3478 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003479 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3480 String callingPackage, int subId) {
3481 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003482
3483 final long identity = Binder.clearCallingIdentity();
3484 try {
3485 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003486 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003487 } finally {
3488 Binder.restoreCallingIdentity(identity);
3489 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003490 }
3491
3492 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003493 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003494 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003495
3496 final long identity = Binder.clearCallingIdentity();
3497 try {
3498 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003499 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003500 } finally {
3501 Binder.restoreCallingIdentity(identity);
3502 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003503 }
3504
3505 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003506 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3507 String callingAttributionTag, int subId, String number, int port, String text,
3508 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003509 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003510 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003511 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003512 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003513 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3514 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003515 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003516
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003517 /**
fionaxu0152e512016-11-14 13:36:14 -08003518 * Sets the voice activation state of a given subId.
3519 */
3520 @Override
3521 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003522 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3523 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003524
3525 final long identity = Binder.clearCallingIdentity();
3526 try {
3527 final Phone phone = getPhone(subId);
3528 if (phone != null) {
3529 phone.setVoiceActivationState(activationState);
3530 } else {
3531 loge("setVoiceActivationState fails with invalid subId: " + subId);
3532 }
3533 } finally {
3534 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003535 }
3536 }
3537
3538 /**
3539 * Sets the data activation state of a given subId.
3540 */
3541 @Override
3542 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003543 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3544 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003545
3546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 final Phone phone = getPhone(subId);
3549 if (phone != null) {
3550 phone.setDataActivationState(activationState);
3551 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003552 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003553 }
3554 } finally {
3555 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003556 }
3557 }
3558
3559 /**
3560 * Returns the voice activation state of a given subId.
3561 */
3562 @Override
3563 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003564 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565
fionaxu0152e512016-11-14 13:36:14 -08003566 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003567 final long identity = Binder.clearCallingIdentity();
3568 try {
3569 if (phone != null) {
3570 return phone.getVoiceActivationState();
3571 } else {
3572 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3573 }
3574 } finally {
3575 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003576 }
3577 }
3578
3579 /**
3580 * Returns the data activation state of a given subId.
3581 */
3582 @Override
3583 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003584 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003585
fionaxu0152e512016-11-14 13:36:14 -08003586 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003587 final long identity = Binder.clearCallingIdentity();
3588 try {
3589 if (phone != null) {
3590 return phone.getDataActivationState();
3591 } else {
3592 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3593 }
3594 } finally {
3595 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003596 }
3597 }
3598
3599 /**
Wink Saville36469e72014-06-11 15:17:00 -07003600 * Returns the unread count of voicemails for a subId
3601 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003602 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003603 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3604 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003605 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003606 mApp, subId, callingPackage, callingFeatureId,
3607 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003608 return 0;
3609 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003610 final long identity = Binder.clearCallingIdentity();
3611 try {
3612 final Phone phone = getPhone(subId);
3613 if (phone != null) {
3614 return phone.getVoiceMessageCount();
3615 } else {
3616 return 0;
3617 }
3618 } finally {
3619 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003621 }
3622
3623 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003624 * returns true, if the device is in a state where both voice and data
3625 * are supported simultaneously. This can change based on location or network condition.
3626 */
3627 @Override
3628 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003629 final long identity = Binder.clearCallingIdentity();
3630 try {
3631 final Phone phone = getPhone(subId);
3632 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3633 } finally {
3634 Binder.restoreCallingIdentity(identity);
3635 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003636 }
3637
3638 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003639 * Send the dialer code if called from the current default dialer or the caller has
3640 * carrier privilege.
3641 * @param inputCode The dialer code to send
3642 */
3643 @Override
3644 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003645 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003646 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003647 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3648 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003649 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003650 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003651 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003652 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653
3654 final long identity = Binder.clearCallingIdentity();
3655 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003656 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657 } finally {
3658 Binder.restoreCallingIdentity(identity);
3659 }
fionaxu235cc5e2017-03-06 22:25:57 -08003660 }
3661
Pengquan Menga1bb6272018-09-06 09:59:22 -07003662 @Override
3663 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003664 TelephonyPermissions
3665 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3666 mApp, subId, "getNetworkSelectionMode");
3667 final long identity = Binder.clearCallingIdentity();
3668 try {
3669 if (!isActiveSubscription(subId)) {
3670 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3671 }
3672 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3673 } finally {
3674 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003675 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003676 }
3677
Brad Ebinger35c841c2018-10-01 10:40:55 -07003678 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003679 public boolean isInEmergencySmsMode() {
3680 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3681 final long identity = Binder.clearCallingIdentity();
3682 try {
3683 for (Phone phone : PhoneFactory.getPhones()) {
3684 if (phone.isInEmergencySmsMode()) {
3685 return true;
3686 }
3687 }
3688 } finally {
3689 Binder.restoreCallingIdentity(identity);
3690 }
3691 return false;
3692 }
3693
shilu366312e2019-12-17 09:28:10 -08003694 /**
3695 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3696 * @param subId The subscription to use to check the configuration.
3697 * @param c The callback that will be used to send the result.
3698 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003699 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003700 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3701 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003702 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3703 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003704
Brad Ebinger77b832e2019-10-17 17:03:22 -07003705 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3706 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3707 "IMS not available on device.");
3708 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003709 final long token = Binder.clearCallingIdentity();
3710 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003711 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003712 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003713 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003714 } catch (ImsException e) {
3715 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003716 } finally {
3717 Binder.restoreCallingIdentity(token);
3718 }
3719 }
3720
shilu366312e2019-12-17 09:28:10 -08003721 /**
3722 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3723 * @param subId The subscription to use to check the configuration.
3724 * @param c The callback that will be used to send the result.
3725 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003726 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003727 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003728 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3729 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003730 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3731 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3732 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003733 final long token = Binder.clearCallingIdentity();
3734 try {
3735 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3736 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3737 .removeRegistrationCallbackForSubscription(c, subId);
3738 } catch (ImsException e) {
3739 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3740 + "is inactive, ignoring unregister.");
3741 // If the subscription is no longer active, just return, since the callback
3742 // will already have been removed internally.
3743 } finally {
3744 Binder.restoreCallingIdentity(token);
3745 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003746 }
3747
Brad Ebinger774ba362019-10-22 17:36:18 -07003748 /**
3749 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3750 */
3751 @Override
3752 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3753 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3754 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3755 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3756 "IMS not available on device.");
3757 }
3758 final long token = Binder.clearCallingIdentity();
3759 try {
3760 Phone phone = getPhone(subId);
3761 if (phone == null) {
3762 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3763 + subId + "'");
3764 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3765 }
3766 phone.getImsRegistrationState(regState -> {
3767 try {
3768 consumer.accept((regState == null)
3769 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3770 } catch (RemoteException e) {
3771 // Ignore if the remote process is no longer available to call back.
3772 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3773 }
3774 });
3775 } finally {
3776 Binder.restoreCallingIdentity(token);
3777 }
3778 }
3779
3780 /**
3781 * Get the transport type for the IMS service registration state.
3782 */
3783 @Override
3784 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003785 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3786 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003787 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3788 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3789 "IMS not available on device.");
3790 }
3791 final long token = Binder.clearCallingIdentity();
3792 try {
3793 Phone phone = getPhone(subId);
3794 if (phone == null) {
3795 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3796 + subId + "'");
3797 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3798 }
3799 phone.getImsRegistrationTech(regTech -> {
3800 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3801 int regTechConverted = (regTech == null)
3802 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3803 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3804 regTechConverted);
3805 try {
3806 consumer.accept(regTechConverted);
3807 } catch (RemoteException e) {
3808 // Ignore if the remote process is no longer available to call back.
3809 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3810 }
3811 });
3812 } finally {
3813 Binder.restoreCallingIdentity(token);
3814 }
3815 }
3816
shilu366312e2019-12-17 09:28:10 -08003817 /**
3818 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3819 * @param subId The subscription to use to check the configuration.
3820 * @param c The callback that will be used to send the result.
3821 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003822 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003823 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3824 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003825 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3826 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003827 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3828 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3829 "IMS not available on device.");
3830 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003831 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3832 final long token = Binder.clearCallingIdentity();
3833 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003834 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003835 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003836 } catch (ImsException e) {
3837 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003838 } finally {
3839 Binder.restoreCallingIdentity(token);
3840 }
3841 }
3842
shilu366312e2019-12-17 09:28:10 -08003843 /**
3844 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3845 * @param subId The subscription to use to check the configuration.
3846 * @param c The callback that will be used to send the result.
3847 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003848 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003849 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003850 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3851 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003852 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3853 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3854 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003855
3856 final long token = Binder.clearCallingIdentity();
3857 try {
3858 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3859 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003860 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003861 } catch (ImsException e) {
3862 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3863 + "is inactive, ignoring unregister.");
3864 // If the subscription is no longer active, just return, since the callback
3865 // will already have been removed internally.
3866 } finally {
3867 Binder.restoreCallingIdentity(token);
3868 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003869 }
3870
3871 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003872 public boolean isCapable(int subId, int capability, int regTech) {
3873 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003874 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3875 final long token = Binder.clearCallingIdentity();
3876 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003877 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003878 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003879 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003880 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3881 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003882 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003883 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3884 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003885 } finally {
3886 Binder.restoreCallingIdentity(token);
3887 }
3888 }
3889
3890 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003891 public boolean isAvailable(int subId, int capability, int regTech) {
3892 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003893 final long token = Binder.clearCallingIdentity();
3894 try {
3895 Phone phone = getPhone(subId);
3896 if (phone == null) return false;
3897 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003898 } catch (com.android.ims.ImsException e) {
3899 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3900 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003901 } finally {
3902 Binder.restoreCallingIdentity(token);
3903 }
3904 }
3905
Brad Ebinger77b832e2019-10-17 17:03:22 -07003906 /**
3907 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3908 * subscription.
3909 * @param subId The subscription to use to check the configuration.
3910 * @param callback The callback that will be used to send the result.
3911 * @param capability The MmTelFeature capability that will be used to send the result.
3912 * @param transportType The transport type of the MmTelFeature capability.
3913 */
3914 @Override
3915 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3916 int transportType) {
3917 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3918 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3919 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3920 "IMS not available on device.");
3921 }
3922 final long token = Binder.clearCallingIdentity();
3923 try {
3924 int slotId = getSlotIndex(subId);
3925 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3926 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3927 + subId + "'");
3928 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3929 }
3930 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3931 transportType, aBoolean -> {
3932 try {
3933 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3934 } catch (RemoteException e) {
3935 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3936 + "running. Ignore");
3937 }
3938 });
3939 } finally {
3940 Binder.restoreCallingIdentity(token);
3941 }
3942 }
3943
shilu366312e2019-12-17 09:28:10 -08003944 /**
3945 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3946 * @param subId The subscription to use to check the configuration.
3947 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003948 @Override
3949 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003950 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3951 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003952
Brad Ebinger35c841c2018-10-01 10:40:55 -07003953 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3954 final long token = Binder.clearCallingIdentity();
3955 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003956 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003957 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003958 } catch (ImsException e) {
3959 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003960 } finally {
3961 Binder.restoreCallingIdentity(token);
3962 }
3963 }
3964
3965 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003966 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003968 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003969 final long identity = Binder.clearCallingIdentity();
3970 try {
3971 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003972 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003973 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003974 } catch (ImsException e) {
3975 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003976 } finally {
3977 Binder.restoreCallingIdentity(identity);
3978 }
3979 }
3980
shilu366312e2019-12-17 09:28:10 -08003981 /**
3982 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3983 * @param subId The subscription to use to check the configuration.
3984 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003985 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003986 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003987 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3988 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003989 final long identity = Binder.clearCallingIdentity();
3990 try {
3991 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003992 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3993 } catch (ImsException e) {
3994 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003995 } finally {
3996 Binder.restoreCallingIdentity(identity);
3997 }
3998 }
3999
4000 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004001 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004003 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004004 final long identity = Binder.clearCallingIdentity();
4005 try {
4006 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004007 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004008 } catch (ImsException e) {
4009 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004010 } finally {
4011 Binder.restoreCallingIdentity(identity);
4012 }
4013 }
4014
shilu366312e2019-12-17 09:28:10 -08004015 /**
4016 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4017 * @param subId The subscription to use to check the configuration.
4018 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004019 @Override
4020 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004021 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4022 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004023 final long identity = Binder.clearCallingIdentity();
4024 try {
4025 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004026 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004027 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004028 } catch (ImsException e) {
4029 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004030 } finally {
4031 Binder.restoreCallingIdentity(identity);
4032 }
4033 }
4034
4035 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004036 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004038 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 final long identity = Binder.clearCallingIdentity();
4040 try {
4041 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004042 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004043 } catch (ImsException e) {
4044 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004045 } finally {
4046 Binder.restoreCallingIdentity(identity);
4047 }
4048 }
4049
shilu366312e2019-12-17 09:28:10 -08004050 /**
4051 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4052 * @param subId The subscription to use to check the configuration.
4053 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004054 @Override
4055 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004056 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4057 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004058 final long identity = Binder.clearCallingIdentity();
4059 try {
4060 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004061 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004062 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004063 } catch (ImsException e) {
4064 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004065 } finally {
4066 Binder.restoreCallingIdentity(identity);
4067 }
4068 }
4069
4070 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004071 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004073 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 final long identity = Binder.clearCallingIdentity();
4075 try {
4076 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004077 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004078 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004079 } catch (ImsException e) {
4080 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004081 } finally {
4082 Binder.restoreCallingIdentity(identity);
4083 }
4084 }
4085
4086 @Override
4087 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4088 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4089 "setVoWiFiNonPersistent");
4090 final long identity = Binder.clearCallingIdentity();
4091 try {
4092 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004093 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004094 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004095 } catch (ImsException e) {
4096 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004097 } finally {
4098 Binder.restoreCallingIdentity(identity);
4099 }
4100 }
4101
shilu366312e2019-12-17 09:28:10 -08004102 /**
4103 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4104 * @param subId The subscription to use to check the configuration.
4105 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004106 @Override
4107 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004108 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4109 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004110 final long identity = Binder.clearCallingIdentity();
4111 try {
4112 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004113 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004114 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004115 } catch (ImsException e) {
4116 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004117 } finally {
4118 Binder.restoreCallingIdentity(identity);
4119 }
4120 }
4121
4122 @Override
4123 public void setVoWiFiModeSetting(int subId, int mode) {
4124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4125 "setVoWiFiModeSetting");
4126 final long identity = Binder.clearCallingIdentity();
4127 try {
4128 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004129 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004130 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004131 } catch (ImsException e) {
4132 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004133 } finally {
4134 Binder.restoreCallingIdentity(identity);
4135 }
4136 }
4137
4138 @Override
4139 public int getVoWiFiRoamingModeSetting(int subId) {
4140 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4141 final long identity = Binder.clearCallingIdentity();
4142 try {
4143 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004144 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004145 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004146 } catch (ImsException e) {
4147 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004148 } finally {
4149 Binder.restoreCallingIdentity(identity);
4150 }
4151 }
4152
4153 @Override
4154 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4156 "setVoWiFiRoamingModeSetting");
4157 final long identity = Binder.clearCallingIdentity();
4158 try {
4159 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004160 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004161 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004162 } catch (ImsException e) {
4163 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004164 } finally {
4165 Binder.restoreCallingIdentity(identity);
4166 }
4167 }
4168
4169 @Override
4170 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4172 "setRttCapabilityEnabled");
4173 final long identity = Binder.clearCallingIdentity();
4174 try {
4175 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004176 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4177 } catch (ImsException e) {
4178 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004179 } finally {
4180 Binder.restoreCallingIdentity(identity);
4181 }
4182 }
4183
shilu366312e2019-12-17 09:28:10 -08004184 /**
4185 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4186 * @param subId The subscription to use to check the configuration.
4187 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004188 @Override
4189 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004190 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4191 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004192 final long identity = Binder.clearCallingIdentity();
4193 try {
4194 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004195 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004196 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004197 } catch (ImsException e) {
4198 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004199 } finally {
4200 Binder.restoreCallingIdentity(identity);
4201 }
4202 }
4203
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004204 @Override
4205 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4206 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4207 final long identity = Binder.clearCallingIdentity();
4208 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004209 if (!isImsAvailableOnDevice()) {
4210 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4211 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004212 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004213 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004214 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004215 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004216 } catch (ImsException e) {
4217 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004218 } finally {
4219 Binder.restoreCallingIdentity(identity);
4220 }
4221 }
4222
4223 @Override
4224 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4225 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4226 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004227 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4228 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4229 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004230 try {
4231 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004232 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004233 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004234 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004235 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4236 + "is inactive, ignoring unregister.");
4237 // If the subscription is no longer active, just return, since the callback will already
4238 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004239 } finally {
4240 Binder.restoreCallingIdentity(identity);
4241 }
4242 }
4243
allenwtsu99c623b2020-01-03 18:24:23 +08004244
4245 private void checkModifyPhoneStatePermission(int subId, String message) {
4246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4247 message);
4248 }
4249
4250 private boolean isImsProvisioningRequired(int subId, int capability,
4251 boolean isMmtelCapability) {
4252 Phone phone = getPhone(subId);
4253 if (phone == null) {
4254 loge("phone instance null for subid " + subId);
4255 return false;
4256 }
4257 if (isMmtelCapability) {
4258 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4259 return false;
4260 }
4261 } else {
4262 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4263 return false;
4264 }
4265 }
4266 return true;
4267 }
4268
4269 @Override
4270 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4271 boolean isProvisioned) {
4272 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4273
4274 final long identity = Binder.clearCallingIdentity();
4275 try {
4276 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4277 if (!isImsProvisioningRequired(subId, capability, false)) {
4278 return;
4279 }
4280
4281 // this capability requires provisioning, route to the correct API.
4282 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4283 switch (capability) {
4284 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4285 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4286 ims.setEabProvisioned(isProvisioned);
4287 break;
4288 default: {
4289 throw new IllegalArgumentException("Tried to set provisioning for "
4290 + "rcs capability '" + capability + "', which does not require "
4291 + "provisioning.");
4292 }
4293 }
4294 } finally {
4295 Binder.restoreCallingIdentity(identity);
4296 }
4297
4298 }
4299
4300
4301 @Override
4302 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4303 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4304 final long identity = Binder.clearCallingIdentity();
4305 try {
4306 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4307 if (!isImsProvisioningRequired(subId, capability, false)) {
4308 return true;
4309 }
4310
4311 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4312 switch (capability) {
4313 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4314 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4315 return ims.isEabProvisionedOnDevice();
4316
4317 default: {
4318 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4319 + "capability '" + capability + "', which does not require "
4320 + "provisioning.");
4321 }
4322 }
4323
4324 } finally {
4325 Binder.restoreCallingIdentity(identity);
4326 }
4327 }
4328
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004329 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004330 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4331 boolean isProvisioned) {
4332 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4333 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4334 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4335 }
allenwtsu99c623b2020-01-03 18:24:23 +08004336 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004337 final long identity = Binder.clearCallingIdentity();
4338 try {
4339 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004340 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004341 return;
4342 }
4343
4344 // this capability requires provisioning, route to the correct API.
4345 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4346 switch (capability) {
4347 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4348 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4349 ims.setVolteProvisioned(isProvisioned);
4350 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4351 ims.setWfcProvisioned(isProvisioned);
4352 }
4353 break;
4354 }
4355 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4356 // There is currently no difference in VT provisioning type.
4357 ims.setVtProvisioned(isProvisioned);
4358 break;
4359 }
4360 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4361 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4362 // change the capability of the feature instead if needed.
4363 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4364 == isProvisioned) {
4365 // No change in provisioning.
4366 return;
4367 }
4368 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4369 try {
4370 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004371 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004372 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4373 + ", Exception" + e.getMessage());
4374 }
4375 break;
4376 }
4377 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004378 throw new IllegalArgumentException("Tried to set provisioning for "
4379 + "MmTel capability '" + capability + "', which does not require "
4380 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004381 }
4382 }
4383
4384 } finally {
4385 Binder.restoreCallingIdentity(identity);
4386 }
4387 }
4388
4389 @Override
4390 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4391 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4392 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4393 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4394 }
4395 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4396 final long identity = Binder.clearCallingIdentity();
4397 try {
4398 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004399 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004400 return true;
4401 }
4402
4403 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4404 switch (capability) {
4405 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4406 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4407 return ims.isVolteProvisionedOnDevice();
4408 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4409 return ims.isWfcProvisionedOnDevice();
4410 }
4411 // This should never happen, since we are checking tech above to make sure it
4412 // is either LTE or IWLAN.
4413 throw new IllegalArgumentException("Invalid radio technology for voice "
4414 + "capability.");
4415 }
4416 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4417 // There is currently no difference in VT provisioning type.
4418 return ims.isVtProvisionedOnDevice();
4419 }
4420 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4421 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4422 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4423 }
4424 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004425 throw new IllegalArgumentException(
4426 "Tried to get provisioning for MmTel capability '" + capability
4427 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004428 }
4429 }
4430
4431 } finally {
4432 Binder.restoreCallingIdentity(identity);
4433 }
4434 }
4435
4436 @Override
4437 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4438 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4439 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4440 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4441 }
4442 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4443 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4444 return (provisionedBits & capability) > 0;
4445 }
4446
4447 @Override
4448 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4449 boolean isProvisioned) {
4450 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4451 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4452 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4453 }
4454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4455 "setProvisioningStatusForCapability");
4456 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4457 // If the current provisioning status for capability already matches isProvisioned,
4458 // do nothing.
4459 if (((provisionedBits & capability) > 0) == isProvisioned) {
4460 return;
4461 }
4462 if (isProvisioned) {
4463 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4464 } else {
4465 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4466 }
4467 }
4468
4469 /**
4470 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4471 * technology. The bitfield should mirror the bitfield defined by
4472 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4473 */
4474 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4475 String key = getMmTelProvisioningKey(subId, tech);
4476 // Default is no capabilities are provisioned.
4477 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4478 }
4479
4480 /**
4481 * Sets the MmTel capability provisioning bitfield (defined by
4482 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4483 * technology specified.
4484 *
4485 * Note: This is a synchronous command and should not be called on UI thread.
4486 */
4487 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4488 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4489 String key = getMmTelProvisioningKey(subId, tech);
4490 editor.putInt(key, newField);
4491 editor.commit();
4492 }
4493
4494 private static String getMmTelProvisioningKey(int subId, int tech) {
4495 // resulting key is provision_ims_mmtel_{subId}_{tech}
4496 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4497 }
4498
4499 /**
4500 * Query CarrierConfig to see if the specified capability requires provisioning for the
4501 * carrier associated with the subscription id.
4502 */
4503 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4504 int capability) {
4505 CarrierConfigManager configManager = new CarrierConfigManager(context);
4506 PersistableBundle c = configManager.getConfigForSubId(subId);
4507 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004508 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004509 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4510 false);
4511 boolean requireVoiceVtProvisioning = c.getBoolean(
4512 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4513
4514 // First check to make sure that the capability requires provisioning.
4515 switch (capability) {
4516 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4517 // intentional fallthrough
4518 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4519 if (requireVoiceVtProvisioning) {
4520 // Voice and Video requires provisioning
4521 return true;
4522 }
4523 break;
4524 }
4525 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4526 if (requireUtProvisioning) {
4527 // UT requires provisioning
4528 return true;
4529 }
4530 break;
4531 }
4532 }
4533 return false;
4534 }
4535
allenwtsu99c623b2020-01-03 18:24:23 +08004536 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4537 int capability) {
4538 CarrierConfigManager configManager = new CarrierConfigManager(context);
4539 PersistableBundle c = configManager.getConfigForSubId(subId);
4540
4541 boolean requireRcsProvisioning = c.getBoolean(
4542 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4543
4544 // First check to make sure that the capability requires provisioning.
4545 switch (capability) {
4546 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4547 // intentional fallthrough
4548 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4549 if (requireRcsProvisioning) {
4550 // OPTION or PRESENCE requires provisioning
4551 return true;
4552 }
4553 break;
4554 }
4555 }
4556 return false;
4557 }
4558
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004559 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004560 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004561 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4562 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4563 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004564 enforceReadPrivilegedPermission("getImsProvisioningInt");
4565 final long identity = Binder.clearCallingIdentity();
4566 try {
4567 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004568 int slotId = getSlotIndex(subId);
4569 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4570 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4571 + subId + "' for key:" + key);
4572 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4573 }
4574 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004575 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004576 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4577 + subId + "' for key:" + key);
4578 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004579 } finally {
4580 Binder.restoreCallingIdentity(identity);
4581 }
4582 }
4583
4584 @Override
4585 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004586 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4587 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4588 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004589 enforceReadPrivilegedPermission("getImsProvisioningString");
4590 final long identity = Binder.clearCallingIdentity();
4591 try {
4592 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004593 int slotId = getSlotIndex(subId);
4594 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4595 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4596 + subId + "' for key:" + key);
4597 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4598 }
4599 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004600 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004601 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4602 + subId + "' for key:" + key);
4603 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004604 } finally {
4605 Binder.restoreCallingIdentity(identity);
4606 }
4607 }
4608
4609 @Override
4610 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004611 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4612 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4613 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4615 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004616 final long identity = Binder.clearCallingIdentity();
4617 try {
4618 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004619 int slotId = getSlotIndex(subId);
4620 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4621 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4622 + subId + "' for key:" + key);
4623 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4624 }
4625 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004626 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004627 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4628 + "' for key:" + key);
4629 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004630 } finally {
4631 Binder.restoreCallingIdentity(identity);
4632 }
4633 }
4634
4635 @Override
4636 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004637 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4638 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4639 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4641 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004642 final long identity = Binder.clearCallingIdentity();
4643 try {
4644 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004645 int slotId = getSlotIndex(subId);
4646 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4647 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4648 + subId + "' for key:" + key);
4649 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4650 }
4651 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004652 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004653 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4654 + "' for key:" + key);
4655 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004656 } finally {
4657 Binder.restoreCallingIdentity(identity);
4658 }
4659 }
4660
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004661 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004662 int slotId = SubscriptionManager.getSlotIndex(subId);
4663 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004664 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4665 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004666 }
4667 return slotId;
4668 }
4669
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004670 private int getSlotIndex(int subId) {
4671 int slotId = SubscriptionManager.getSlotIndex(subId);
4672 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4673 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4674 }
4675 return slotId;
4676 }
4677
Wink Saville36469e72014-06-11 15:17:00 -07004678 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004679 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004680 */
4681 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004682 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4683 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004684 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004685 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004686 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004687 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004688 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004689 mApp, subId, callingPackage, callingFeatureId,
4690 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004691 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4692 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004694 final long identity = Binder.clearCallingIdentity();
4695 try {
4696 final Phone phone = getPhone(subId);
4697 if (phone != null) {
4698 return phone.getServiceState().getDataNetworkType();
4699 } else {
4700 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4701 }
4702 } finally {
4703 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004705 }
4706
4707 /**
4708 * Returns the data network type
4709 */
4710 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004711 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4712 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4713 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004714 }
4715
4716 /**
4717 * Returns the data network type for a subId
4718 */
4719 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004720 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4721 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004722 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004723 mApp, subId, callingPackage, callingFeatureId,
4724 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004725 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4726 }
4727
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004728 final long identity = Binder.clearCallingIdentity();
4729 try {
4730 final Phone phone = getPhone(subId);
4731 if (phone != null) {
4732 return phone.getServiceState().getDataNetworkType();
4733 } else {
4734 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4735 }
4736 } finally {
4737 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004738 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004739 }
4740
4741 /**
Wink Saville36469e72014-06-11 15:17:00 -07004742 * Returns the Voice network type for a subId
4743 */
4744 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004745 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4746 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004747 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004748 mApp, subId, callingPackage, callingFeatureId,
4749 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004750 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4751 }
4752
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004753 final long identity = Binder.clearCallingIdentity();
4754 try {
4755 final Phone phone = getPhone(subId);
4756 if (phone != null) {
4757 return phone.getServiceState().getVoiceNetworkType();
4758 } else {
4759 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4760 }
4761 } finally {
4762 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004763 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004764 }
4765
4766 /**
4767 * @return true if a ICC card is present
4768 */
4769 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004770 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004771 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4772 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004773 }
4774
4775 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004776 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004777 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004778 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004779 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004780 final long identity = Binder.clearCallingIdentity();
4781 try {
4782 final Phone phone = PhoneFactory.getPhone(slotIndex);
4783 if (phone != null) {
4784 return phone.getIccCard().hasIccCard();
4785 } else {
4786 return false;
4787 }
4788 } finally {
4789 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004790 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004791 }
4792
4793 /**
4794 * Return if the current radio is LTE on CDMA. This
4795 * is a tri-state return value as for a period of time
4796 * the mode may be unknown.
4797 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004798 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004799 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004800 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004801 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004802 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004803 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4804 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4805 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004806 }
4807
Sanket Padawe356d7632015-06-22 14:03:32 -07004808 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004809 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4810 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004811 try {
4812 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4813 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004814 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4815 }
4816
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004817 final long identity = Binder.clearCallingIdentity();
4818 try {
4819 final Phone phone = getPhone(subId);
4820 if (phone == null) {
4821 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4822 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004823 return TelephonyProperties.lte_on_cdma_device()
4824 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004825 }
4826 } finally {
4827 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004828 }
Wink Saville36469e72014-06-11 15:17:00 -07004829 }
4830
Wink Saville36469e72014-06-11 15:17:00 -07004831 /**
4832 * {@hide}
4833 * Returns Default subId, 0 in the case of single standby.
4834 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004835 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004836 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004837 }
4838
Shishir Agrawala9f32182016-04-12 12:00:16 -07004839 private int getSlotForDefaultSubscription() {
4840 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4841 }
4842
Wink Savilleb564aae2014-10-23 10:18:09 -07004843 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004844 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004845 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004846
Pengquan Menge92a50d2018-09-21 15:54:48 -07004847 private boolean isActiveSubscription(int subId) {
4848 return mSubscriptionController.isActiveSubId(subId);
4849 }
4850
Ihab Awadf2177b72013-11-25 13:33:23 -08004851 /**
4852 * @see android.telephony.TelephonyManager.WifiCallingChoices
4853 */
4854 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004855 final long identity = Binder.clearCallingIdentity();
4856 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004857 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004858 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4859 getWhenToMakeWifiCallsDefaultPreference());
4860 } finally {
4861 Binder.restoreCallingIdentity(identity);
4862 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004863 }
4864
4865 /**
4866 * @see android.telephony.TelephonyManager.WifiCallingChoices
4867 */
4868 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004869 final long identity = Binder.clearCallingIdentity();
4870 try {
4871 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004872 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004873 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4874 } finally {
4875 Binder.restoreCallingIdentity(identity);
4876 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004877 }
4878
Sailesh Nepald1e68152013-12-12 19:08:02 -08004879 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004880 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004881 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004882 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004883
Jordan Liu4c733742019-02-28 12:03:40 -08004884 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4885 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4886 if (phoneId == -1) {
4887 throw new IllegalArgumentException("Given slot index: " + slotIndex
4888 + " does not correspond to an active phone");
4889 }
4890 return PhoneFactory.getPhone(phoneId);
4891 }
4892
Shishir Agrawal566b7612013-10-28 14:41:00 -07004893 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004894 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4895 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004896 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4897 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004898 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004899 if (DBG) {
4900 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4901 }
4902 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4903 p2);
4904 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004905
Jordan Liu4c733742019-02-28 12:03:40 -08004906
4907 @Override
4908 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4909 int slotIndex, String callingPackage, String aid, int p2) {
4910 enforceModifyPermission();
4911 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4912 if (DBG) {
4913 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4914 }
4915 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4916 callingPackage, aid, p2);
4917 }
4918
4919 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4920 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004921 final long identity = Binder.clearCallingIdentity();
4922 try {
4923 if (TextUtils.equals(ISDR_AID, aid)) {
4924 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004925 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4926 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004927 if (bestComponent == null
4928 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4929 loge("The calling package is not allowed to access ISD-R.");
4930 throw new SecurityException(
4931 "The calling package is not allowed to access ISD-R.");
4932 }
Derek Tan740e1672017-06-27 14:56:27 -07004933 }
Derek Tan740e1672017-06-27 14:56:27 -07004934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004936 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4937 null /* workSource */);
4938 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004939 return response;
4940 } finally {
4941 Binder.restoreCallingIdentity(identity);
4942 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004943 }
4944
4945 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004946 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004947 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4948 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004949 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4950 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4951 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004952
Jordan Liu4c733742019-02-28 12:03:40 -08004953 @Override
4954 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4955 enforceModifyPermission();
4956 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4957 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4958 channel);
4959 }
4960
4961 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962 final long identity = Binder.clearCallingIdentity();
4963 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004964 if (channel < 0) {
4965 return false;
4966 }
Jordan Liu4c733742019-02-28 12:03:40 -08004967 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4968 null /* workSource */);
4969 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970 return success;
4971 } finally {
4972 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004973 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004974 }
4975
4976 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004977 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004978 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4980 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004981 if (DBG) {
4982 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4983 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4984 + p3 + " data=" + data);
4985 }
4986 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4987 command, p1, p2, p3, data);
4988 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004989
Jordan Liu4c733742019-02-28 12:03:40 -08004990 @Override
4991 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4992 int command, int p1, int p2, int p3, String data) {
4993 enforceModifyPermission();
4994 if (DBG) {
4995 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4996 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4997 + p3 + " data=" + data);
4998 }
4999 return iccTransmitApduLogicalChannelWithPermission(
5000 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5001 data);
5002 }
5003
5004 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5005 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006 final long identity = Binder.clearCallingIdentity();
5007 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005008 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005009 return "";
5010 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005013 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5014 null /* workSource */);
5015 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017 // Append the returned status code to the end of the response payload.
5018 String s = Integer.toHexString(
5019 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5020 if (response.payload != null) {
5021 s = IccUtils.bytesToHexString(response.payload) + s;
5022 }
5023 return s;
5024 } finally {
5025 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005026 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005027 }
Jake Hambye994d462014-02-03 13:10:13 -08005028
Evan Charltonc66da362014-05-16 14:06:40 -07005029 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005030 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5031 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5033 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005034 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005035 if (DBG) {
5036 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5037 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5038 }
5039 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5040 cla, command, p1, p2, p3, data);
5041 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005042
Jordan Liu4c733742019-02-28 12:03:40 -08005043 @Override
5044 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5045 int command, int p1, int p2, int p3, String data) {
5046 enforceModifyPermission();
5047 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5048 if (DBG) {
5049 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5050 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5051 + " data=" + data);
5052 }
5053
5054 return iccTransmitApduBasicChannelWithPermission(
5055 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5056 p2, p3, data);
5057 }
5058
5059 // open APDU basic channel assuming the caller has sufficient permissions
5060 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5061 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005062 final long identity = Binder.clearCallingIdentity();
5063 try {
5064 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5065 && TextUtils.equals(ISDR_AID, data)) {
5066 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005067 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5068 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005069 if (bestComponent == null
5070 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5071 loge("The calling package is not allowed to select ISD-R.");
5072 throw new SecurityException(
5073 "The calling package is not allowed to select ISD-R.");
5074 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005075 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005076
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005077 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005078 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5079 null /* workSource */);
5080 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005081
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005082 // Append the returned status code to the end of the response payload.
5083 String s = Integer.toHexString(
5084 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5085 if (response.payload != null) {
5086 s = IccUtils.bytesToHexString(response.payload) + s;
5087 }
5088 return s;
5089 } finally {
5090 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005091 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005092 }
5093
5094 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005095 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005096 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5098 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005099
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005100 final long identity = Binder.clearCallingIdentity();
5101 try {
5102 if (DBG) {
5103 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5104 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5105 }
5106
5107 IccIoResult response =
5108 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5109 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5110 subId);
5111
5112 if (DBG) {
5113 log("Exchange SIM_IO [R]" + response);
5114 }
5115
5116 byte[] result = null;
5117 int length = 2;
5118 if (response.payload != null) {
5119 length = 2 + response.payload.length;
5120 result = new byte[length];
5121 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5122 } else {
5123 result = new byte[length];
5124 }
5125
5126 result[length - 1] = (byte) response.sw2;
5127 result[length - 2] = (byte) response.sw1;
5128 return result;
5129 } finally {
5130 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005131 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005132 }
5133
Nathan Haroldb3014052017-01-25 15:57:32 -08005134 /**
5135 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5136 * on a particular subscription
5137 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005138 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5139 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005140 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005141 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005142 return null;
5143 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005144
5145 final long identity = Binder.clearCallingIdentity();
5146 try {
5147 if (appType != TelephonyManager.APPTYPE_USIM
5148 && appType != TelephonyManager.APPTYPE_SIM) {
5149 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5150 return null;
5151 }
5152 Object response = sendRequest(
5153 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5154 if (response instanceof String[]) {
5155 return (String[]) response;
5156 }
yincheng zhaod698b842019-09-06 17:06:54 -07005157 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005159 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005160 } finally {
5161 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005162 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005163 }
5164
yincheng zhaod698b842019-09-06 17:06:54 -07005165 /**
5166 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5167 * subscription.
5168 *
5169 * @param subId the id of the subscription.
5170 * @param appType the uicc app type, must be USIM or SIM.
5171 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5172 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005173 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005174 * @return number of fplmns that is successfully written to the SIM.
5175 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005176 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5177 String callingFeatureId) {
5178 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5179 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005180 if (DBG) logv("no permissions for setForbiddenplmns");
5181 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5182 }
5183 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5184 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5185 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5186 }
5187 if (fplmns == null) {
5188 throw new IllegalArgumentException("Fplmn List provided is null");
5189 }
5190 for (String fplmn : fplmns) {
5191 if (!CellIdentity.isValidPlmn(fplmn)) {
5192 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5193 }
5194 }
5195 final long identity = Binder.clearCallingIdentity();
5196 try {
5197 Object response = sendRequest(
5198 CMD_SET_FORBIDDEN_PLMNS,
5199 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5200 subId);
5201 return (int) response;
5202 } finally {
5203 Binder.restoreCallingIdentity(identity);
5204 }
5205 }
5206
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005207 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005208 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5210 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005211
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005212 final long identity = Binder.clearCallingIdentity();
5213 try {
5214 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5215 if (response.payload == null) {
5216 return "";
5217 }
Evan Charltonc66da362014-05-16 14:06:40 -07005218
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005219 // Append the returned status code to the end of the response payload.
5220 String s = Integer.toHexString(
5221 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5222 s = IccUtils.bytesToHexString(response.payload) + s;
5223 return s;
5224 } finally {
5225 Binder.restoreCallingIdentity(identity);
5226 }
Evan Charltonc66da362014-05-16 14:06:40 -07005227 }
5228
Jake Hambye994d462014-02-03 13:10:13 -08005229 /**
5230 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5231 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5232 *
5233 * @param itemID the ID of the item to read
5234 * @return the NV item as a String, or null on error.
5235 */
5236 @Override
5237 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005238 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5240 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241
5242 final long identity = Binder.clearCallingIdentity();
5243 try {
5244 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005245 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5247 return value;
5248 } finally {
5249 Binder.restoreCallingIdentity(identity);
5250 }
Jake Hambye994d462014-02-03 13:10:13 -08005251 }
5252
5253 /**
5254 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5255 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5256 *
5257 * @param itemID the ID of the item to read
5258 * @param itemValue the value to write, as a String
5259 * @return true on success; false on any failure
5260 */
5261 @Override
5262 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005263 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005264 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5265 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005266
5267 final long identity = Binder.clearCallingIdentity();
5268 try {
5269 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5270 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005271 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005272 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5273 return success;
5274 } finally {
5275 Binder.restoreCallingIdentity(identity);
5276 }
Jake Hambye994d462014-02-03 13:10:13 -08005277 }
5278
5279 /**
5280 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5281 * Used for device configuration by some CDMA operators.
5282 *
5283 * @param preferredRoamingList byte array containing the new PRL
5284 * @return true on success; false on any failure
5285 */
5286 @Override
5287 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005288 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5289 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290
5291 final long identity = Binder.clearCallingIdentity();
5292 try {
5293 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5294 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5295 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5296 return success;
5297 } finally {
5298 Binder.restoreCallingIdentity(identity);
5299 }
Jake Hambye994d462014-02-03 13:10:13 -08005300 }
5301
5302 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005303 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005304 * Used for device configuration by some CDMA operators.
5305 *
chen xu6dac5ab2018-10-26 17:39:23 -07005306 * @param slotIndex - device slot.
5307 *
Jake Hambye994d462014-02-03 13:10:13 -08005308 * @return true on success; false on any failure
5309 */
5310 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005311 public boolean resetModemConfig(int slotIndex) {
5312 Phone phone = PhoneFactory.getPhone(slotIndex);
5313 if (phone != null) {
5314 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5315 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005316
chen xu6dac5ab2018-10-26 17:39:23 -07005317 final long identity = Binder.clearCallingIdentity();
5318 try {
5319 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5320 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5321 return success;
5322 } finally {
5323 Binder.restoreCallingIdentity(identity);
5324 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325 }
chen xu6dac5ab2018-10-26 17:39:23 -07005326 return false;
5327 }
5328
5329 /**
5330 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5331 *
5332 * @param slotIndex - device slot.
5333 *
5334 * @return true on success; false on any failure
5335 */
5336 @Override
5337 public boolean rebootModem(int slotIndex) {
5338 Phone phone = PhoneFactory.getPhone(slotIndex);
5339 if (phone != null) {
5340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5341 mApp, phone.getSubId(), "rebootModem");
5342
5343 final long identity = Binder.clearCallingIdentity();
5344 try {
5345 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5346 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5347 return success;
5348 } finally {
5349 Binder.restoreCallingIdentity(identity);
5350 }
5351 }
5352 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005353 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005354
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005355 public String[] getPcscfAddress(String apnType, String callingPackage,
5356 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005357 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005358 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5359 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005360 return new String[0];
5361 }
5362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005363 final long identity = Binder.clearCallingIdentity();
5364 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005365 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005366 } finally {
5367 Binder.restoreCallingIdentity(identity);
5368 }
Wink Saville36469e72014-06-11 15:17:00 -07005369 }
5370
Brad Ebinger51f743a2017-01-23 13:50:20 -08005371 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005372 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5373 * {@link #disableIms(int)}.
5374 * @param slotIndex device slot.
5375 */
5376 public void resetIms(int slotIndex) {
5377 enforceModifyPermission();
5378
5379 final long identity = Binder.clearCallingIdentity();
5380 try {
5381 if (mImsResolver == null) {
5382 // may happen if the does not support IMS.
5383 return;
5384 }
5385 mImsResolver.disableIms(slotIndex);
5386 mImsResolver.enableIms(slotIndex);
5387 } finally {
5388 Binder.restoreCallingIdentity(identity);
5389 }
5390 }
5391
5392 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005393 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5394 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005395 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005396 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -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 Ebinger9c0eb502019-01-23 15:06:19 -08005402 // may happen if the device does not support IMS.
5403 return;
5404 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005405 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 } finally {
5407 Binder.restoreCallingIdentity(identity);
5408 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005409 }
5410
5411 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005412 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5413 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005414 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005415 public void disableIms(int slotId) {
5416 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005417
5418 final long identity = Binder.clearCallingIdentity();
5419 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005420 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005421 // may happen if the device does not support IMS.
5422 return;
5423 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005424 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425 } finally {
5426 Binder.restoreCallingIdentity(identity);
5427 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005428 }
5429
5430 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005431 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5432 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005433 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005434 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005435 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005436 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005437
5438 final long identity = Binder.clearCallingIdentity();
5439 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005440 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005441 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5442 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005443 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005444 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 } finally {
5446 Binder.restoreCallingIdentity(identity);
5447 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005448 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005449 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005450 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5451 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005452 @Override
5453 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005454 enforceModifyPermission();
5455
5456 final long identity = Binder.clearCallingIdentity();
5457 try {
5458 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005459 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005460 } finally {
5461 Binder.restoreCallingIdentity(identity);
5462 }
5463 }
5464
5465 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005466 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005467 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005468 */
5469 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5470 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471
5472 final long identity = Binder.clearCallingIdentity();
5473 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005474 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005475 // may happen if the device does not support IMS.
5476 return null;
5477 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005478 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005479 } finally {
5480 Binder.restoreCallingIdentity(identity);
5481 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005482 }
5483
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005484 /**
5485 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005486 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005487 */
5488 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5489 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490
5491 final long identity = Binder.clearCallingIdentity();
5492 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005493 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005494 // may happen if the device does not support IMS.
5495 return null;
5496 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005497 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005498 } finally {
5499 Binder.restoreCallingIdentity(identity);
5500 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005501 }
5502
Brad Ebinger884c07b2018-02-15 16:17:40 -08005503 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005504 * Sets the ImsService Package Name that Telephony will bind to.
5505 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005506 * @param slotIndex the slot ID that the ImsService should bind for.
5507 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005508 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005509 * @param featureTypes An integer array of feature types associated with a packageName.
5510 * @param packageName The name of the package that the current configuration will be replaced
5511 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005512 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005513 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005514 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5515 int[] featureTypes, String packageName) {
5516 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5517 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005518 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5519 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005520 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522 final long identity = Binder.clearCallingIdentity();
5523 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005524 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005525 // may happen if the device does not support IMS.
5526 return false;
5527 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005528 Map<Integer, String> featureConfig = new HashMap<>();
5529 for (int featureType : featureTypes) {
5530 featureConfig.put(featureType, packageName);
5531 }
5532 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5533 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005534 } finally {
5535 Binder.restoreCallingIdentity(identity);
5536 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005537 }
5538
5539 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005540 * Clears any carrier ImsService overrides for the slot index specified that were previously
5541 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5542 *
5543 * This should only be used for testing.
5544 *
5545 * @param slotIndex the slot ID that the ImsService should bind for.
5546 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5547 */
5548 @Override
5549 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5550 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5551 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5552 "clearCarrierImsServiceOverride");
5553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5554 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5555 "clearCarrierImsServiceOverride");
5556
5557 final long identity = Binder.clearCallingIdentity();
5558 try {
5559 if (mImsResolver == null) {
5560 // may happen if the device does not support IMS.
5561 return false;
5562 }
5563 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5564 } finally {
5565 Binder.restoreCallingIdentity(identity);
5566 }
5567 }
5568
5569 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005570 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005571 *
5572 * @param slotId The slot that the ImsService is associated with.
5573 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5574 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005575 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005576 * @return the package name of the ImsService configuration.
5577 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005578 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5579 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005580 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005581 TelephonyPermissions
5582 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5583 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5584 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005585
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586 final long identity = Binder.clearCallingIdentity();
5587 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005588 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005589 // may happen if the device does not support IMS.
5590 return "";
5591 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005592 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005593 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5594 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005595 } finally {
5596 Binder.restoreCallingIdentity(identity);
5597 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005598 }
5599
Brad Ebinger77b832e2019-10-17 17:03:22 -07005600 /**
5601 * Get the MmTelFeature state associated with the requested subscription id.
5602 * @param subId The subscription that the MmTelFeature is associated with.
5603 * @param callback A callback with an integer containing the
5604 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5605 */
5606 @Override
5607 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5608 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5609 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5610 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5611 "IMS not available on device.");
5612 }
5613 final long token = Binder.clearCallingIdentity();
5614 try {
5615 int slotId = getSlotIndex(subId);
5616 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5617 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5618 + subId + "'");
5619 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5620 }
5621 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5622 try {
5623 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5624 } catch (RemoteException e) {
5625 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5626 + "Ignore");
5627 }
5628 });
5629 } finally {
5630 Binder.restoreCallingIdentity(token);
5631 }
5632 }
5633
Daniel Brightbb5840b2021-01-12 15:48:18 -08005634 /**
5635 * Sets the ims registration state on all valid {@link Phone}s.
5636 */
5637 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005638 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639
5640 final long identity = Binder.clearCallingIdentity();
5641 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005642 // NOTE: Before S, this method only set the default phone.
5643 for (final Phone phone : PhoneFactory.getPhones()) {
5644 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5645 phone.setImsRegistrationState(registered);
5646 }
5647 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005648 } finally {
5649 Binder.restoreCallingIdentity(identity);
5650 }
Wink Saville36469e72014-06-11 15:17:00 -07005651 }
5652
5653 /**
Stuart Scott54788802015-03-30 13:18:01 -07005654 * Set the network selection mode to automatic.
5655 *
5656 */
5657 @Override
5658 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5660 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005661
5662 final long identity = Binder.clearCallingIdentity();
5663 try {
shilufc958392020-01-20 11:36:01 -08005664 if (!isActiveSubscription(subId)) {
5665 return;
5666 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005667 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005668 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5669 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005670 } finally {
5671 Binder.restoreCallingIdentity(identity);
5672 }
Stuart Scott54788802015-03-30 13:18:01 -07005673 }
5674
Jack Yud10cdd42020-09-28 20:28:01 -07005675 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005676 * Ask the radio to connect to the input network and change selection mode to manual.
5677 *
5678 * @param subId the id of the subscription.
5679 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5680 * the operator to attach to.
5681 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5682 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5683 * normal network selection next time.
5684 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005685 */
5686 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005687 public boolean setNetworkSelectionModeManual(
5688 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005689 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5690 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005691
5692 if (!isActiveSubscription(subId)) {
5693 return false;
5694 }
5695
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696 final long identity = Binder.clearCallingIdentity();
5697 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005698 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005700 if (DBG) {
5701 log("setNetworkSelectionModeManual: subId: " + subId
5702 + " operator: " + operatorInfo);
5703 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005704 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5705 } finally {
5706 Binder.restoreCallingIdentity(identity);
5707 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005708 }
shilu84f6e8b2019-12-19 13:58:01 -08005709 /**
5710 * Get the manual network selection
5711 *
5712 * @param subId the id of the subscription.
5713 *
5714 * @return the previously saved user selected PLMN
5715 */
5716 @Override
5717 public String getManualNetworkSelectionPlmn(int subId) {
5718 TelephonyPermissions
5719 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5720 mApp, subId, "getManualNetworkSelectionPlmn");
5721
5722 final long identity = Binder.clearCallingIdentity();
5723 try {
5724 if (!isActiveSubscription(subId)) {
5725 return "";
5726 }
5727
5728 final Phone phone = getPhone(subId);
5729 if (phone == null) {
5730 return "";
5731 }
5732 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5733 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5734 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5735 } finally {
5736 Binder.restoreCallingIdentity(identity);
5737 }
5738 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005739
5740 /**
5741 * Scans for available networks.
5742 */
5743 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005744 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5745 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5747 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005748 LocationAccessPolicy.LocationPermissionResult locationResult =
5749 LocationAccessPolicy.checkLocationPermission(mApp,
5750 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5751 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005752 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005753 .setCallingPid(Binder.getCallingPid())
5754 .setCallingUid(Binder.getCallingUid())
5755 .setMethod("getCellNetworkScanResults")
5756 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5757 .build());
5758 switch (locationResult) {
5759 case DENIED_HARD:
5760 throw new SecurityException("Not allowed to access scan results -- location");
5761 case DENIED_SOFT:
5762 return null;
5763 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764
Pengquan Menga1bb6272018-09-06 09:59:22 -07005765 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766 try {
5767 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005768 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005769 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770 } finally {
5771 Binder.restoreCallingIdentity(identity);
5772 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005773 }
5774
5775 /**
sqian80370722020-01-29 15:02:51 -08005776 * Get the call forwarding info, given the call forwarding reason.
5777 */
5778 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005779 public void getCallForwarding(int subId, int callForwardingReason,
5780 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005781 enforceReadPrivilegedPermission("getCallForwarding");
5782 long identity = Binder.clearCallingIdentity();
5783 try {
5784 if (DBG) {
5785 log("getCallForwarding: subId " + subId
5786 + " callForwardingReason" + callForwardingReason);
5787 }
Hall Liua1acea22020-09-18 19:04:59 -07005788
5789 Phone phone = getPhone(subId);
5790 if (phone == null) {
5791 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005792 callback.onError(
5793 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005794 } catch (RemoteException e) {
5795 // ignore
5796 }
5797 return;
5798 }
5799
5800 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5801 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5802 @Override
5803 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5804 try {
5805 callback.onCallForwardingInfoAvailable(info);
5806 } catch (RemoteException e) {
5807 // ignore
5808 }
5809 }
5810
5811 @Override
5812 public void onError(int error) {
5813 try {
5814 callback.onError(error);
5815 } catch (RemoteException e) {
5816 // ignore
5817 }
5818 }
5819 });
5820 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005821 } finally {
5822 Binder.restoreCallingIdentity(identity);
5823 }
5824 }
5825
5826 /**
5827 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5828 * reason, the number to forward, and the timeout before the forwarding is attempted.
5829 */
5830 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005831 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5832 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005833 enforceModifyPermission();
5834 long identity = Binder.clearCallingIdentity();
5835 try {
5836 if (DBG) {
5837 log("setCallForwarding: subId " + subId
5838 + " callForwardingInfo" + callForwardingInfo);
5839 }
Hall Liua1acea22020-09-18 19:04:59 -07005840
5841 Phone phone = getPhone(subId);
5842 if (phone == null) {
5843 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005844 callback.accept(
5845 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005846 } catch (RemoteException e) {
5847 // ignore
5848 }
5849 return;
5850 }
5851
5852 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5853 FunctionalUtils.ignoreRemoteException(callback::accept));
5854
5855 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005856 } finally {
5857 Binder.restoreCallingIdentity(identity);
5858 }
5859 }
5860
5861 /**
Hall Liua1acea22020-09-18 19:04:59 -07005862 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005863 */
5864 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005865 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005866 enforceReadPrivilegedPermission("getCallForwarding");
5867 long identity = Binder.clearCallingIdentity();
5868 try {
Hall Liua1acea22020-09-18 19:04:59 -07005869
5870 Phone phone = getPhone(subId);
5871 if (phone == null) {
5872 try {
5873 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5874 } catch (RemoteException e) {
5875 // ignore
5876 }
5877 return;
5878 }
5879
5880 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5881
sqian80370722020-01-29 15:02:51 -08005882 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005883 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005884 } finally {
5885 Binder.restoreCallingIdentity(identity);
5886 }
5887 }
5888
5889 /**
Hall Liua1acea22020-09-18 19:04:59 -07005890 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005891 */
5892 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005893 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005894 enforceModifyPermission();
5895 long identity = Binder.clearCallingIdentity();
5896 try {
Hall Liua1acea22020-09-18 19:04:59 -07005897 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5898
5899 Phone phone = getPhone(subId);
5900 if (phone == null) {
5901 try {
5902 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5903 } catch (RemoteException e) {
5904 // ignore
5905 }
5906 return;
5907 }
5908
5909 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5910 FunctionalUtils.ignoreRemoteException(callback::accept));
5911
5912 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005913 } finally {
5914 Binder.restoreCallingIdentity(identity);
5915 }
5916 }
5917
5918 /**
yinxub1bed742017-04-17 11:45:04 -07005919 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005920 *
yinxub1bed742017-04-17 11:45:04 -07005921 * @param subId id of the subscription
5922 * @param request contains the radio access networks with bands/channels to scan
5923 * @param messenger callback messenger for scan results or errors
5924 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005925 * @return the id of the requested scan which can be used to stop the scan.
5926 */
5927 @Override
5928 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005929 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005930 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5931 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005932 LocationAccessPolicy.LocationPermissionResult locationResult =
5933 LocationAccessPolicy.checkLocationPermission(mApp,
5934 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5935 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005936 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005937 .setCallingPid(Binder.getCallingPid())
5938 .setCallingUid(Binder.getCallingUid())
5939 .setMethod("requestNetworkScan")
5940 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5941 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005942 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005943 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5944 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005945 if (e != null) {
5946 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5947 throw e;
5948 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005949 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005950 return TelephonyScanManager.INVALID_SCAN_ID;
5951 }
5952 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953 }
Hall Liu912dfd32019-04-25 14:02:26 -07005954 int callingUid = Binder.getCallingUid();
5955 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005956 final long identity = Binder.clearCallingIdentity();
5957 try {
5958 return mNetworkScanRequestTracker.startNetworkScan(
5959 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005960 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005961 } finally {
5962 Binder.restoreCallingIdentity(identity);
5963 }
yinxu504e1392017-04-12 16:03:22 -07005964 }
5965
Hall Liub2ac8ef2019-02-28 15:56:23 -08005966 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005967 NetworkScanRequest request, int subId, String callingPackage) {
5968 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005969 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5970 boolean hasNetworkScanPermission =
5971 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5972 == PERMISSION_GRANTED;
5973
5974 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5975 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5976 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005977 }
5978
5979 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5980 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005981 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5982 return new SecurityException("Specific channels must not be"
5983 + " scanned without location access.");
5984 }
5985 }
5986 }
5987
Hall Liub2ac8ef2019-02-28 15:56:23 -08005988 return null;
5989 }
5990
yinxu504e1392017-04-12 16:03:22 -07005991 /**
5992 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005993 *
5994 * @param subId id of the subscription
5995 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005996 */
5997 @Override
5998 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6000 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001
Hall Liu912dfd32019-04-25 14:02:26 -07006002 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003 final long identity = Binder.clearCallingIdentity();
6004 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006005 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 } finally {
6007 Binder.restoreCallingIdentity(identity);
6008 }
yinxu504e1392017-04-12 16:03:22 -07006009 }
6010
6011 /**
Junda Liu84d15a22014-07-02 11:21:04 -07006012 * Get the calculated preferred network type.
6013 * Used for debugging incorrect network type.
6014 *
6015 * @return the preferred network type, defined in RILConstants.java.
6016 */
6017 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006018 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006019 final Phone defaultPhone = getDefaultPhone();
6020 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006021 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006022 return RILConstants.PREFERRED_NETWORK_MODE;
6023 }
6024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006025 final long identity = Binder.clearCallingIdentity();
6026 try {
6027 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006028 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006029 } finally {
6030 Binder.restoreCallingIdentity(identity);
6031 }
Junda Liu84d15a22014-07-02 11:21:04 -07006032 }
6033
6034 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08006035 * Get the preferred network type.
6036 * Used for device configuration by some CDMA operators.
6037 *
6038 * @return the preferred network type, defined in RILConstants.java.
6039 */
6040 @Override
Stuart Scott54788802015-03-30 13:18:01 -07006041 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006042 TelephonyPermissions
6043 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6044 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045
6046 final long identity = Binder.clearCallingIdentity();
6047 try {
6048 if (DBG) log("getPreferredNetworkType");
6049 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
6050 int networkType = (result != null ? result[0] : -1);
6051 if (DBG) log("getPreferredNetworkType: " + networkType);
6052 return networkType;
6053 } finally {
6054 Binder.restoreCallingIdentity(identity);
6055 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006056 }
6057
6058 /**
6059 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08006060 *
6061 * @param networkType the preferred network type, defined in RILConstants.java.
6062 * @return true on success; false on any failure.
6063 */
6064 @Override
Stuart Scott54788802015-03-30 13:18:01 -07006065 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6067 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068
6069 final long identity = Binder.clearCallingIdentity();
6070 try {
calvinpan089c2a62020-03-12 14:17:55 +08006071 Boolean success = (Boolean) sendRequest(
6072 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08006073
6074 if (success) {
6075 Settings.Global.putInt(mApp.getContentResolver(),
6076 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
6077 }
calvinpan089c2a62020-03-12 14:17:55 +08006078 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
6079 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006080 } finally {
6081 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07006082 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006083 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006084
6085 /**
calvinpan677fc2b2020-01-14 20:42:55 +08006086 * Get the allowed network types that store in the telephony provider.
6087 *
6088 * @param subId the id of the subscription.
6089 * @return allowedNetworkTypes the allowed network types.
6090 */
6091 @Override
6092 public long getAllowedNetworkTypes(int subId) {
6093 TelephonyPermissions
6094 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6095 mApp, subId, "getAllowedNetworkTypes");
6096
6097 final long identity = Binder.clearCallingIdentity();
6098 try {
6099 return SubscriptionManager.getLongSubscriptionProperty(
6100 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
6101 } finally {
6102 Binder.restoreCallingIdentity(identity);
6103 }
6104 }
6105
6106 /**
6107 * Set the allowed network types.
6108 *
6109 * @param subId the id of the subscription.
6110 * @param allowedNetworkTypes the allowed network types.
6111 * @return true on success; false on any failure.
6112 */
6113 @Override
6114 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
6115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6116 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08006117
calvinpan089c2a62020-03-12 14:17:55 +08006118 SubscriptionManager.setSubscriptionProperty(subId,
6119 SubscriptionManager.ALLOWED_NETWORK_TYPES,
6120 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08006121
calvinpan089c2a62020-03-12 14:17:55 +08006122 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6123 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6124 RILConstants.PREFERRED_NETWORK_MODE);
6125 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08006126 }
6127
6128 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006129 * Get the allowed network types for certain reason.
6130 *
6131 * @param subId the id of the subscription.
6132 * @param reason the reason the allowed network type change is taking place
6133 * @return the allowed network types.
6134 */
6135 @Override
6136 public long getAllowedNetworkTypesForReason(int subId,
6137 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6138 TelephonyPermissions
6139 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6140 mApp, subId, "getAllowedNetworkTypesForReason");
6141 final long identity = Binder.clearCallingIdentity();
6142 try {
6143 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6144 } finally {
6145 Binder.restoreCallingIdentity(identity);
6146 }
6147 }
6148
6149 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006150 * Enable/Disable E-UTRA-NR Dual Connectivity
6151 * @param subId subscription id of the sim card
6152 * @param nrDualConnectivityState expected NR dual connectivity state
6153 * This can be passed following states
6154 * <ol>
6155 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6156 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6157 * <li>Disable NR dual connectivity and force secondary cell to be released
6158 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6159 * </ol>
6160 * @return operation result.
6161 */
6162 @Override
6163 public int setNrDualConnectivityState(int subId,
6164 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6166 mApp, subId, "enableNRDualConnectivity");
6167 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6168 final long identity = Binder.clearCallingIdentity();
6169 try {
6170 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6171 nrDualConnectivityState, subId,
6172 workSource);
6173 if (DBG) log("enableNRDualConnectivity result: " + result);
6174 return result;
6175 } finally {
6176 Binder.restoreCallingIdentity(identity);
6177 }
6178 }
6179
6180 /**
6181 * Is E-UTRA-NR Dual Connectivity enabled
6182 * @return true if dual connectivity is enabled else false
6183 */
6184 @Override
6185 public boolean isNrDualConnectivityEnabled(int subId) {
6186 TelephonyPermissions
6187 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6188 mApp, subId, "isNRDualConnectivityEnabled");
6189 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6190 final long identity = Binder.clearCallingIdentity();
6191 try {
6192 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6193 null, subId, workSource);
6194 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6195 return isEnabled;
6196 } finally {
6197 Binder.restoreCallingIdentity(identity);
6198 }
6199 }
6200
6201 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006202 * get carrier bandwidth per primary and secondary carrier
6203 * @param subId subscription id of the sim card
6204 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6205 */
6206 @Override
6207 public CarrierBandwidth getCarrierBandwidth(int subId) {
6208 TelephonyPermissions
6209 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6210 mApp, subId, "isNRDualConnectivityEnabled");
6211 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6212 final long identity = Binder.clearCallingIdentity();
6213 try {
6214 CarrierBandwidth carrierBandwidth =
6215 getPhoneFromSubId(subId).getCarrierBandwidth();
6216 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6217 return carrierBandwidth;
6218 } finally {
6219 Binder.restoreCallingIdentity(identity);
6220 }
6221 }
6222
6223 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006224 * Get the effective allowed network types on the device.
6225 * This API will return an intersection of allowed network types for all reasons,
6226 * including the configuration done through setAllowedNetworkTypes
6227 *
6228 * @param subId the id of the subscription.
6229 * @return the allowed network types
6230 */
6231 @Override
6232 public long getEffectiveAllowedNetworkTypes(int subId) {
6233 TelephonyPermissions
6234 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6235 mApp, subId, "getEffectiveAllowedNetworkTypes");
6236 final long identity = Binder.clearCallingIdentity();
6237 try {
6238 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6239 } finally {
6240 Binder.restoreCallingIdentity(identity);
6241 }
6242 }
6243
6244 /**
6245 * Set the allowed network types of the device and
6246 * provide the reason triggering the allowed network change.
6247 *
6248 * @param subId the id of the subscription.
6249 * @param reason the reason the allowed network type change is taking place
6250 * @param allowedNetworkTypes the allowed network types.
6251 * @return true on success; false on any failure.
6252 */
6253 @Override
6254 public boolean setAllowedNetworkTypesForReason(int subId,
6255 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6257 mApp, subId, "setAllowedNetworkTypesForReason");
6258 final long identity = Binder.clearCallingIdentity();
6259 try {
6260 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6261 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6262 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6263 RILConstants.PREFERRED_NETWORK_MODE);
6264 return setPreferredNetworkType(subId, preferredNetworkMode);
6265 } finally {
6266 Binder.restoreCallingIdentity(identity);
6267 }
6268 }
6269
6270 /**
Miaoa84611c2019-03-15 09:21:10 +08006271 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006272 *
Miaoa84611c2019-03-15 09:21:10 +08006273 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006274 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006275 * @hide
6276 */
6277 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006278 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006279 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006281 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282 try {
Miaoa84611c2019-03-15 09:21:10 +08006283 if (phone != null) {
6284 return phone.hasMatchedTetherApnSetting();
6285 } else {
6286 return false;
6287 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288 } finally {
6289 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006290 }
Junda Liu475951f2014-11-07 16:45:03 -08006291 }
6292
6293 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006294 * Enable or disable always reporting signal strength changes from radio.
6295 *
6296 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6297 */
6298 @Override
6299 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6300 enforceModifyPermission();
6301 enforceSystemCaller();
6302
6303 final long identity = Binder.clearCallingIdentity();
6304 final Phone phone = getPhone(subId);
6305 try {
6306 if (phone != null) {
6307 if (DBG) {
6308 log("setAlwaysReportSignalStrength: subId=" + subId
6309 + " isEnable=" + isEnable);
6310 }
6311 phone.setAlwaysReportSignalStrength(isEnable);
6312 } else {
6313 loge("setAlwaysReportSignalStrength: no phone found for subId="
6314 + subId);
6315 }
6316 } finally {
6317 Binder.restoreCallingIdentity(identity);
6318 }
6319 }
6320
6321 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006322 * Get the user enabled state of Mobile Data.
6323 *
6324 * TODO: remove and use isUserDataEnabled.
6325 * This can't be removed now because some vendor codes
6326 * calls through ITelephony directly while they should
6327 * use TelephonyManager.
6328 *
6329 * @return true on enabled
6330 */
6331 @Override
6332 public boolean getDataEnabled(int subId) {
6333 return isUserDataEnabled(subId);
6334 }
6335
6336 /**
6337 * Get whether mobile data is enabled per user setting.
6338 *
6339 * There are other factors deciding whether mobile data is actually enabled, but they are
6340 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006341 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006342 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006343 *
6344 * @return {@code true} if data is enabled else {@code false}
6345 */
6346 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006347 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006348 try {
6349 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6350 null);
6351 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6353 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006354 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006355
6356 final long identity = Binder.clearCallingIdentity();
6357 try {
6358 int phoneId = mSubscriptionController.getPhoneId(subId);
6359 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6360 Phone phone = PhoneFactory.getPhone(phoneId);
6361 if (phone != null) {
6362 boolean retVal = phone.isUserDataEnabled();
6363 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6364 return retVal;
6365 } else {
6366 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6367 return false;
6368 }
6369 } finally {
6370 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006371 }
6372 }
6373
6374 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006375 * Checks if the device is capable of mobile data by considering whether whether the
6376 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6377 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006378 *
Shuo Qian985d1232020-01-08 14:30:06 -08006379 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006380 */
6381 @Override
6382 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006383 try {
6384 try {
6385 mApp.enforceCallingOrSelfPermission(
6386 android.Manifest.permission.ACCESS_NETWORK_STATE,
6387 null);
6388 } catch (Exception e) {
6389 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6390 "isDataEnabled");
6391 }
6392 } catch (Exception e) {
6393 enforceReadPrivilegedPermission("isDataEnabled");
6394 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006395
6396 final long identity = Binder.clearCallingIdentity();
6397 try {
6398 int phoneId = mSubscriptionController.getPhoneId(subId);
6399 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6400 Phone phone = PhoneFactory.getPhone(phoneId);
6401 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006402 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6404 return retVal;
6405 } else {
6406 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6407 return false;
6408 }
6409 } finally {
6410 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006411 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006412 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006413
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006414 /**
6415 * Check if data is enabled for a specific reason
6416 * @param subId Subscription index
6417 * @param reason the reason the data enable change is taking place
6418 * @return {@code true} if the overall data is enabled; {@code false} if not.
6419 */
6420 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006421 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006422 @TelephonyManager.DataEnabledReason int reason) {
6423 try {
6424 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6425 null);
6426 } catch (Exception e) {
6427 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006428 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006429 }
6430
6431
6432 final long identity = Binder.clearCallingIdentity();
6433 try {
6434 int phoneId = mSubscriptionController.getPhoneId(subId);
6435 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006436 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006437 + " reason=" + reason);
6438 }
6439 Phone phone = PhoneFactory.getPhone(phoneId);
6440 if (phone != null) {
6441 boolean retVal;
6442 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6443 retVal = phone.isUserDataEnabled();
6444 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006445 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006446 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006447 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006448 return retVal;
6449 } else {
6450 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006451 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006452 + subId + " retVal=false");
6453 }
6454 return false;
6455 }
6456 } finally {
6457 Binder.restoreCallingIdentity(identity);
6458 }
6459 }
6460
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006461 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006462 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006463 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6464 // Skip the check if it's one of these special uids
6465 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6466 }
6467
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006468 //load access rules from carrier configs, and check those as well: b/139133814
6469 SubscriptionController subController = SubscriptionController.getInstance();
6470 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6471 || subController == null) return privilegeFromSim;
6472
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006473 PackageManager pkgMgr = phone.getContext().getPackageManager();
6474 String[] packages = pkgMgr.getPackagesForUid(uid);
6475
6476 final long identity = Binder.clearCallingIdentity();
6477 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006478 int subId = phone.getSubId();
6479 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6480 // A test override is in place for the privileges for this subId, so don't try to
6481 // read the subscription privileges.
6482 return privilegeFromSim;
6483 }
6484 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006485 SubscriptionManager subManager = (SubscriptionManager)
6486 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6487 for (String pkg : packages) {
6488 if (subManager.canManageSubscription(subInfo, pkg)) {
6489 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6490 }
6491 }
6492 return privilegeFromSim;
6493 } finally {
6494 Binder.restoreCallingIdentity(identity);
6495 }
6496 }
6497
6498 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6499 String pkgName) {
6500 //load access rules from carrier configs, and check those as well: b/139133814
6501 SubscriptionController subController = SubscriptionController.getInstance();
6502 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6503 || subController == null) return privilegeFromSim;
6504
6505 final long identity = Binder.clearCallingIdentity();
6506 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006507 int subId = phone.getSubId();
6508 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6509 // A test override is in place for the privileges for this subId, so don't try to
6510 // read the subscription privileges.
6511 return privilegeFromSim;
6512 }
6513 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006514 SubscriptionManager subManager = (SubscriptionManager)
6515 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6516 return subManager.canManageSubscription(subInfo, pkgName)
6517 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6518 } finally {
6519 Binder.restoreCallingIdentity(identity);
6520 }
6521 }
6522
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006523 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006524 public int getCarrierPrivilegeStatus(int subId) {
6525 final Phone phone = getPhone(subId);
6526 if (phone == null) {
6527 loge("getCarrierPrivilegeStatus: Invalid subId");
6528 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6529 }
6530 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006531 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006532 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006533 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6534 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006535
6536 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6537 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006538 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006539 }
Junda Liu29340342014-07-10 15:23:27 -07006540
6541 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006542 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006543 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006544 final Phone phone = getPhone(subId);
6545 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006546 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006547 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6548 }
6549 UiccProfile profile =
6550 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6551 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006552 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006553 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6554 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006555 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006556 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006557 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006558 }
6559
6560 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006561 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6562 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006563 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006564 }
6565
6566 int phoneId = SubscriptionManager.getPhoneId(subId);
6567 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006568 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006569 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006570 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6571 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006572 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6573 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6574 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006575 }
6576
6577 @Override
6578 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006579 if (TextUtils.isEmpty(pkgName))
6580 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006581 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6582 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6583 UiccCard card = UiccController.getInstance().getUiccCard(i);
6584 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006585 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006586 continue;
6587 }
6588
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006589 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6590 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6591 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006592 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6593 break;
6594 }
6595 }
6596
6597 return result;
Junda Liu29340342014-07-10 15:23:27 -07006598 }
Derek Tan89e89d42014-07-08 17:00:10 -07006599
6600 @Override
Junda Liue64de782015-04-16 17:19:16 -07006601 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6602 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6603 loge("phoneId " + phoneId + " is not valid.");
6604 return null;
6605 }
6606 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006607 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006608 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006609 return null ;
6610 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006611 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006612 }
6613
Amith Yamasani6e118872016-02-19 12:53:51 -08006614 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006615 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006616 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006617 List<String> privilegedPackages = new ArrayList<>();
6618 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006619 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6620 // has UICC in that slot.
6621 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006622 if (card.hasCarrierPrivilegeRules()) {
6623 if (packages == null) {
6624 // Only check packages in user 0 for now
6625 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006626 PackageManager.MATCH_DISABLED_COMPONENTS
6627 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006628 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006629 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006630 }
6631 for (int p = packages.size() - 1; p >= 0; p--) {
6632 PackageInfo pkgInfo = packages.get(p);
6633 if (pkgInfo != null && pkgInfo.packageName != null
6634 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006635 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006636 privilegedPackages.add(pkgInfo.packageName);
6637 }
6638 }
6639 }
6640 }
6641 return privilegedPackages;
6642 }
6643
chen xuf7e9fe82019-05-09 19:31:02 -07006644 @Override
6645 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006646 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6647
6648 final long identity = Binder.clearCallingIdentity();
6649
chen xuf7e9fe82019-05-09 19:31:02 -07006650 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006651 try {
6652 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6653 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6654 }
6655 } finally {
6656 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006657 }
6658 return privilegedPackages;
6659 }
6660
Wink Savilleb564aae2014-10-23 10:18:09 -07006661 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006662 final Phone phone = getPhone(subId);
6663 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006664 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006665 return null;
6666 }
6667 String iccId = card.getIccId();
6668 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006669 return null;
6670 }
6671 return iccId;
6672 }
6673
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006674 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006675 public void setCallComposerStatus(int subId, int status) {
6676 enforceModifyPermission();
6677
6678 final long identity = Binder.clearCallingIdentity();
6679 try {
6680 Phone phone = getPhone(subId);
6681 if (phone != null) {
6682 Phone defaultPhone = phone.getImsPhone();
6683 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6684 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6685 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006686 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6687 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006688 }
6689 }
Shuo Qiand8782462020-12-22 19:10:14 -08006690 } catch (ImsException e) {
6691 throw new ServiceSpecificException(e.getCode());
6692 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006693 Binder.restoreCallingIdentity(identity);
6694 }
6695 }
6696
6697 @Override
6698 public int getCallComposerStatus(int subId) {
6699 enforceReadPrivilegedPermission("getCallComposerStatus");
6700
6701 final long identity = Binder.clearCallingIdentity();
6702 try {
6703 Phone phone = getPhone(subId);
6704 if (phone != null) {
6705 Phone defaultPhone = phone.getImsPhone();
6706 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6707 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6708 return imsPhone.getCallComposerStatus();
6709 }
6710 }
6711 } finally {
6712 Binder.restoreCallingIdentity(identity);
6713 }
6714 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6715 }
6716
6717 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006718 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6719 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006720 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006721 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006723 final long identity = Binder.clearCallingIdentity();
6724 try {
6725 final String iccId = getIccId(subId);
6726 final Phone phone = getPhone(subId);
6727 if (phone == null) {
6728 return false;
6729 }
6730 final String subscriberId = phone.getSubscriberId();
6731
6732 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006733 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006734 + subscriberId + " to " + number);
6735 }
6736
6737 if (TextUtils.isEmpty(iccId)) {
6738 return false;
6739 }
6740
6741 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6742
6743 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6744 if (alphaTag == null) {
6745 editor.remove(alphaTagPrefKey);
6746 } else {
6747 editor.putString(alphaTagPrefKey, alphaTag);
6748 }
6749
6750 // Record both the line number and IMSI for this ICCID, since we need to
6751 // track all merged IMSIs based on line number
6752 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6753 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6754 if (number == null) {
6755 editor.remove(numberPrefKey);
6756 editor.remove(subscriberPrefKey);
6757 } else {
6758 editor.putString(numberPrefKey, number);
6759 editor.putString(subscriberPrefKey, subscriberId);
6760 }
6761
6762 editor.commit();
6763 return true;
6764 } finally {
6765 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006766 }
Derek Tan7226c842014-07-02 17:42:23 -07006767 }
6768
6769 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006770 public String getLine1NumberForDisplay(int subId, String callingPackage,
6771 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006772 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006773 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006774 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006775 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006776 return null;
6777 }
Derek Tan97ebb422014-09-05 16:55:38 -07006778
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006779 final long identity = Binder.clearCallingIdentity();
6780 try {
6781 String iccId = getIccId(subId);
6782 if (iccId != null) {
6783 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6784 if (DBG_MERGE) {
6785 log("getLine1NumberForDisplay returning "
6786 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6787 }
6788 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006789 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006790 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6791 return null;
6792 } finally {
6793 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006794 }
Derek Tan7226c842014-07-02 17:42:23 -07006795 }
6796
6797 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006798 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6799 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006800 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006801 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006802 return null;
6803 }
Derek Tan97ebb422014-09-05 16:55:38 -07006804
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805 final long identity = Binder.clearCallingIdentity();
6806 try {
6807 String iccId = getIccId(subId);
6808 if (iccId != null) {
6809 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6810 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6811 }
6812 return null;
6813 } finally {
6814 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006815 }
Derek Tan7226c842014-07-02 17:42:23 -07006816 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006817
6818 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006819 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6820 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006821 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6822 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006823 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006824 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006825 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006826 return null;
6827 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006828
Jordan Liub49b04b2019-05-06 14:45:15 -07006829 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6830 // the process, where TelephonyManager was instantiated.
6831 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006832 final long identity = Binder.clearCallingIdentity();
6833 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006834 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006835 final TelephonyManager tele = TelephonyManager.from(context);
6836 final SubscriptionManager sub = SubscriptionManager.from(context);
6837
6838 // Figure out what subscribers are currently active
6839 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006840
Jordan Liub49b04b2019-05-06 14:45:15 -07006841 // Only consider subs which match the current subId
6842 // This logic can be simplified. See b/131189269 for progress.
6843 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006844 activeSubscriberIds.add(tele.getSubscriberId(subId));
6845 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006846
6847 // First pass, find a number override for an active subscriber
6848 String mergeNumber = null;
6849 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6850 for (String key : prefs.keySet()) {
6851 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6852 final String subscriberId = (String) prefs.get(key);
6853 if (activeSubscriberIds.contains(subscriberId)) {
6854 final String iccId = key.substring(
6855 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6856 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6857 mergeNumber = (String) prefs.get(numberKey);
6858 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006859 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006860 + " for active subscriber " + subscriberId);
6861 }
6862 if (!TextUtils.isEmpty(mergeNumber)) {
6863 break;
6864 }
6865 }
6866 }
6867 }
6868
6869 // Shortcut when no active merged subscribers
6870 if (TextUtils.isEmpty(mergeNumber)) {
6871 return null;
6872 }
6873
6874 // Second pass, find all subscribers under that line override
6875 final ArraySet<String> result = new ArraySet<>();
6876 for (String key : prefs.keySet()) {
6877 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6878 final String number = (String) prefs.get(key);
6879 if (mergeNumber.equals(number)) {
6880 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6881 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6882 final String subscriberId = (String) prefs.get(subscriberKey);
6883 if (!TextUtils.isEmpty(subscriberId)) {
6884 result.add(subscriberId);
6885 }
6886 }
6887 }
6888 }
6889
6890 final String[] resultArray = result.toArray(new String[result.size()]);
6891 Arrays.sort(resultArray);
6892 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006893 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006894 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6895 }
6896 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006897 } finally {
6898 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006899 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006900 }
6901
6902 @Override
zoey chen38003472019-12-13 17:16:31 +08006903 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6904 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006905
6906 final long identity = Binder.clearCallingIdentity();
6907 try {
6908 final TelephonyManager telephonyManager = mApp.getSystemService(
6909 TelephonyManager.class);
6910 String subscriberId = telephonyManager.getSubscriberId(subId);
6911 if (subscriberId == null) {
6912 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006913 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006914 + subId);
6915 }
6916 return null;
6917 }
6918
6919 final SubscriptionInfo info = SubscriptionController.getInstance()
6920 .getSubscriptionInfo(subId);
6921 final ParcelUuid groupUuid = info.getGroupUuid();
6922 // If it doesn't belong to any group, return just subscriberId of itself.
6923 if (groupUuid == null) {
6924 return new String[]{subscriberId};
6925 }
6926
6927 // Get all subscriberIds from the group.
6928 final List<String> mergedSubscriberIds = new ArrayList<>();
6929 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006930 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006931 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006932 for (SubscriptionInfo subInfo : groupInfos) {
6933 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6934 if (subscriberId != null) {
6935 mergedSubscriberIds.add(subscriberId);
6936 }
6937 }
6938
6939 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6940 } finally {
6941 Binder.restoreCallingIdentity(identity);
6942
6943 }
6944 }
6945
6946 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006947 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006948 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006949 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006950
6951 final long identity = Binder.clearCallingIdentity();
6952 try {
6953 final Phone phone = getPhone(subId);
6954 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6955 } finally {
6956 Binder.restoreCallingIdentity(identity);
6957 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006958 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006959
6960 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006961 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006962 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6963 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006964 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6965 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006966
6967 final long identity = Binder.clearCallingIdentity();
6968 try {
6969 final Phone phone = getPhone(subId);
6970 if (phone == null) {
6971 return false;
6972 }
6973 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6974 cdmaNonRoamingList);
6975 } finally {
6976 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006977 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006978 }
6979
6980 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006981 @Deprecated
6982 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6983 enforceModifyPermission();
6984
6985 int returnValue = 0;
6986 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006987 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006988 if(result.exception == null) {
6989 if (result.result != null) {
6990 byte[] responseData = (byte[])(result.result);
6991 if(responseData.length > oemResp.length) {
6992 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6993 responseData.length + "bytes. Buffer Size is " +
6994 oemResp.length + "bytes.");
6995 }
6996 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6997 returnValue = responseData.length;
6998 }
6999 } else {
7000 CommandException ex = (CommandException) result.exception;
7001 returnValue = ex.getCommandError().ordinal();
7002 if(returnValue > 0) returnValue *= -1;
7003 }
7004 } catch (RuntimeException e) {
7005 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7006 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7007 if(returnValue > 0) returnValue *= -1;
7008 }
7009
7010 return returnValue;
7011 }
7012
7013 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07007014 public void setRadioCapability(RadioAccessFamily[] rafs) {
7015 try {
7016 ProxyController.getInstance().setRadioCapability(rafs);
7017 } catch (RuntimeException e) {
7018 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
7019 }
7020 }
7021
7022 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007023 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007024 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007025 try {
7026 TelephonyPermissions
7027 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7028 mApp, phone.getSubId(), "getRadioAccessFamily");
7029 } catch (SecurityException e) {
7030 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7031 throw e;
7032 }
chen xub97461a2018-10-26 14:17:57 -07007033 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007034 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007035 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007037 final long identity = Binder.clearCallingIdentity();
7038 try {
chen xub97461a2018-10-26 14:17:57 -07007039 TelephonyPermissions
7040 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7041 mApp, phone.getSubId(), "getRadioAccessFamily");
7042 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007043 } finally {
7044 Binder.restoreCallingIdentity(identity);
7045 }
chen xub97461a2018-10-26 14:17:57 -07007046 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007047 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007048
7049 @Override
7050 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007051 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007052 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007053
7054 final long identity = Binder.clearCallingIdentity();
7055 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007056 ImsManager.getInstance(defaultPhone.getContext(),
7057 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007058 } finally {
7059 Binder.restoreCallingIdentity(identity);
7060 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007061 }
7062
7063 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007064 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007065 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7067 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007068 return false;
7069 }
Svet Ganovb320e182015-04-16 12:30:10 -07007070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007071 final long identity = Binder.clearCallingIdentity();
7072 try {
7073 // Check the user preference and the system-level IMS setting. Even if the user has
7074 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7075 // In the long run, we may instead need to check if there exists a connection service
7076 // which can support video calling.
7077 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007078 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 return imsManager.isVtEnabledByPlatform()
7080 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7081 && imsManager.isVtEnabledByUser();
7082 } finally {
7083 Binder.restoreCallingIdentity(identity);
7084 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007085 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007086
Andrew Leea1239f22015-03-02 17:44:07 -08007087 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007088 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7089 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007090 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007091 mApp, subId, callingPackage, callingFeatureId,
7092 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007093 return false;
7094 }
7095
7096 final long identity = Binder.clearCallingIdentity();
7097 try {
7098 CarrierConfigManager configManager =
7099 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007100 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007101 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7102 } finally {
7103 Binder.restoreCallingIdentity(identity);
7104 }
Andrew Leea1239f22015-03-02 17:44:07 -08007105 }
7106
7107 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007108 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007109 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007110 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007111 return false;
7112 }
7113
7114 final long identity = Binder.clearCallingIdentity();
7115 try {
7116 CarrierConfigManager configManager =
7117 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007118 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007119 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7120 } finally {
7121 Binder.restoreCallingIdentity(identity);
7122 }
Andrew Leea1239f22015-03-02 17:44:07 -08007123 }
7124
Andrew Lee9431b832015-03-09 18:46:45 -07007125 @Override
7126 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007127 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007128 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007129 }
7130
7131 @Override
7132 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007133 final long identity = Binder.clearCallingIdentity();
7134 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007135 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007136 } finally {
7137 Binder.restoreCallingIdentity(identity);
7138 }
Andrew Lee9431b832015-03-09 18:46:45 -07007139 }
7140
Hall Liuf6668912018-10-31 17:05:23 -07007141 /**
7142 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7143 * support for the feature and device firmware support.
7144 *
7145 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7146 */
7147 @Override
7148 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007149 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007150 final Phone phone = getPhone(subscriptionId);
7151 if (phone == null) {
7152 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7153 return false;
7154 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007155 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007156 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007157 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7158 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007159 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007160 return isCarrierSupported && isDeviceSupported;
7161 } finally {
7162 Binder.restoreCallingIdentity(identity);
7163 }
Hall Liu98187582018-01-22 19:15:32 -08007164 }
7165
Hall Liuf6668912018-10-31 17:05:23 -07007166 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007167 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7168 * RTT setting, will return true if the device and carrier both support RTT.
7169 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007170 */
7171 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007172 final long identity = Binder.clearCallingIdentity();
7173 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007174 boolean isRttSupported = isRttSupported(subscriptionId);
7175 boolean isUserRttSettingOn = Settings.Secure.getInt(
7176 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7177 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7178 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7179 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007180 } finally {
7181 Binder.restoreCallingIdentity(identity);
7182 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007183 }
7184
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007185 @Deprecated
7186 @Override
7187 public String getDeviceId(String callingPackage) {
7188 return getDeviceIdWithFeature(callingPackage, null);
7189 }
7190
Sanket Padawe7310cc72015-01-14 09:53:20 -08007191 /**
7192 * Returns the unique device ID of phone, for example, the IMEI for
7193 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7194 *
7195 * <p>Requires Permission:
7196 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7197 */
7198 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007199 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007200 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007201 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007202 return null;
7203 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007204 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007205 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007206 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007207 return null;
7208 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007209
7210 final long identity = Binder.clearCallingIdentity();
7211 try {
7212 return phone.getDeviceId();
7213 } finally {
7214 Binder.restoreCallingIdentity(identity);
7215 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007216 }
7217
Ping Sunc67b7c22016-03-02 19:16:45 +08007218 /**
7219 * {@hide}
7220 * Returns the IMS Registration Status on a particular subid
7221 *
7222 * @param subId
7223 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007224 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007225 Phone phone = getPhone(subId);
7226 if (phone != null) {
7227 return phone.isImsRegistered();
7228 } else {
7229 return false;
7230 }
7231 }
7232
Santos Cordon7a1885b2015-02-03 11:15:19 -08007233 @Override
7234 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235 final long identity = Binder.clearCallingIdentity();
7236 try {
7237 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7238 } finally {
7239 Binder.restoreCallingIdentity(identity);
7240 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007241 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007242
Tyler Gunnf70ed162019-04-03 15:28:53 -07007243 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007244 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007245 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007246 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007247 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007248 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7249 }
7250 final long identity = Binder.clearCallingIdentity();
7251 try {
7252 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7253 } finally {
7254 Binder.restoreCallingIdentity(identity);
7255 }
7256 }
7257
7258 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007259 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007260 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7261 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007262 final long identity = Binder.clearCallingIdentity();
7263 try {
7264 Phone phone = getPhone(subscriptionId);
7265 if (phone == null) {
7266 return null;
7267 }
7268 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7269 } finally {
7270 Binder.restoreCallingIdentity(identity);
7271 }
7272 }
7273
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007274 /**
7275 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007276 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007277 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007278 final long identity = Binder.clearCallingIdentity();
7279 try {
7280 Phone phone = getPhone(subId);
7281 if (phone != null) {
7282 return phone.isWifiCallingEnabled();
7283 } else {
7284 return false;
7285 }
7286 } finally {
7287 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007288 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007289 }
7290
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007291 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007292 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007293 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007294 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007295 final long identity = Binder.clearCallingIdentity();
7296 try {
7297 Phone phone = getPhone(subId);
7298 if (phone != null) {
7299 return phone.isVideoEnabled();
7300 } else {
7301 return false;
7302 }
7303 } finally {
7304 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007305 }
7306 }
7307
7308 /**
7309 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7310 * defined in {@link ImsRegistrationImplBase}.
7311 */
7312 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007313 final long identity = Binder.clearCallingIdentity();
7314 try {
7315 Phone phone = getPhone(subId);
7316 if (phone != null) {
7317 return phone.getImsRegistrationTech();
7318 } else {
7319 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7320 }
7321 } finally {
7322 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007323 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007324 }
7325
Stuart Scott8eef64f2015-04-08 15:13:54 -07007326 @Override
7327 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007328 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007329 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7330 return;
7331 }
7332
Svet Ganovcc087f82015-05-12 20:35:54 -07007333 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007334
Svet Ganovcc087f82015-05-12 20:35:54 -07007335 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007336 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7337 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007338 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007339 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007340 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007341 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007342 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7343 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007344 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007345 // There has been issues when Sms raw table somehow stores orphan
7346 // fragments. They lead to garbled message when new fragments come
7347 // in and combined with those stale ones. In case this happens again,
7348 // user can reset all network settings which will clean up this table.
7349 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007350 // Clean up IMS settings as well here.
7351 int slotId = getSlotIndex(subId);
7352 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7353 ImsManager.getInstance(mApp, slotId).factoryReset();
7354 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007355
7356 // Erase modem config if erase modem on network setting is enabled.
7357 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7358 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7359 if (configValue != null && Boolean.parseBoolean(configValue)) {
7360 sendEraseModemConfig(getDefaultPhone());
7361 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007362 } finally {
7363 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007364 }
7365 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007366
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007367 private void cleanUpSmsRawTable(Context context) {
7368 ContentResolver resolver = context.getContentResolver();
7369 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7370 resolver.delete(uri, null, null);
7371 }
7372
Narayan Kamath1c496c22015-04-16 14:40:19 +01007373 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007374 public String getSimLocaleForSubscriber(int subId) {
7375 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7376 final Phone phone = getPhone(subId);
7377 if (phone == null) {
7378 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007379 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007380 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007381 final long identity = Binder.clearCallingIdentity();
7382 try {
chen xu5d3637b2019-01-21 23:31:38 -08007383 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007384 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007385 if (info == null) {
7386 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7387 return null;
7388 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 // Try and fetch the locale from the carrier properties or from the SIM language
7390 // preferences (EF-PL and EF-LI)...
7391 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007392 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007393 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7394 if (localeFromDefaultSim != null) {
7395 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7396 if (DBG) log("Using locale from subId: " + subId + " locale: "
7397 + localeFromDefaultSim);
7398 return localeFromDefaultSim.toLanguageTag();
7399 } else {
7400 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007401 }
7402 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007403
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007404 // The SIM language preferences only store a language (e.g. fr = French), not an
7405 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7406 // the SIM and carrier preferences does not include a country we add the country
7407 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007408 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007409 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007410 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007411 return mccLocale.toLanguageTag();
7412 }
7413
7414 if (DBG) log("No locale found - returning null");
7415 return null;
7416 } finally {
7417 Binder.restoreCallingIdentity(identity);
7418 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007419 }
7420
7421 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007422 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007423 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007424 }
7425
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007426 /**
7427 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7428 */
7429 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007430 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007431 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007432 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007433
Chenjie Yu1ba97252018-01-11 18:16:20 -08007434 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007435 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007436
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007437 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007438 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7439 * representing the state of the modem.
7440 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007441 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7442 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007443 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007444 */
7445 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007446 public void requestModemActivityInfo(ResultReceiver result) {
7447 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007448 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007449
7450 final long identity = Binder.clearCallingIdentity();
7451 try {
sqian1a1be542020-03-05 11:37:28 -08007452 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007453 } finally {
7454 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007455 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007456 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007457
Siddharth Rayb8114062018-06-17 15:02:38 -07007458 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7459 // less than total activity duration.
7460 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7461 if (info == null) {
7462 return false;
7463 }
7464 int activityDurationMs =
7465 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7466 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007467 int[] txTimeMs = info.getTransmitTimeMillis();
7468 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7469 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007470 }
7471 return (info.isValid()
7472 && (info.getSleepTimeMillis() <= activityDurationMs)
7473 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007474 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007475 && (totalTxTimeMs <= activityDurationMs));
7476 }
7477
Jack Yu85bd38a2015-11-09 11:34:32 -08007478 /**
7479 * {@hide}
7480 * Returns the service state information on specified subscription.
7481 */
7482 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007483 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7484 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007485 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007486 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007487 return null;
7488 }
7489
Hall Liuf19c44f2018-11-27 14:38:17 -08007490 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7491 LocationAccessPolicy.checkLocationPermission(mApp,
7492 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7493 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007494 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007495 .setCallingPid(Binder.getCallingPid())
7496 .setCallingUid(Binder.getCallingUid())
7497 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007498 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007499 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7500 .build());
7501
7502 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7503 LocationAccessPolicy.checkLocationPermission(mApp,
7504 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7505 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007506 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007507 .setCallingPid(Binder.getCallingPid())
7508 .setCallingUid(Binder.getCallingUid())
7509 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007510 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007511 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7512 .build());
7513 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7514 boolean hasFinePermission =
7515 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7516 boolean hasCoarsePermission =
7517 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7518
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007519 final long identity = Binder.clearCallingIdentity();
7520 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007521 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7522 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7523 Rlog.d(LOG_TAG,
7524 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7525 return null;
7526 }
7527
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 final Phone phone = getPhone(subId);
7529 if (phone == null) {
7530 return null;
7531 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007532
Hall Liuf19c44f2018-11-27 14:38:17 -08007533 ServiceState ss = phone.getServiceState();
7534
7535 // Scrub out the location info in ServiceState depending on what level of access
7536 // the caller has.
7537 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007538 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7539 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007540 } finally {
7541 Binder.restoreCallingIdentity(identity);
7542 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007543 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007544
7545 /**
7546 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7547 *
7548 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7549 * voicemail ringtone.
7550 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7551 * PhoneAccount.
7552 */
7553 @Override
7554 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007555 final long identity = Binder.clearCallingIdentity();
7556 try {
7557 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7558 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007559 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007560 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007561
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007562 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7563 } finally {
7564 Binder.restoreCallingIdentity(identity);
7565 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007566 }
7567
7568 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007569 * Sets the per-account voicemail ringtone.
7570 *
7571 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7572 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7573 *
7574 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7575 * voicemail ringtone.
7576 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7577 * PhoneAccount.
7578 */
7579 @Override
7580 public void setVoicemailRingtoneUri(String callingPackage,
7581 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007582 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007583 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007584 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7585 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7587 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7588 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007589 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007590
7591 final long identity = Binder.clearCallingIdentity();
7592 try {
7593 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7594 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007595 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007596 }
7597 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7598 } finally {
7599 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007600 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007601 }
7602
7603 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007604 * Returns whether vibration is set for voicemail notification in Phone settings.
7605 *
7606 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7607 * voicemail vibration setting.
7608 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7609 */
7610 @Override
7611 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007612 final long identity = Binder.clearCallingIdentity();
7613 try {
7614 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7615 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007616 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007617 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007619 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7620 } finally {
7621 Binder.restoreCallingIdentity(identity);
7622 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007623 }
7624
Youhan Wange64578a2016-05-02 15:32:42 -07007625 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007626 * Sets the per-account voicemail vibration.
7627 *
7628 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7629 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7630 *
7631 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7632 * voicemail vibration setting.
7633 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7634 * specific PhoneAccount.
7635 */
7636 @Override
7637 public void setVoicemailVibrationEnabled(String callingPackage,
7638 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007639 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007640 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007641 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7642 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7644 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7645 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007646 }
7647
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007648 final long identity = Binder.clearCallingIdentity();
7649 try {
7650 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7651 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007652 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007653 }
7654 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7655 } finally {
7656 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007657 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007658 }
7659
7660 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007661 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7662 *
7663 * @throws SecurityException if the caller does not have the required permission
7664 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007665 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007666 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007667 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007668 }
7669
7670 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007671 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7672 * permission.
7673 *
7674 * @throws SecurityException if the caller does not have the required permission
7675 */
7676 private void enforceSendSmsPermission() {
7677 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7678 }
7679
7680 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007681 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007682 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007683 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007684 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007685 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007686 final long identity = Binder.clearCallingIdentity();
7687 try {
7688 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007689 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690 if (componentName == null) {
7691 throw new SecurityException(
7692 "Caller not current active visual voicemail package[null]");
7693 }
7694 String vvmPackage = componentName.getPackageName();
7695 if (!callingPackage.equals(vvmPackage)) {
7696 throw new SecurityException("Caller not current active visual voicemail package["
7697 + vvmPackage + "]");
7698 }
7699 } finally {
7700 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007701 }
7702 }
7703
7704 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007705 * Return the application ID for the app type.
7706 *
7707 * @param subId the subscription ID that this request applies to.
7708 * @param appType the uicc app type.
7709 * @return Application ID for specificied app type, or null if no uicc.
7710 */
7711 @Override
7712 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007713 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007714 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007715
7716 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007717 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007718 if (phone == null) {
7719 return null;
7720 }
7721 String aid = null;
7722 try {
7723 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7724 .getApplicationByType(appType).getAid();
7725 } catch (Exception e) {
7726 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7727 }
7728 return aid;
7729 } finally {
7730 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007731 }
Youhan Wange64578a2016-05-02 15:32:42 -07007732 }
7733
Youhan Wang4001d252016-05-11 10:29:41 -07007734 /**
7735 * Return the Electronic Serial Number.
7736 *
7737 * @param subId the subscription ID that this request applies to.
7738 * @return ESN or null if error.
7739 */
7740 @Override
7741 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007742 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007743 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007744
7745 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007746 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007747 if (phone == null) {
7748 return null;
7749 }
7750 String esn = null;
7751 try {
7752 esn = phone.getEsn();
7753 } catch (Exception e) {
7754 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7755 }
7756 return esn;
7757 } finally {
7758 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007759 }
Youhan Wang4001d252016-05-11 10:29:41 -07007760 }
7761
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007762 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007763 * Return the Preferred Roaming List Version.
7764 *
7765 * @param subId the subscription ID that this request applies to.
7766 * @return PRLVersion or null if error.
7767 */
7768 @Override
7769 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007770 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007771 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007772
7773 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007774 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007775 if (phone == null) {
7776 return null;
7777 }
7778 String cdmaPrlVersion = null;
7779 try {
7780 cdmaPrlVersion = phone.getCdmaPrlVersion();
7781 } catch (Exception e) {
7782 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7783 }
7784 return cdmaPrlVersion;
7785 } finally {
7786 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007787 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007788 }
7789
7790 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007791 * Get snapshot of Telephony histograms
7792 * @return List of Telephony histograms
7793 * @hide
7794 */
7795 @Override
7796 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007797 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7798 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007799
7800 final long identity = Binder.clearCallingIdentity();
7801 try {
7802 return RIL.getTelephonyRILTimingHistograms();
7803 } finally {
7804 Binder.restoreCallingIdentity(identity);
7805 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007806 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007807
7808 /**
7809 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007810 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7811 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007812 * Require system privileges. In the future we may add this to carrier APIs.
7813 *
Michele Berionne482f8202018-11-27 18:57:59 -08007814 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007815 */
7816 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007817 @TelephonyManager.SetCarrierRestrictionResult
7818 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007819 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007820 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007821
Michele Berionne482f8202018-11-27 18:57:59 -08007822 if (carrierRestrictionRules == null) {
7823 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007824 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007826 final long identity = Binder.clearCallingIdentity();
7827 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007828 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007829 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007830 } finally {
7831 Binder.restoreCallingIdentity(identity);
7832 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007833 }
7834
7835 /**
7836 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007837 * Get the allowed carrier list and the excluded carrier list, including the priority between
7838 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007839 * Require system privileges. In the future we may add this to carrier APIs.
7840 *
Michele Berionne482f8202018-11-27 18:57:59 -08007841 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007842 */
7843 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007844 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007845 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007846 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007847
7848 final long identity = Binder.clearCallingIdentity();
7849 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007850 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7851 if (response instanceof CarrierRestrictionRules) {
7852 return (CarrierRestrictionRules) response;
7853 }
7854 // Response is an Exception of some kind,
7855 // which is signalled to the user as a NULL retval
7856 return null;
7857 } catch (Exception e) {
7858 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7859 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007860 } finally {
7861 Binder.restoreCallingIdentity(identity);
7862 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007863 }
7864
fionaxu59545b42016-05-25 15:53:37 -07007865 /**
fionaxu59545b42016-05-25 15:53:37 -07007866 * Action set from carrier signalling broadcast receivers to enable/disable radio
7867 * @param subId the subscription ID that this action applies to.
7868 * @param enabled control enable or disable radio.
7869 * {@hide}
7870 */
7871 @Override
7872 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7873 enforceModifyPermission();
7874 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007875
7876 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007877 if (phone == null) {
7878 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7879 return;
7880 }
7881 try {
7882 phone.carrierActionSetRadioEnabled(enabled);
7883 } catch (Exception e) {
7884 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007885 } finally {
7886 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007887 }
7888 }
7889
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007890 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007891 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7892 * network status based on which carrier apps could apply actions accordingly,
7893 * enable/disable default url handler for example.
7894 *
7895 * @param subId the subscription ID that this action applies to.
7896 * @param report control start/stop reporting the default network status.
7897 * {@hide}
7898 */
7899 @Override
7900 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7901 enforceModifyPermission();
7902 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007903
7904 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007905 if (phone == null) {
7906 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7907 return;
7908 }
7909 try {
7910 phone.carrierActionReportDefaultNetworkStatus(report);
7911 } catch (Exception e) {
7912 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007913 } finally {
7914 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007915 }
7916 }
7917
7918 /**
fionaxud9622282017-07-17 17:51:30 -07007919 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7920 * @param subId the subscription ID that this action applies to.
7921 * {@hide}
7922 */
7923 @Override
7924 public void carrierActionResetAll(int subId) {
7925 enforceModifyPermission();
7926 final Phone phone = getPhone(subId);
7927 if (phone == null) {
7928 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7929 return;
7930 }
7931 try {
7932 phone.carrierActionResetAll();
7933 } catch (Exception e) {
7934 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7935 }
7936 }
7937
7938 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007939 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7940 * bug report is being generated.
7941 */
7942 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007943 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007944 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7945 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007946 writer.println("Permission Denial: can't dump Phone from pid="
7947 + Binder.getCallingPid()
7948 + ", uid=" + Binder.getCallingUid()
7949 + "without permission "
7950 + android.Manifest.permission.DUMP);
7951 return;
7952 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007953 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007954 }
Jack Yueb89b242016-06-22 13:27:47 -07007955
Brad Ebingerdac2f002018-04-03 15:17:52 -07007956 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007957 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7958 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7959 @NonNull String[] args) {
7960 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7961 this, in.getFileDescriptor(), out.getFileDescriptor(),
7962 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007963 }
7964
Jack Yueb89b242016-06-22 13:27:47 -07007965 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007966 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007967 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007968 * @param reason the reason the data enable change is taking place
7969 * @param enabled True if enabling the data, otherwise disabling.
7970 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007971 */
7972 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007973 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007974 boolean enabled) {
7975 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7976 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7977 try {
7978 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007979 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007980 } catch (SecurityException se) {
7981 enforceModifyPermission();
7982 }
7983 } else {
7984 enforceModifyPermission();
7985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007986
7987 final long identity = Binder.clearCallingIdentity();
7988 try {
7989 Phone phone = getPhone(subId);
7990 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007991 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7992 phone.carrierActionSetMeteredApnsEnabled(enabled);
7993 } else {
7994 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007996 }
7997 } finally {
7998 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007999 }
8000 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008001
8002 /**
8003 * Get Client request stats
8004 * @return List of Client Request Stats
8005 * @hide
8006 */
8007 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008008 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8009 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008010 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008011 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008012 return null;
8013 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008014 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008016 final long identity = Binder.clearCallingIdentity();
8017 try {
8018 if (phone != null) {
8019 return phone.getClientRequestStats();
8020 }
8021
8022 return null;
8023 } finally {
8024 Binder.restoreCallingIdentity(identity);
8025 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008026 }
8027
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008028 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008029 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008030 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008031 }
Jack Yueb4124c2017-02-16 15:32:43 -08008032
8033 /**
Grace Chen70990072017-03-24 17:21:30 -07008034 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008035 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008036 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008037 * @param state State of SIM (power down, power up, pass through)
8038 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8039 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8040 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008041 *
8042 **/
8043 @Override
Grace Chen70990072017-03-24 17:21:30 -07008044 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008045 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008046 Phone phone = PhoneFactory.getPhone(slotIndex);
8047
vagdeviaf9a5b92018-08-15 16:01:53 -07008048 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8049
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008050 final long identity = Binder.clearCallingIdentity();
8051 try {
8052 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08008053 phone.setSimPowerState(state, null, workSource);
8054 }
8055 } finally {
8056 Binder.restoreCallingIdentity(identity);
8057 }
8058 }
8059
8060 /**
8061 * Set SIM card power state.
8062 *
8063 * @param slotIndex SIM slot id.
8064 * @param state State of SIM (power down, power up, pass through)
8065 * @param callback callback to trigger after success or failure
8066 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8067 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8068 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8069 *
8070 **/
8071 @Override
8072 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8073 IIntegerConsumer callback) {
8074 enforceModifyPermission();
8075 Phone phone = PhoneFactory.getPhone(slotIndex);
8076
8077 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8078
8079 final long identity = Binder.clearCallingIdentity();
8080 try {
8081 if (phone != null) {
8082 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8083 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008084 }
8085 } finally {
8086 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008087 }
8088 }
Shuo Qiandd210312017-04-12 22:11:33 +00008089
Tyler Gunn65d45c22017-06-05 11:22:26 -07008090 private boolean isUssdApiAllowed(int subId) {
8091 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008092 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008093 if (configManager == null) {
8094 return false;
8095 }
8096 PersistableBundle pb = configManager.getConfigForSubId(subId);
8097 if (pb == null) {
8098 return false;
8099 }
8100 return pb.getBoolean(
8101 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8102 }
8103
Shuo Qiandd210312017-04-12 22:11:33 +00008104 /**
8105 * Check if phone is in emergency callback mode
8106 * @return true if phone is in emergency callback mode
8107 * @param subId sub id
8108 */
goneil9c5f4872017-12-05 14:07:56 -08008109 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008110 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008111 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008112 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008113
8114 final long identity = Binder.clearCallingIdentity();
8115 try {
8116 if (phone != null) {
8117 return phone.isInEcm();
8118 } else {
8119 return false;
8120 }
8121 } finally {
8122 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008123 }
8124 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008125
8126 /**
8127 * Get the current signal strength information for the given subscription.
8128 * Because this information is not updated when the device is in a low power state
8129 * it should not be relied-upon to be current.
8130 * @param subId Subscription index
8131 * @return the most recent cached signal strength info from the modem
8132 */
8133 @Override
8134 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008135 final long identity = Binder.clearCallingIdentity();
8136 try {
8137 Phone p = getPhone(subId);
8138 if (p == null) {
8139 return null;
8140 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008141
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008142 return p.getSignalStrength();
8143 } finally {
8144 Binder.restoreCallingIdentity(identity);
8145 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008146 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008147
Pengquan Meng77b7f132018-08-22 14:49:57 -07008148 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008149 * Get the current modem radio state for the given slot.
8150 * @param slotIndex slot index.
8151 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008152 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008153 * @return the current radio power state from the modem
8154 */
8155 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008156 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008157 Phone phone = PhoneFactory.getPhone(slotIndex);
8158 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008159 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8160 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008161 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8162 }
8163
8164 final long identity = Binder.clearCallingIdentity();
8165 try {
8166 return phone.getRadioPowerState();
8167 } finally {
8168 Binder.restoreCallingIdentity(identity);
8169 }
8170 }
8171 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8172 }
8173
8174 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008175 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8176 *
8177 * <p>Requires one of the following permissions:
8178 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8179 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8180 * privileges.
8181 *
8182 * @param subId subscription id
8183 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8184 * {@code false}.
8185 */
8186 @Override
8187 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008188 try {
8189 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8190 null);
8191 } catch (Exception e) {
8192 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8193 mApp, subId, "isDataRoamingEnabled");
8194 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008195
Pengquan Menga1bb6272018-09-06 09:59:22 -07008196 boolean isEnabled = false;
8197 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008198 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008199 Phone phone = getPhone(subId);
8200 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008201 } finally {
8202 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008203 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008204 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008205 }
8206
8207
8208 /**
8209 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8210 *
8211 * <p> Requires permission:
8212 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8213 * privileges.
8214 *
8215 * @param subId subscription id
8216 * @param isEnabled {@code true} means enable, {@code false} means disable.
8217 */
8218 @Override
8219 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8221 mApp, subId, "setDataRoamingEnabled");
8222
Pengquan Menga1bb6272018-09-06 09:59:22 -07008223 final long identity = Binder.clearCallingIdentity();
8224 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008225 Phone phone = getPhone(subId);
8226 if (phone != null) {
8227 phone.setDataRoamingEnabled(isEnabled);
8228 }
8229 } finally {
8230 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008231 }
8232 }
8233
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008234 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008235 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008236 TelephonyPermissions
8237 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008238 mApp, subId, "isManualNetworkSelectionAllowed");
8239
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008240 boolean isAllowed = true;
8241 final long identity = Binder.clearCallingIdentity();
8242 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008243 Phone phone = getPhone(subId);
8244 if (phone != null) {
8245 isAllowed = phone.isCspPlmnEnabled();
8246 }
8247 } finally {
8248 Binder.restoreCallingIdentity(identity);
8249 }
8250 return isAllowed;
8251 }
8252
8253 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008254 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008255 // Verify that tha callingPackage belongs to the calling UID
8256 mApp.getSystemService(AppOpsManager.class)
8257 .checkPackage(Binder.getCallingUid(), callingPackage);
8258
Jordan Liu1e142fc2019-04-22 15:10:43 -07008259 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008260 try {
8261 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008262 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008263 } catch (SecurityException e) {
8264 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8265 // has carrier privileges on an active UICC
8266 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8267 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008268 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008269 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008270 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008271
8272 final long identity = Binder.clearCallingIdentity();
8273 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008274 UiccController uiccController = UiccController.getInstance();
8275 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008276 if (hasReadPermission) {
8277 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008278 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008279
8280 // Remove private info if the caller doesn't have access
8281 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8282 for (UiccCardInfo cardInfo : cardInfos) {
8283 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8284 // is available
8285 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8286 if (card == null || card.getUiccProfile() == null) {
8287 // assume no access if the card or profile is unavailable
8288 filteredInfos.add(cardInfo.getUnprivileged());
8289 continue;
8290 }
8291 UiccProfile profile = card.getUiccProfile();
8292 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8293 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8294 filteredInfos.add(cardInfo);
8295 } else {
8296 filteredInfos.add(cardInfo.getUnprivileged());
8297 }
8298 }
8299 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008300 } finally {
8301 Binder.restoreCallingIdentity(identity);
8302 }
8303 }
8304
8305 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008306 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008307 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008309 final long identity = Binder.clearCallingIdentity();
8310 try {
8311 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8312 if (slots == null) {
8313 Rlog.i(LOG_TAG, "slots is null.");
8314 return null;
8315 }
8316
8317 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8318 for (int i = 0; i < slots.length; i++) {
8319 UiccSlot slot = slots[i];
8320 if (slot == null) {
8321 continue;
8322 }
8323
Jordan Liu7be7e652019-05-06 18:55:02 +00008324 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008325 UiccCard card = slot.getUiccCard();
8326 if (card != null) {
8327 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008328 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008329 cardId = slot.getEid();
8330 if (TextUtils.isEmpty(cardId)) {
8331 cardId = slot.getIccId();
8332 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008333 }
8334
Jordan Liu857451f2019-05-09 16:35:35 -07008335 if (cardId != null) {
8336 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8337 // if cardId is an EID, it's all digits so this is fine
8338 cardId = IccUtils.stripTrailingFs(cardId);
8339 }
8340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008341 int cardState = 0;
8342 switch (slot.getCardState()) {
8343 case CARDSTATE_ABSENT:
8344 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8345 break;
8346 case CARDSTATE_PRESENT:
8347 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8348 break;
8349 case CARDSTATE_ERROR:
8350 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8351 break;
8352 case CARDSTATE_RESTRICTED:
8353 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8354 break;
8355 default:
8356 break;
8357
8358 }
8359
8360 infos[i] = new UiccSlotInfo(
8361 slot.isActive(),
8362 slot.isEuicc(),
8363 cardId,
8364 cardState,
8365 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008366 slot.isExtendedApduSupported(),
8367 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008368 }
8369 return infos;
8370 } finally {
8371 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008372 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008373 }
8374
8375 @Override
8376 public boolean switchSlots(int[] physicalSlots) {
8377 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008378
8379 final long identity = Binder.clearCallingIdentity();
8380 try {
8381 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8382 } finally {
8383 Binder.restoreCallingIdentity(identity);
8384 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008385 }
Jack Yu4c988042018-02-27 15:30:01 -08008386
8387 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008388 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008389 final long identity = Binder.clearCallingIdentity();
8390 try {
8391 return UiccController.getInstance().getCardIdForDefaultEuicc();
8392 } finally {
8393 Binder.restoreCallingIdentity(identity);
8394 }
8395 }
8396
Pengquan Meng85728fb2018-03-12 16:31:21 -07008397 /**
goneil47ffb6e2018-04-06 15:40:58 -07008398 * A test API to reload the UICC profile.
8399 *
8400 * <p>Requires that the calling app has permission
8401 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8402 * @hide
8403 */
8404 @Override
8405 public void refreshUiccProfile(int subId) {
8406 enforceModifyPermission();
8407
8408 final long identity = Binder.clearCallingIdentity();
8409 try {
8410 Phone phone = getPhone(subId);
8411 if (phone == null) {
8412 return;
8413 }
8414 UiccCard uiccCard = phone.getUiccCard();
8415 if (uiccCard == null) {
8416 return;
8417 }
8418 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8419 if (uiccProfile == null) {
8420 return;
8421 }
8422 uiccProfile.refresh();
8423 } finally {
8424 Binder.restoreCallingIdentity(identity);
8425 }
8426 }
8427
8428 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008429 * Returns false if the mobile data is disabled by default, otherwise return true.
8430 */
8431 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008432 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008433 }
8434
8435 /**
8436 * Returns true if the data roaming is enabled by default, i.e the system property
8437 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8438 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8439 */
8440 private boolean getDefaultDataRoamingEnabled(int subId) {
8441 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008442 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008443 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008444 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8445 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8446 return isDataRoamingEnabled;
8447 }
8448
8449 /**
8450 * Returns the default network type for the given {@code subId}, if the default network type is
8451 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8452 */
8453 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008454 List<Integer> list = TelephonyProperties.default_network();
8455 int phoneId = mSubscriptionController.getPhoneId(subId);
8456 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8457 return list.get(phoneId);
8458 }
8459 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008460 }
fionaxua13278b2018-03-21 00:08:13 -07008461
8462 @Override
8463 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008464 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008465 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008466
8467 final long identity = Binder.clearCallingIdentity();
8468 try {
8469 final Phone phone = getPhone(subId);
8470 if (phone == null) {
8471 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8472 return;
8473 }
chen xueaba88a2019-03-15 13:15:10 -07008474 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8475 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008476 if (carrierPrivilegeRules == null) {
8477 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8478 } else {
8479 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8480 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008481 } finally {
8482 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008483 }
fionaxua13278b2018-03-21 00:08:13 -07008484 }
8485
8486 @Override
8487 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008488 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008489
8490 final long identity = Binder.clearCallingIdentity();
8491 try {
8492 final Phone phone = getPhone(subId);
8493 if (phone == null) {
8494 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8495 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8496 }
8497 return phone.getCarrierIdListVersion();
8498 } finally {
8499 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008500 }
fionaxua13278b2018-03-21 00:08:13 -07008501 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008502
8503 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008504 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8505 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008506 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008507 mApp, subId, callingPackage, callingFeatureId,
8508 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008509 return -1;
8510 }
8511
8512 final long identity = Binder.clearCallingIdentity();
8513 try {
8514 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8515 } finally {
8516 Binder.restoreCallingIdentity(identity);
8517 }
8518 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008519
8520 @Override
8521 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008522 TelephonyPermissions
8523 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008524 mApp, subId, "getCdmaRoamingMode");
8525
8526 final long identity = Binder.clearCallingIdentity();
8527 try {
8528 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8529 } finally {
8530 Binder.restoreCallingIdentity(identity);
8531 }
8532 }
8533
8534 @Override
8535 public boolean setCdmaRoamingMode(int subId, int mode) {
8536 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8537 mApp, subId, "setCdmaRoamingMode");
8538
8539 final long identity = Binder.clearCallingIdentity();
8540 try {
8541 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8542 } finally {
8543 Binder.restoreCallingIdentity(identity);
8544 }
8545 }
8546
8547 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008548 public int getCdmaSubscriptionMode(int subId) {
8549 TelephonyPermissions
8550 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8551 mApp, subId, "getCdmaSubscriptionMode");
8552
8553 final long identity = Binder.clearCallingIdentity();
8554 try {
8555 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8556 } finally {
8557 Binder.restoreCallingIdentity(identity);
8558 }
8559 }
8560
8561 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008562 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8564 mApp, subId, "setCdmaSubscriptionMode");
8565
8566 final long identity = Binder.clearCallingIdentity();
8567 try {
8568 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8569 } finally {
8570 Binder.restoreCallingIdentity(identity);
8571 }
8572 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008573
sqianc5eccab2018-10-19 18:46:41 -07008574 @Override
sqian8c685422019-02-22 15:55:18 -08008575 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008576 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008577 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008578 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8579 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008580 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8581 }
8582 final long identity = Binder.clearCallingIdentity();
8583 try {
sqian854d44b2018-12-12 16:48:18 -08008584 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8585 for (Phone phone: PhoneFactory.getPhones()) {
8586 if (phone.getEmergencyNumberTracker() != null
8587 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8588 emergencyNumberListInternal.put(
8589 phone.getSubId(),
8590 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8591 }
sqian11b7a0e2018-12-05 18:48:28 -08008592 }
sqian854d44b2018-12-12 16:48:18 -08008593 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008594 } finally {
8595 Binder.restoreCallingIdentity(identity);
8596 }
sqianc5eccab2018-10-19 18:46:41 -07008597 }
8598
8599 @Override
sqian8c685422019-02-22 15:55:18 -08008600 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008601 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008602 if (!exactMatch) {
8603 TelephonyPermissions
8604 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008605 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008606 }
8607 final long identity = Binder.clearCallingIdentity();
8608 try {
sqian854d44b2018-12-12 16:48:18 -08008609 for (Phone phone: PhoneFactory.getPhones()) {
8610 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008611 && phone.getEmergencyNumberTracker()
8612 .isEmergencyNumber(number, exactMatch)) {
8613 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008614 }
sqian11b7a0e2018-12-05 18:48:28 -08008615 }
8616 return false;
8617 } finally {
8618 Binder.restoreCallingIdentity(identity);
8619 }
8620 }
8621
sqianf4ca7ed2019-01-15 18:32:07 -08008622 /**
8623 * Update emergency number list for test mode.
8624 */
8625 @Override
8626 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8627 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8628 "updateEmergencyNumberListTestMode");
8629
8630 final long identity = Binder.clearCallingIdentity();
8631 try {
8632 for (Phone phone: PhoneFactory.getPhones()) {
8633 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8634 if (tracker != null) {
8635 tracker.executeEmergencyNumberTestModeCommand(action, num);
8636 }
8637 }
8638 } finally {
8639 Binder.restoreCallingIdentity(identity);
8640 }
8641 }
8642
8643 /**
8644 * Get the full emergency number list for test mode.
8645 */
8646 @Override
8647 public List<String> getEmergencyNumberListTestMode() {
8648 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8649 "getEmergencyNumberListTestMode");
8650
8651 final long identity = Binder.clearCallingIdentity();
8652 try {
8653 Set<String> emergencyNumbers = new HashSet<>();
8654 for (Phone phone: PhoneFactory.getPhones()) {
8655 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8656 if (tracker != null) {
8657 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8658 emergencyNumbers.add(num.getNumber());
8659 }
8660 }
8661 }
8662 return new ArrayList<>(emergencyNumbers);
8663 } finally {
8664 Binder.restoreCallingIdentity(identity);
8665 }
8666 }
8667
chen xud6b45bd2018-10-30 22:27:10 -07008668 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008669 public int getEmergencyNumberDbVersion(int subId) {
8670 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8671
8672 final long identity = Binder.clearCallingIdentity();
8673 try {
8674 final Phone phone = getPhone(subId);
8675 if (phone == null) {
8676 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8677 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8678 }
8679 return phone.getEmergencyNumberDbVersion();
8680 } finally {
8681 Binder.restoreCallingIdentity(identity);
8682 }
8683 }
8684
8685 @Override
8686 public void notifyOtaEmergencyNumberDbInstalled() {
8687 enforceModifyPermission();
8688
8689 final long identity = Binder.clearCallingIdentity();
8690 try {
8691 for (Phone phone: PhoneFactory.getPhones()) {
8692 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8693 if (tracker != null) {
8694 tracker.updateOtaEmergencyNumberDatabase();
8695 }
8696 }
8697 } finally {
8698 Binder.restoreCallingIdentity(identity);
8699 }
8700 }
8701
8702 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008703 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008704 enforceActiveEmergencySessionPermission();
8705
8706 final long identity = Binder.clearCallingIdentity();
8707 try {
8708 for (Phone phone: PhoneFactory.getPhones()) {
8709 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8710 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008711 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8712 }
8713 }
8714 } finally {
8715 Binder.restoreCallingIdentity(identity);
8716 }
8717 }
8718
8719 @Override
8720 public void resetOtaEmergencyNumberDbFilePath() {
8721 enforceActiveEmergencySessionPermission();
8722
8723 final long identity = Binder.clearCallingIdentity();
8724 try {
8725 for (Phone phone: PhoneFactory.getPhones()) {
8726 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8727 if (tracker != null) {
8728 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008729 }
8730 }
8731 } finally {
8732 Binder.restoreCallingIdentity(identity);
8733 }
8734 }
8735
8736 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008737 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8738 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8739 Phone phone = getPhone(subId);
8740 if (phone == null) {
8741 return null;
8742 }
8743 final long identity = Binder.clearCallingIdentity();
8744 try {
8745 UiccProfile profile = UiccController.getInstance()
8746 .getUiccProfileForPhone(phone.getPhoneId());
8747 if (profile != null) {
8748 return profile.getCertsFromCarrierPrivilegeAccessRules();
8749 }
8750 } finally {
8751 Binder.restoreCallingIdentity(identity);
8752 }
8753 return null;
8754 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008755
8756 /**
8757 * Enable or disable a modem stack.
8758 */
8759 @Override
8760 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8761 enforceModifyPermission();
8762
8763 final long identity = Binder.clearCallingIdentity();
8764 try {
8765 Phone phone = PhoneFactory.getPhone(slotIndex);
8766 if (phone == null) {
8767 return false;
8768 } else {
8769 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8770 }
8771 } finally {
8772 Binder.restoreCallingIdentity(identity);
8773 }
8774 }
Michelecea4cf22018-12-21 15:00:11 -08008775
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008776 /**
8777 * Whether a modem stack is enabled or not.
8778 */
8779 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008780 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8781 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008782 Phone phone = PhoneFactory.getPhone(slotIndex);
8783 if (phone == null) return false;
8784
8785 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008786 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8787 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008788 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8789 }
8790
8791 final long identity = Binder.clearCallingIdentity();
8792 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008793 try {
8794 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8795 } catch (NoSuchElementException ex) {
8796 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8797 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008798 } finally {
8799 Binder.restoreCallingIdentity(identity);
8800 }
8801 }
8802
Michelecea4cf22018-12-21 15:00:11 -08008803 @Override
Michele0ea7d782019-03-19 14:58:42 -07008804 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008805 enforceModifyPermission();
8806
8807 final long identity = Binder.clearCallingIdentity();
8808 try {
8809 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008810 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008811 .commit();
8812 } finally {
8813 Binder.restoreCallingIdentity(identity);
8814 }
8815 }
8816
8817 @Override
Michele0ea7d782019-03-19 14:58:42 -07008818 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008819 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008820 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008821 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8822 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008823 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008824 }
Michelecea4cf22018-12-21 15:00:11 -08008825
8826 final long identity = Binder.clearCallingIdentity();
8827 try {
Michele0ea7d782019-03-19 14:58:42 -07008828 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008829 } finally {
8830 Binder.restoreCallingIdentity(identity);
8831 }
8832 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008833
Michele0ea7d782019-03-19 14:58:42 -07008834 @TelephonyManager.IsMultiSimSupportedResult
8835 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008836 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8837 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8838 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008839 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8840 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008841 }
8842 // Check if the hardware supports multisim functionality. If usage of multisim is not
8843 // supported by the modem, indicate that it is restricted.
8844 PhoneCapability staticCapability =
8845 mPhoneConfigurationManager.getStaticPhoneCapability();
8846 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008847 loge("isMultiSimSupportedInternal: no static configuration available");
8848 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008849 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008850 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008851 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8852 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008853 }
8854 // Check if support of multiple SIMs is restricted by carrier
8855 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008856 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008857 }
8858
Michele0ea7d782019-03-19 14:58:42 -07008859 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008860 }
8861
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008862 /**
8863 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008864 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8865 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8866 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008867 * @param numOfSims number of active sims we want to switch to
8868 */
8869 @Override
8870 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008871 if (numOfSims == 1) {
8872 enforceModifyPermission();
8873 } else {
8874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8875 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8876 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008877 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008878
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008879 try {
Michele30b57b22019-03-01 12:01:14 -08008880 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008881 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008882 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8883 return;
8884 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008885 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8886 } finally {
8887 Binder.restoreCallingIdentity(identity);
8888 }
8889 }
8890
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008891 @Override
8892 public boolean isApplicationOnUicc(int subId, int appType) {
8893 enforceReadPrivilegedPermission("isApplicationOnUicc");
8894 Phone phone = getPhone(subId);
8895 if (phone == null) {
8896 return false;
8897 }
8898 final long identity = Binder.clearCallingIdentity();
8899 try {
8900 UiccCard uiccCard = phone.getUiccCard();
8901 if (uiccCard == null) {
8902 return false;
8903 }
8904 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8905 if (uiccProfile == null) {
8906 return false;
8907 }
8908 if (TelephonyManager.APPTYPE_SIM <= appType
8909 && appType <= TelephonyManager.APPTYPE_ISIM) {
8910 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8911 }
8912 return false;
8913 } finally {
8914 Binder.restoreCallingIdentity(identity);
8915 }
8916 }
8917
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008918 /**
chen xub4baa772019-04-03 10:23:41 -07008919 * Get whether making changes to modem configurations will trigger reboot.
8920 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008921 */
8922 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008923 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8924 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008925 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008926 mApp, subId, callingPackage, callingFeatureId,
8927 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008928 return false;
8929 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008930 final long identity = Binder.clearCallingIdentity();
8931 try {
8932 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8933 } finally {
8934 Binder.restoreCallingIdentity(identity);
8935 }
8936 }
8937
Nathan Harold29f5f052019-02-15 13:41:57 -08008938 private void updateModemStateMetrics() {
8939 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8940 // TODO: check the state for each modem if the api is ready.
8941 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8942 }
8943
Pengquan Meng3889a572019-01-23 11:16:29 -08008944 @Override
8945 public int[] getSlotsMapping() {
8946 enforceReadPrivilegedPermission("getSlotsMapping");
8947
8948 final long identity = Binder.clearCallingIdentity();
8949 try {
8950 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8951 // All logical slots should have a mapping to a physical slot.
8952 int[] logicalSlotsMapping = new int[phoneCount];
8953 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8954 for (int i = 0; i < slotInfos.length; i++) {
8955 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8956 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8957 }
8958 }
8959 return logicalSlotsMapping;
8960 } finally {
8961 Binder.restoreCallingIdentity(identity);
8962 }
8963 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008964
8965 /**
8966 * Get the IRadio HAL Version
8967 */
8968 @Override
8969 public int getRadioHalVersion() {
8970 Phone phone = getDefaultPhone();
8971 if (phone == null) return -1;
8972 HalVersion hv = phone.getHalVersion();
8973 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8974 return hv.major * 100 + hv.minor;
8975 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008976
8977 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008978 * Get the current calling package name.
8979 * @return the current calling package name
8980 */
8981 @Override
8982 public String getCurrentPackageName() {
8983 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8984 }
8985
8986 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008987 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8988 * corresponding network requests on a subId.
8989 *
8990 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008991 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008992 * 2) APN is un-metered for this subscription, or
8993 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008994 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008995 *
8996 * @return whether data is allowed for a apn type.
8997 *
8998 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008999 */
9000 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009001 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07009002 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9003 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009004
9005 // Now that all security checks passes, perform the operation as ourselves.
9006 final long identity = Binder.clearCallingIdentity();
9007 try {
9008 Phone phone = getPhone(subId);
9009 if (phone == null) return false;
9010
Jack Yu41407ee2019-05-13 16:54:09 -07009011 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009012 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9013 } finally {
9014 Binder.restoreCallingIdentity(identity);
9015 }
9016 }
9017
9018 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009019 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009020 enforceReadPrivilegedPermission("isApnMetered");
9021
9022 // Now that all security checks passes, perform the operation as ourselves.
9023 final long identity = Binder.clearCallingIdentity();
9024 try {
9025 Phone phone = getPhone(subId);
9026 if (phone == null) return true; // By default return true.
9027
Jack Yu41407ee2019-05-13 16:54:09 -07009028 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009029 } finally {
9030 Binder.restoreCallingIdentity(identity);
9031 }
9032 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009033
9034 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08009035 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9036 int subscriptionId, IBooleanConsumer resultCallback) {
9037 enforceModifyPermission();
9038 long token = Binder.clearCallingIdentity();
9039 try {
9040 Phone phone = getPhone(subscriptionId);
9041 if (phone == null) {
9042 try {
9043 if (resultCallback != null) {
9044 resultCallback.accept(false);
9045 }
9046 } catch (RemoteException e) {
9047 // ignore
9048 }
9049 return;
9050 }
9051 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9052 Pair.create(specifiers, (x) -> {
9053 try {
9054 if (resultCallback != null) {
9055 resultCallback.accept(x);
9056 }
9057 } catch (RemoteException e) {
9058 // ignore
9059 }
9060 });
9061 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9062 } finally {
9063 Binder.restoreCallingIdentity(token);
9064 }
9065 }
9066
9067 @Override
Sarah Chincc055732020-11-18 13:39:35 -08009068 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9069 TelephonyPermissions
9070 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9071 mApp, subId, "getSystemSelectionChannels");
9072 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9073 final long identity = Binder.clearCallingIdentity();
9074 try {
9075 List<RadioAccessSpecifier> specifiers =
9076 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9077 null, subId, workSource);
9078 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9079 return specifiers;
9080 } finally {
9081 Binder.restoreCallingIdentity(identity);
9082 }
9083 }
9084
9085 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009086 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009087 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009088 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9089 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9090 if (iccRecords == null) {
9091 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9092 return false;
9093 }
9094 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9095 }
9096
9097 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009098 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9099 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009100 if (callingPackage == null) {
9101 callingPackage = getCurrentPackageName();
9102 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009103 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9104 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009105 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9106 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009107 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9108 }
9109 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9110 Intent intent = new Intent();
9111 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9112 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9113 // Bring up choose default SMS subscription dialog right now
9114 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9115 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9116 mApp.startActivity(intent);
9117 }
chen xud5ca2d52019-05-28 15:20:57 -07009118
9119 @Override
9120 public String getMmsUAProfUrl(int subId) {
9121 //TODO investigate if this API should require proper permission check in R b/133791609
9122 final long identity = Binder.clearCallingIdentity();
9123 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009124 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9125 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9126 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9127 return carrierUAProfUrl;
9128 }
chen xud5ca2d52019-05-28 15:20:57 -07009129 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9130 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9131 } finally {
9132 Binder.restoreCallingIdentity(identity);
9133 }
9134 }
9135
9136 @Override
9137 public String getMmsUserAgent(int subId) {
9138 //TODO investigate if this API should require proper permission check in R b/133791609
9139 final long identity = Binder.clearCallingIdentity();
9140 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009141 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9142 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9143 if (!TextUtils.isEmpty(carrierUserAgent)) {
9144 return carrierUserAgent;
9145 }
chen xud5ca2d52019-05-28 15:20:57 -07009146 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9147 .getString(com.android.internal.R.string.config_mms_user_agent);
9148 } finally {
9149 Binder.restoreCallingIdentity(identity);
9150 }
9151 }
Jack Yub07d4972019-05-28 16:12:25 -07009152
9153 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009154 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9155 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9156
9157 final long identity = Binder.clearCallingIdentity();
9158 try {
9159 Phone phone = getPhone(subscriptionId);
9160 if (phone == null) return false;
9161
9162 switch (policy) {
9163 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9164 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9165 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9166 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9167 default:
9168 throw new IllegalArgumentException(policy + " is not a valid policy");
9169 }
9170 } finally {
9171 Binder.restoreCallingIdentity(identity);
9172 }
9173 }
9174
9175 @Override
9176 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9177 boolean enabled) {
9178 enforceModifyPermission();
9179
9180 final long identity = Binder.clearCallingIdentity();
9181 try {
9182 Phone phone = getPhone(subscriptionId);
9183 if (phone == null) return;
9184
9185 switch (policy) {
9186 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9187 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9188 break;
9189 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9190 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9191 break;
9192 default:
9193 throw new IllegalArgumentException(policy + " is not a valid policy");
9194 }
9195 } finally {
9196 Binder.restoreCallingIdentity(identity);
9197 }
9198 }
9199
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009200 /**
Hall Liub48cf452020-09-25 11:13:49 -07009201 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009202 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9203 * otherwise.
9204 */
9205 @Override
9206 public void setCepEnabled(boolean isCepEnabled) {
9207 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9208
9209 final long identity = Binder.clearCallingIdentity();
9210 try {
9211 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9212 for (Phone phone : PhoneFactory.getPhones()) {
9213 Phone defaultPhone = phone.getImsPhone();
9214 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9215 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9216 ImsPhoneCallTracker imsPhoneCallTracker =
9217 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9218 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9219 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9220 + imsPhone.getMsisdn());
9221 }
9222 }
9223 } finally {
9224 Binder.restoreCallingIdentity(identity);
9225 }
9226 }
allenwtsu46dcc572020-01-08 18:24:03 +08009227
9228 /**
9229 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9230 *
9231 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9232 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9233 * before being read.
9234 */
9235 @Override
9236 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9237 isCompressed) {
9238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9239 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009240 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9241 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9242 }
9243 if (!isImsAvailableOnDevice()) {
9244 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9245 "IMS not available on device.");
9246 }
9247
9248 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009249 try {
Hui Wang068ab862020-10-31 05:12:53 +00009250 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9251 } finally {
9252 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009253 }
9254 }
zoey chenf95ca592019-12-30 16:11:23 +08009255
9256 @Override
9257 public boolean isIccLockEnabled(int subId) {
9258 enforceReadPrivilegedPermission("isIccLockEnabled");
9259
9260 // Now that all security checks passes, perform the operation as ourselves.
9261 final long identity = Binder.clearCallingIdentity();
9262 try {
9263 Phone phone = getPhone(subId);
9264 if (phone != null && phone.getIccCard() != null) {
9265 return phone.getIccCard().getIccLockEnabled();
9266 } else {
9267 return false;
9268 }
9269 } finally {
9270 Binder.restoreCallingIdentity(identity);
9271 }
9272 }
9273
9274 /**
zoey chene02881a2019-12-30 16:11:23 +08009275 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009276 *
zoey chene02881a2019-12-30 16:11:23 +08009277 * @return an integer representing the status of IccLock enabled or disabled in the following
9278 * three cases:
9279 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9280 * successfully.
9281 * - Positive number and zero for remaining password attempts.
9282 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009283 *
9284 */
9285 @Override
9286 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9287 enforceModifyPermission();
9288
9289 Phone phone = getPhone(subId);
9290 if (phone == null) {
9291 return 0;
9292 }
9293 // Now that all security checks passes, perform the operation as ourselves.
9294 final long identity = Binder.clearCallingIdentity();
9295 try {
9296 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9297 new Pair<Boolean, String>(enabled, password), phone, null);
9298 return attemptsRemaining;
9299
9300 } catch (Exception e) {
9301 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9302 } finally {
9303 Binder.restoreCallingIdentity(identity);
9304 }
9305 return 0;
9306 }
9307
9308 /**
9309 * Change the ICC password used in ICC pin lock.
9310 *
zoey chene02881a2019-12-30 16:11:23 +08009311 * @return an integer representing the status of IccLock changed in the following three cases:
9312 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9313 * - Positive number and zero for remaining password attempts.
9314 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009315 *
9316 */
9317 @Override
9318 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9319 enforceModifyPermission();
9320
9321 Phone phone = getPhone(subId);
9322 if (phone == null) {
9323 return 0;
9324 }
9325 // Now that all security checks passes, perform the operation as ourselves.
9326 final long identity = Binder.clearCallingIdentity();
9327 try {
9328 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9329 new Pair<String, String>(oldPassword, newPassword), phone, null);
9330 return attemptsRemaining;
9331
9332 } catch (Exception e) {
9333 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9334 } finally {
9335 Binder.restoreCallingIdentity(identity);
9336 }
9337 return 0;
9338 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009339
Peter Wangdafb9ac2020-01-15 14:13:38 -08009340 /**
9341 * Request for receiving user activity notification
9342 */
9343 @Override
9344 public void requestUserActivityNotification() {
9345 if (!mNotifyUserActivity.get()
9346 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9347 mNotifyUserActivity.set(true);
9348 }
9349 }
9350
9351 /**
9352 * Called when userActivity is signalled in the power manager.
9353 * This is safe to call from any thread, with any window manager locks held or not.
9354 */
9355 @Override
9356 public void userActivity() {
9357 // ***************************************
9358 // * Inherited from PhoneWindowManager *
9359 // ***************************************
9360 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9361 // WITH ITS LOCKS HELD.
9362 //
9363 // This code must be VERY careful about the locks
9364 // it acquires.
9365 // In fact, the current code acquires way too many,
9366 // and probably has lurking deadlocks.
9367
9368 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9369 throw new SecurityException("Only the OS may call notifyUserActivity()");
9370 }
9371
9372 if (mNotifyUserActivity.getAndSet(false)) {
9373 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9374 USER_ACTIVITY_NOTIFICATION_DELAY);
9375 }
9376 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009377
Malcolm Chen884180b2020-04-13 11:59:40 -07009378 @Override
9379 public boolean canConnectTo5GInDsdsMode() {
9380 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9381 }
Jack Yud10cdd42020-09-28 20:28:01 -07009382
9383 @Override
9384 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9385 String callingFeatureId) {
9386 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9387 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9388 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9389 }
9390
9391 Phone phone = getPhone(subId);
9392 if (phone == null) {
9393 throw new RuntimeException("phone is not available");
9394 }
9395 // Now that all security checks passes, perform the operation as ourselves.
9396 final long identity = Binder.clearCallingIdentity();
9397 try {
9398 return phone.getEquivalentHomePlmns();
9399 } finally {
9400 Binder.restoreCallingIdentity(identity);
9401 }
9402 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009403
Hui Wang0866fcc2020-10-12 12:14:23 -07009404 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009405 public boolean isRadioInterfaceCapabilitySupported(
9406 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009407 Set<String> radioInterfaceCapabilities =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009408 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9409 if (radioInterfaceCapabilities == null) {
9410 throw new RuntimeException("radio interface capabilities are not available");
9411 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009412 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009413 }
9414 }
9415
9416 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009417 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9418 UaSecurityProtocolIdentifier securityProtocol,
9419 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9420 throws RemoteException {
9421 enforceModifyPermission();
9422 if (DBG) {
9423 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9424 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9425 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9426 }
9427
9428 if (!SubscriptionManager.isValidSubscriptionId(subId)
9429 || appType < TelephonyManager.APPTYPE_UNKNOWN
9430 || appType > TelephonyManager.APPTYPE_ISIM
9431 || nafUrl == null || securityProtocol == null || callback == null) {
9432 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9433 if (callback != null) {
9434 try {
9435 callback.onAuthenticationFailure(
9436 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9437 } catch (RemoteException exception) {
9438 log("Fail to notify onAuthenticationFailure due to " + exception);
9439 }
9440 return;
9441 }
9442 }
9443
9444 final long token = Binder.clearCallingIdentity();
9445 try {
9446 getGbaManager(subId).bootstrapAuthenticationRequest(
9447 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9448 forceBootStrapping, callback));
9449 } finally {
9450 Binder.restoreCallingIdentity(token);
9451 }
9452 }
9453
Jack Nudelman24d51a52020-11-24 12:08:04 -08009454 /**
9455 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9456 * requested radio power state will actually be set. See {@link
9457 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9458 *
9459 * @param subId the subscription ID of the phone requesting to set the radio power state.
9460 * @param enable {@code true} if trying to turn radio on.
9461 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9462 * false}.
9463 */
9464 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9465 Phone phone = getPhone(subId);
9466 if (phone != null) {
9467 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9468 return true;
9469 }
9470 return false;
9471 }
9472
9473 private int handleDataThrottlingRequest(int subId,
9474 DataThrottlingRequest dataThrottlingRequest) {
9475 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9476 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9477 if (!setRadioPowerForThermal(subId, true)) {
9478 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9479 }
9480
9481 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9482
9483 int thermalMitigationResult =
9484 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9485 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9486 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9487 }
9488 return thermalMitigationResult;
9489 }
9490
9491 /**
9492 * Thermal mitigation request to control functionalities at modem.
9493 *
9494 * @param subId the id of the subscription.
9495 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9496 *
9497 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9498 */
9499 @Override
9500 @ThermalMitigationResult
9501 public int sendThermalMitigationRequest(
9502 int subId,
9503 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9504 enforceModifyPermission();
9505
9506 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9507 final long identity = Binder.clearCallingIdentity();
9508
9509 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9510 try {
9511 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9512 switch (thermalMitigationAction) {
9513 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9514 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009515 handleDataThrottlingRequest(subId,
9516 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009517 break;
9518 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9519 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9520 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9521 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9522 }
9523
9524 // Ensure that radio is on. If not able to power on due to phone being
9525 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9526 if (!setRadioPowerForThermal(subId, true)) {
9527 thermalMitigationResult =
9528 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9529 break;
9530 }
9531
9532 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9533 false);
9534 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9535 break;
9536 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9537 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9538 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9539 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9540 }
9541
9542 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9543 if (registry != null) {
9544 TelephonyConnectionService service =
9545 registry.getTelephonyConnectionService();
9546 Phone phone = getPhone(subId);
9547 if (phone == null) {
9548 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009549 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009550 break;
9551 }
9552
9553 if (PhoneConstantConversions.convertCallState(phone.getState())
Daniel Bright74f1ca82020-11-13 11:49:37 -08009554 != TelephonyManager.CALL_STATE_IDLE
9555 || phone.isInEmergencySmsMode() || phone.isInEcm()
9556 || (service != null && service.isEmergencyCallPending())) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009557 String errorMessage = "Phone state is not valid. call state = "
9558 + PhoneConstantConversions.convertCallState(phone.getState())
9559 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9560 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9561 errorMessage += service == null
9562 ? " TelephonyConnectionService is null"
9563 : " isEmergencyCallPending = "
9564 + service.isEmergencyCallPending();
9565 Log.e(LOG_TAG, errorMessage);
9566 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009567 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009568 break;
9569 }
9570 } else {
9571 thermalMitigationResult =
9572 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9573 break;
9574 }
9575
9576 // Turn radio off. If not able to power off due to phone being unavailable,
9577 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9578 if (!setRadioPowerForThermal(subId, false)) {
9579 thermalMitigationResult =
9580 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9581 break;
9582 }
9583 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009584 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009585 break;
9586 default:
9587 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9588 + "not exist. Requested action: " + thermalMitigationAction);
9589 }
9590 } catch (IllegalArgumentException e) {
9591 throw e;
9592 } catch (Exception e) {
9593 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9594 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9595 } finally {
9596 Binder.restoreCallingIdentity(identity);
9597 }
9598
9599 if (DBG) {
9600 log("thermalMitigationRequest returning with thermalMitigationResult: "
9601 + thermalMitigationResult);
9602 }
9603
9604 return thermalMitigationResult;
9605 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009606
9607 /**
9608 * Set the GbaService Package Name that Telephony will bind to.
9609 *
9610 * @param subId The sim that the GbaService is associated with.
9611 * @param packageName The name of the package to be replaced with.
9612 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9613 */
9614 @Override
9615 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9616 enforceModifyPermission();
9617
9618 final long identity = Binder.clearCallingIdentity();
9619 try {
9620 return getGbaManager(subId).overrideServicePackage(packageName);
9621 } finally {
9622 Binder.restoreCallingIdentity(identity);
9623 }
9624 }
9625
9626 /**
9627 * Return the package name of the currently bound GbaService.
9628 *
9629 * @param subId The sim that the GbaService is associated with.
9630 * @return the package name of the GbaService configuration, null if GBA is not supported.
9631 */
9632 @Override
9633 public String getBoundGbaService(int subId) {
9634 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9635
9636 final long identity = Binder.clearCallingIdentity();
9637 try {
9638 return getGbaManager(subId).getServicePackage();
9639 } finally {
9640 Binder.restoreCallingIdentity(identity);
9641 }
9642 }
9643
9644 /**
9645 * Set the release time for telephony to unbind GbaService.
9646 *
9647 * @param subId The sim that the GbaService is associated with.
9648 * @param interval The release time to unbind GbaService by millisecond.
9649 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9650 */
9651 @Override
9652 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9653 enforceModifyPermission();
9654
9655 final long identity = Binder.clearCallingIdentity();
9656 try {
9657 return getGbaManager(subId).overrideReleaseTime(interval);
9658 } finally {
9659 Binder.restoreCallingIdentity(identity);
9660 }
9661 }
9662
9663 /**
9664 * Return the release time for telephony to unbind GbaService.
9665 *
9666 * @param subId The sim that the GbaService is associated with.
9667 * @return The release time to unbind GbaService by millisecond.
9668 */
9669 @Override
9670 public int getGbaReleaseTime(int subId) {
9671 enforceReadPrivilegedPermission("getGbaReleaseTime");
9672
9673 final long identity = Binder.clearCallingIdentity();
9674 try {
9675 return getGbaManager(subId).getReleaseTime();
9676 } finally {
9677 Binder.restoreCallingIdentity(identity);
9678 }
9679 }
9680
9681 private GbaManager getGbaManager(int subId) {
9682 GbaManager instance = GbaManager.getInstance(subId);
9683 if (instance == null) {
9684 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9685 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9686 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9687 }
9688 return instance;
9689 }
Hui Wang068ab862020-10-31 05:12:53 +00009690
9691 /**
9692 * indicate whether the device and the carrier can support
9693 * RCS VoLTE single registration.
9694 */
9695 @Override
9696 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9697 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9698
9699 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9700 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9701 }
9702
9703 final long identity = Binder.clearCallingIdentity();
9704 try {
9705 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9706 if (rpm != null) {
9707 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9708 }
9709 return false;
9710 } finally {
9711 Binder.restoreCallingIdentity(identity);
9712 }
9713 }
9714
9715 /**
9716 * Register RCS provisioning callback.
9717 */
9718 @Override
9719 public void registerRcsProvisioningChangedCallback(int subId,
9720 IRcsConfigCallback callback) {
9721 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9722
9723 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9724 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9725 }
9726 if (!isImsAvailableOnDevice()) {
9727 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9728 "IMS not available on device.");
9729 }
9730
9731 final long identity = Binder.clearCallingIdentity();
9732 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009733 if (!RcsProvisioningMonitor.getInstance()
9734 .registerRcsProvisioningChangedCallback(subId, callback)) {
9735 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9736 "Service not available for the subscription.");
9737 }
Hui Wang068ab862020-10-31 05:12:53 +00009738 } finally {
9739 Binder.restoreCallingIdentity(identity);
9740 }
9741 }
9742
9743 /**
9744 * Unregister RCS provisioning callback.
9745 */
9746 @Override
9747 public void unregisterRcsProvisioningChangedCallback(int subId,
9748 IRcsConfigCallback callback) {
9749 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9750
9751 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9752 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9753 }
9754 if (!isImsAvailableOnDevice()) {
9755 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9756 "IMS not available on device.");
9757 }
9758
9759 final long identity = Binder.clearCallingIdentity();
9760 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009761 RcsProvisioningMonitor.getInstance()
9762 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009763 } finally {
9764 Binder.restoreCallingIdentity(identity);
9765 }
9766 }
9767
9768 /**
9769 * trigger RCS reconfiguration.
9770 */
9771 public void triggerRcsReconfiguration(int subId) {
9772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9773 mApp, subId, "triggerRcsReconfiguration");
9774
9775 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9776 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9777 }
9778 if (!isImsAvailableOnDevice()) {
9779 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9780 "IMS not available on device.");
9781 }
9782
9783 final long identity = Binder.clearCallingIdentity();
9784 try {
9785 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9786 } finally {
9787 Binder.restoreCallingIdentity(identity);
9788 }
9789 }
9790
9791 /**
9792 * Provide the client configuration parameters of the RCS application.
9793 */
9794 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9796 mApp, subId, "setRcsClientConfiguration");
9797
9798 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9799 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9800 }
9801 if (!isImsAvailableOnDevice()) {
9802 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9803 "IMS not available on device.");
9804 }
9805
9806 final long identity = Binder.clearCallingIdentity();
9807
9808 try {
9809 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9810 if (configBinder == null) {
9811 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9812 } else {
9813 configBinder.setRcsClientConfiguration(rcc);
9814 }
9815 } catch (RemoteException e) {
9816 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9817 } finally {
9818 Binder.restoreCallingIdentity(identity);
9819 }
9820 }
9821
9822 /**
Hui Wang19a21872021-02-19 20:45:36 -08009823 * Enables or disables the test mode for RCS VoLTE single registration.
9824 */
9825 @Override
9826 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9827 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9828 "setRcsSingleRegistrationTestModeEnabled");
9829
9830 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9831 }
9832
9833 /**
9834 * Gets the test mode for RCS VoLTE single registration.
9835 */
9836 @Override
9837 public boolean getRcsSingleRegistrationTestModeEnabled() {
9838 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9839 "getRcsSingleRegistrationTestModeEnabled");
9840
9841 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9842 }
9843
9844 /**
Hui Wang068ab862020-10-31 05:12:53 +00009845 * Overrides the config of RCS VoLTE single registration enabled for the device.
9846 */
9847 @Override
9848 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9849 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9850 "setDeviceSingleRegistrationEnabledOverride");
9851 enforceModifyPermission();
9852
9853 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9854 : Boolean.parseBoolean(enabledStr);
9855 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009856 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009857 }
9858
9859 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009860 * Sends a device to device communication message. Only usable via shell.
9861 * @param message message to send.
9862 * @param value message value.
9863 */
9864 @Override
9865 public void sendDeviceToDeviceMessage(int message, int value) {
9866 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9867 "setCarrierSingleRegistrationEnabledOverride");
9868 enforceModifyPermission();
9869
9870 final long identity = Binder.clearCallingIdentity();
9871 try {
9872 TelephonyConnectionService service =
9873 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9874 if (service == null) {
9875 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9876 return;
9877 }
9878 service.sendTestDeviceToDeviceMessage(message, value);
9879 } finally {
9880 Binder.restoreCallingIdentity(identity);
9881 }
9882 }
9883
9884
9885 /**
Hui Wang068ab862020-10-31 05:12:53 +00009886 * Gets the config of RCS VoLTE single registration enabled for the device.
9887 */
9888 @Override
9889 public boolean getDeviceSingleRegistrationEnabled() {
9890 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9891 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9892 }
9893
9894 /**
9895 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9896 */
9897 @Override
9898 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9899 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9900 "setCarrierSingleRegistrationEnabledOverride");
9901 enforceModifyPermission();
9902
9903 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9904 : Boolean.parseBoolean(enabledStr);
9905 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9906 subId, enabled);
9907 }
9908
9909 /**
9910 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9911 */
9912 @Override
9913 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9914 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9915 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9916 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009917
9918 /**
9919 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9920 * their mobile plan.
9921 */
9922 @Override
9923 public String getMobileProvisioningUrl() {
9924 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9925 final long identity = Binder.clearCallingIdentity();
9926 try {
9927 return getDefaultPhone().getMobileProvisioningUrl();
9928 } finally {
9929 Binder.restoreCallingIdentity(identity);
9930 }
9931 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009932
James.cf Linbcdf8b32021-01-14 16:44:13 +08009933 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009934 * Get the EAB contact from the EAB database.
9935 */
9936 @Override
9937 public String getContactFromEab(String contact) {
9938 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9939 enforceModifyPermission();
9940 final long identity = Binder.clearCallingIdentity();
9941 try {
9942 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9943 } finally {
9944 Binder.restoreCallingIdentity(identity);
9945 }
9946 }
9947
9948 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009949 * Remove the EAB contacts from the EAB database.
9950 */
9951 @Override
9952 public int removeContactFromEab(int subId, String contacts) {
9953 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9954 enforceModifyPermission();
9955 final long identity = Binder.clearCallingIdentity();
9956 try {
9957 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9958 } finally {
9959 Binder.restoreCallingIdentity(identity);
9960 }
9961 }
9962
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009963 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +08009964 public boolean getDeviceUceEnabled() {
9965 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
9966 final long identity = Binder.clearCallingIdentity();
9967 try {
9968 return mApp.getDeviceUceEnabled();
9969 } finally {
9970 Binder.restoreCallingIdentity(identity);
9971 }
9972 }
9973
9974 @Override
9975 public void setDeviceUceEnabled(boolean isEnabled) {
9976 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
9977 final long identity = Binder.clearCallingIdentity();
9978 try {
9979 mApp.setDeviceUceEnabled(isEnabled);
9980 } finally {
9981 Binder.restoreCallingIdentity(identity);
9982 }
9983 }
9984
9985 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009986 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9987 String callingPackage) {
9988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9989 mApp, subId, "setSignalStrengthUpdateRequest");
9990
9991 final int callingUid = Binder.getCallingUid();
9992 // Verify that tha callingPackage belongs to the calling UID
9993 mApp.getSystemService(AppOpsManager.class)
9994 .checkPackage(callingUid, callingPackage);
9995
9996 validateSignalStrengthUpdateRequest(request, callingUid);
9997
9998 final long identity = Binder.clearCallingIdentity();
9999 try {
10000 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10001 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10002
10003 if (result instanceof IllegalStateException) {
10004 throw (IllegalStateException) result;
10005 }
10006 } finally {
10007 Binder.restoreCallingIdentity(identity);
10008 }
10009 }
10010
10011 @Override
10012 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10013 String callingPackage) {
10014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10015 mApp, subId, "clearSignalStrengthUpdateRequest");
10016
10017 final int callingUid = Binder.getCallingUid();
10018 // Verify that tha callingPackage belongs to the calling UID
10019 mApp.getSystemService(AppOpsManager.class)
10020 .checkPackage(callingUid, callingPackage);
10021
10022 final long identity = Binder.clearCallingIdentity();
10023 try {
10024 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10025 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10026
10027 if (result instanceof IllegalStateException) {
10028 throw (IllegalStateException) result;
10029 }
10030 } finally {
10031 Binder.restoreCallingIdentity(identity);
10032 }
10033 }
10034
10035 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10036 int callingUid) {
10037 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10038 // phone/system process do not have further restriction on request
10039 return;
10040 }
10041
10042 // Applications has restrictions on how to use the request:
10043 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10044 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10045 // This is not system caller which has been checked above
10046 throw new IllegalArgumentException(
10047 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10048 }
10049
10050 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10051 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10052 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10053 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10054 || info.isEnabled()) {
10055 throw new IllegalArgumentException(
10056 "Only system can set hide fields in SignalThresholdInfo");
10057 }
10058
10059 // Thresholds length for each RAN need in range. This has been validated in
10060 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10061 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10062 final int[] thresholds = info.getThresholds();
10063 Objects.requireNonNull(thresholds);
10064 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10065 || thresholds.length
10066 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10067 throw new IllegalArgumentException(
10068 "thresholds length is out of range: " + thresholds.length);
10069 }
10070 }
10071 }
Michele Berionned9fbae52020-11-13 02:36:59 +000010072
10073 /**
10074 * Prepare TelephonyManager for an unattended reboot. The reboot is
10075 * required to be done shortly after the API is invoked.
10076 */
10077 @Override
10078 @TelephonyManager.PrepareUnattendedRebootResult
10079 public int prepareForUnattendedReboot() {
10080 enforceRebootPermission();
10081
10082 final long identity = Binder.clearCallingIdentity();
10083 try {
10084 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10085 } finally {
10086 Binder.restoreCallingIdentity(identity);
10087 }
10088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010089}