blob: e85b483aac5733b3ccedf650cbedf1669506dfb2 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070055import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070057import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070058import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080059import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070060import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090061import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080062import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080063import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070064import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070065import android.telephony.Annotation.ApnType;
Jack Nudelman24d51a52020-11-24 12:08:04 -080066import android.telephony.Annotation.ThermalMitigationResult;
sqian80370722020-01-29 15:02:51 -080067import android.telephony.CallForwardingInfo;
Sooraj Sasindran1f812e02020-10-30 13:17:53 -070068import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070069import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080070import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070071import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080072import android.telephony.CellIdentityCdma;
73import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070075import android.telephony.CellInfoGsm;
76import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070077import android.telephony.ClientRequestStats;
Jack Nudelman24d51a52020-11-24 12:08:04 -080078import android.telephony.DataThrottlingRequest;
Hui Wang0866fcc2020-10-12 12:14:23 -070079import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070080import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070081import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080082import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070083import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080084import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070085import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080086import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080087import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070088import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080089import android.telephony.RadioAccessSpecifier;
Daniel Bright74f1ca82020-11-13 11:49:37 -080090import android.telephony.RadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080092import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080093import android.telephony.SignalStrengthUpdateRequest;
94import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080095import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080096import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080097import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070098import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070099import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800100import android.telephony.TelephonyScanManager;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800101import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800102import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000103import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700104import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700105import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800106import android.telephony.data.ApnSetting;
107import android.telephony.emergency.EmergencyNumber;
Hui Wang0866fcc2020-10-12 12:14:23 -0700108import android.telephony.gba.GbaAuthRequest;
109import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700110import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800111import android.telephony.ims.ProvisioningManager;
Hui Wang068ab862020-10-31 05:12:53 +0000112import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger774ba362019-10-22 17:36:18 -0700113import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700114import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800115import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700116import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800117import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700118import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang068ab862020-10-31 05:12:53 +0000119import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700120import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800121import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800122import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800123import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800124import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800126import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700127import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800129import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800130
Andrew Lee312e8172014-10-23 17:01:36 -0700131import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800132import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800133import com.android.ims.rcs.uce.eab.EabUtil;
sqian80370722020-01-29 15:02:51 -0800134import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700135import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700136import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700137import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800138import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700139import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700140import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800141import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang0866fcc2020-10-12 12:14:23 -0700143import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800144import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800145import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700146import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700147import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800148import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800150import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700151import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700152import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700153import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700155import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800156import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700157import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700158import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700159import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700160import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700161import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700162import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700163import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700164import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800165import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800166import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800167import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700168import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800169import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700170import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800171import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700172import com.android.internal.telephony.imsphone.ImsPhone;
173import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800174import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900175import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700176import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800177import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700178import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800179import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700180import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800181import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700182import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800183import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000184import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800185import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700186import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700187import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800188import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700189import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700190import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800191import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700192import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700193import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800194import com.android.services.telephony.TelecomAccountRegistry;
195import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800196import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800197
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700198import java.io.FileDescriptor;
199import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800201import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800202import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800203import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800204import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100205import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800206import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700207import java.util.NoSuchElementException;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800208import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800209import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800210import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800211import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700212
213/**
214 * Implementation of the ITelephony interface.
215 */
Santos Cordon117fee72014-05-16 17:56:12 -0700216public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217 private static final String LOG_TAG = "PhoneInterfaceManager";
218 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
219 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800220 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700221
222 // Message codes used with mMainThreadHandler
223 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700224 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
225 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700226 private static final int CMD_OPEN_CHANNEL = 9;
227 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
228 private static final int CMD_CLOSE_CHANNEL = 11;
229 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800230 private static final int CMD_NV_READ_ITEM = 13;
231 private static final int EVENT_NV_READ_ITEM_DONE = 14;
232 private static final int CMD_NV_WRITE_ITEM = 15;
233 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
234 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
235 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700236 private static final int CMD_RESET_MODEM_CONFIG = 19;
237 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800238 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
239 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
240 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
241 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800242 private static final int CMD_SEND_ENVELOPE = 25;
243 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000244 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
245 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700246 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
247 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
248 private static final int CMD_EXCHANGE_SIM_IO = 31;
249 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800250 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
251 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700252 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
253 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700254 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
255 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700256 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
257 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
258 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
259 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700260 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
261 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
262 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
263 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700264 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800265 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
266 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000267 private static final int CMD_SWITCH_SLOTS = 50;
268 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700269 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
270 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
271 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
272 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
273 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
274 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
275 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
276 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700277 private static final int CMD_GET_ALL_CELL_INFO = 60;
278 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
279 private static final int CMD_GET_CELL_LOCATION = 62;
280 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700281 private static final int CMD_MODEM_REBOOT = 64;
282 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700283 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
284 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800285 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
286 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700287 private static final int CMD_GET_MODEM_STATUS = 70;
288 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700289 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
290 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700291 private static final int CMD_ERASE_MODEM_CONFIG = 74;
292 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800293 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
294 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
295 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
296 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800297 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
298 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800299 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800300 private static final int CMD_GET_CALL_FORWARDING = 83;
301 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
302 private static final int CMD_SET_CALL_FORWARDING = 85;
303 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
304 private static final int CMD_GET_CALL_WAITING = 87;
305 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
306 private static final int CMD_SET_CALL_WAITING = 89;
307 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700308 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
309 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
310 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
311 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700312 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
313 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800314 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
315 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800316 private static final int CMD_SET_DATA_THROTTLING = 99;
317 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800318 private static final int CMD_SET_SIM_POWER = 101;
319 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800320 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
321 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
322 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
323 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700324
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800325 // Parameters of select command.
326 private static final int SELECT_COMMAND = 0xA4;
327 private static final int SELECT_P1 = 0x04;
328 private static final int SELECT_P2 = 0;
329 private static final int SELECT_P3 = 0x10;
330
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700331 /** The singleton instance. */
332 private static PhoneInterfaceManager sInstance;
333
Wink Saville3ab207e2014-11-20 13:07:20 -0800334 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800335 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800336 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700337 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800338 private AppOpsManager mAppOps;
339 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800340 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800341 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700342 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343
Peter Wangdafb9ac2020-01-15 14:13:38 -0800344 /** User Activity */
345 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800346 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
347
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700348 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
349
Derek Tan97ebb422014-09-05 16:55:38 -0700350 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
351 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800352 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800353 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700354
Michelecea4cf22018-12-21 15:00:11 -0800355 // String to store multi SIM allowed
356 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
357
Derek Tan740e1672017-06-27 14:56:27 -0700358 // The AID of ISD-R.
359 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
360
yinxub1bed742017-04-17 11:45:04 -0700361 private NetworkScanRequestTracker mNetworkScanRequestTracker;
362
David Kelly5e06a7f2018-03-12 14:10:59 +0000363 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
364 private static final int MANUFACTURER_CODE_LENGTH = 8;
365
Jack Nudelman24d51a52020-11-24 12:08:04 -0800366 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
367
Derek Tan89e89d42014-07-08 17:00:10 -0700368 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700369 * Experiment flag to enable erase modem config on reset network, default value is false
370 */
371 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
372 "reset_network_erase_modem_config_enabled";
373
374 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700375 * A request object to use for transmitting data to an ICC.
376 */
377 private static final class IccAPDUArgument {
378 public int channel, cla, command, p1, p2, p3;
379 public String data;
380
381 public IccAPDUArgument(int channel, int cla, int command,
382 int p1, int p2, int p3, String data) {
383 this.channel = channel;
384 this.cla = cla;
385 this.command = command;
386 this.p1 = p1;
387 this.p2 = p2;
388 this.p3 = p3;
389 this.data = data;
390 }
391 }
392
393 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700394 * A request object to use for transmitting data to an ICC.
395 */
396 private static final class ManualNetworkSelectionArgument {
397 public OperatorInfo operatorInfo;
398 public boolean persistSelection;
399
400 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
401 this.operatorInfo = operatorInfo;
402 this.persistSelection = persistSelection;
403 }
404 }
405
406 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
408 * request after sending. The main thread will notify the request when it is complete.
409 */
410 private static final class MainThreadRequest {
411 /** The argument to use for the request */
412 public Object argument;
413 /** The result of the request that is run on the main thread */
414 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800415 // The subscriber id that this request applies to. Defaults to
416 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
417 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418
Nathan Harold92bed182018-10-12 18:16:49 -0700419 // In cases where subId is unavailable, the caller needs to specify the phone.
420 public Phone phone;
421
vagdeviaf9a5b92018-08-15 16:01:53 -0700422 public WorkSource workSource;
423
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 public MainThreadRequest(Object argument) {
425 this.argument = argument;
426 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800427
Nathan Harold92bed182018-10-12 18:16:49 -0700428 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
429 this.argument = argument;
430 if (phone != null) {
431 this.phone = phone;
432 }
433 this.workSource = workSource;
434 }
435
vagdeviaf9a5b92018-08-15 16:01:53 -0700436 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800437 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800438 if (subId != null) {
439 this.subId = subId;
440 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700441 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443 }
444
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800445 private static final class IncomingThirdPartyCallArgs {
446 public final ComponentName component;
447 public final String callId;
448 public final String callerDisplayName;
449
450 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
451 String callerDisplayName) {
452 this.component = component;
453 this.callId = callId;
454 this.callerDisplayName = callerDisplayName;
455 }
456 }
457
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458 /**
459 * A handler that processes messages on the main thread in the phone process. Since many
460 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
461 * inbound binder threads to the main thread in the phone process. The Binder thread
462 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
463 * on, which will be notified when the operation completes and will contain the result of the
464 * request.
465 *
466 * <p>If a MainThreadRequest object is provided in the msg.obj field,
467 * note that request.result must be set to something non-null for the calling thread to
468 * unblock.
469 */
470 private final class MainThreadHandler extends Handler {
471 @Override
472 public void handleMessage(Message msg) {
473 MainThreadRequest request;
474 Message onCompleted;
475 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800476 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700477 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800478 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700479
480 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700481 case CMD_HANDLE_USSD_REQUEST: {
482 request = (MainThreadRequest) msg.obj;
483 final Phone phone = getPhoneFromRequest(request);
484 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
485 String ussdRequest = ussdObject.first;
486 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700487
Pengquan Menga1bb6272018-09-06 09:59:22 -0700488 if (!isUssdApiAllowed(request.subId)) {
489 // Carrier does not support use of this API, return failure.
490 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
491 UssdResponse response = new UssdResponse(ussdRequest, null);
492 Bundle returnData = new Bundle();
493 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
494 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700495
Pengquan Menga1bb6272018-09-06 09:59:22 -0700496 request.result = true;
497 notifyRequester(request);
498 return;
499 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700500
Pengquan Menga1bb6272018-09-06 09:59:22 -0700501 try {
502 request.result = phone != null
503 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
504 } catch (CallStateException cse) {
505 request.result = false;
506 }
507 // Wake up the requesting thread
508 notifyRequester(request);
509 break;
pkanwar32d516d2016-10-14 19:37:38 -0700510 }
511
Yorke Lee716f67e2015-06-17 15:39:16 -0700512 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700513 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700514 final Phone phone = getPhoneFromRequest(request);
515 request.result = phone != null ?
516 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
517 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700518 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700519 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700522
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700524 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700525 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800526 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700527 if (uiccCard == null) {
528 loge("iccTransmitApduLogicalChannel: No UICC");
529 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700530 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700531 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
533 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700534 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700535 iccArgument.channel, iccArgument.cla, iccArgument.command,
536 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700537 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700538 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700539 break;
540
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700542 ar = (AsyncResult) msg.obj;
543 request = (MainThreadRequest) ar.userObj;
544 if (ar.exception == null && ar.result != null) {
545 request.result = ar.result;
546 } else {
547 request.result = new IccIoResult(0x6F, 0, (byte[])null);
548 if (ar.result == null) {
549 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800550 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700551 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800552 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700553 } else {
554 loge("iccTransmitApduLogicalChannel: Unknown exception");
555 }
556 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700558 break;
559
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
561 request = (MainThreadRequest) msg.obj;
562 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800563 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 if (uiccCard == null) {
565 loge("iccTransmitApduBasicChannel: No UICC");
566 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700567 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 } else {
569 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
570 request);
571 uiccCard.iccTransmitApduBasicChannel(
572 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
573 iccArgument.p3, iccArgument.data, onCompleted);
574 }
575 break;
576
577 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
578 ar = (AsyncResult) msg.obj;
579 request = (MainThreadRequest) ar.userObj;
580 if (ar.exception == null && ar.result != null) {
581 request.result = ar.result;
582 } else {
583 request.result = new IccIoResult(0x6F, 0, (byte[])null);
584 if (ar.result == null) {
585 loge("iccTransmitApduBasicChannel: Empty response");
586 } else if (ar.exception instanceof CommandException) {
587 loge("iccTransmitApduBasicChannel: CommandException: " +
588 ar.exception);
589 } else {
590 loge("iccTransmitApduBasicChannel: Unknown exception");
591 }
592 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 break;
595
596 case CMD_EXCHANGE_SIM_IO:
597 request = (MainThreadRequest) msg.obj;
598 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800599 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 if (uiccCard == null) {
601 loge("iccExchangeSimIO: No UICC");
602 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700603 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 } else {
605 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
606 request);
607 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
608 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
609 iccArgument.data, onCompleted);
610 }
611 break;
612
613 case EVENT_EXCHANGE_SIM_IO_DONE:
614 ar = (AsyncResult) msg.obj;
615 request = (MainThreadRequest) ar.userObj;
616 if (ar.exception == null && ar.result != null) {
617 request.result = ar.result;
618 } else {
619 request.result = new IccIoResult(0x6f, 0, (byte[])null);
620 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700621 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 break;
623
Derek Tan4d5e5c12014-02-04 11:54:58 -0800624 case CMD_SEND_ENVELOPE:
625 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800626 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700627 if (uiccCard == null) {
628 loge("sendEnvelopeWithStatus: No UICC");
629 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700631 } else {
632 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
633 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
634 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800635 break;
636
637 case EVENT_SEND_ENVELOPE_DONE:
638 ar = (AsyncResult) msg.obj;
639 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700640 if (ar.exception == null && ar.result != null) {
641 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800642 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700643 request.result = new IccIoResult(0x6F, 0, (byte[])null);
644 if (ar.result == null) {
645 loge("sendEnvelopeWithStatus: Empty response");
646 } else if (ar.exception instanceof CommandException) {
647 loge("sendEnvelopeWithStatus: CommandException: " +
648 ar.exception);
649 } else {
650 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
651 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800652 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700653 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800654 break;
655
Shishir Agrawal566b7612013-10-28 14:41:00 -0700656 case CMD_OPEN_CHANNEL:
657 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800658 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800659 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700660 if (uiccCard == null) {
661 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800662 request.result = new IccOpenLogicalChannelResponse(-1,
663 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700664 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700665 } else {
666 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800667 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
668 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700669 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 break;
671
672 case EVENT_OPEN_CHANNEL_DONE:
673 ar = (AsyncResult) msg.obj;
674 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700675 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700677 int[] result = (int[]) ar.result;
678 int channelId = result[0];
679 byte[] selectResponse = null;
680 if (result.length > 1) {
681 selectResponse = new byte[result.length - 1];
682 for (int i = 1; i < result.length; ++i) {
683 selectResponse[i - 1] = (byte) result[i];
684 }
685 }
686 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700687 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 if (ar.result == null) {
690 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700692 if (ar.exception != null) {
693 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
694 }
695
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700696 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700697 if (ar.exception instanceof CommandException) {
698 CommandException.Error error =
699 ((CommandException) (ar.exception)).getCommandError();
700 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700701 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700702 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700703 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700704 }
705 }
706 openChannelResp = new IccOpenLogicalChannelResponse(
707 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700709 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700710 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700711 break;
712
713 case CMD_CLOSE_CHANNEL:
714 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800715 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700716 if (uiccCard == null) {
717 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900718 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700719 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700720 } else {
721 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
722 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
723 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700724 break;
725
726 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800727 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
728 break;
729
730 case CMD_NV_READ_ITEM:
731 request = (MainThreadRequest) msg.obj;
732 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800733 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
734 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800735 break;
736
737 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700738 ar = (AsyncResult) msg.obj;
739 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800740 if (ar.exception == null && ar.result != null) {
741 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800743 request.result = "";
744 if (ar.result == null) {
745 loge("nvReadItem: Empty response");
746 } else if (ar.exception instanceof CommandException) {
747 loge("nvReadItem: CommandException: " +
748 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700749 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800750 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700751 }
752 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700753 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700754 break;
755
Jake Hambye994d462014-02-03 13:10:13 -0800756 case CMD_NV_WRITE_ITEM:
757 request = (MainThreadRequest) msg.obj;
758 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
759 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800760 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700761 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800762 break;
763
764 case EVENT_NV_WRITE_ITEM_DONE:
765 handleNullReturnEvent(msg, "nvWriteItem");
766 break;
767
768 case CMD_NV_WRITE_CDMA_PRL:
769 request = (MainThreadRequest) msg.obj;
770 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800771 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800772 break;
773
774 case EVENT_NV_WRITE_CDMA_PRL_DONE:
775 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
776 break;
777
chen xu6dac5ab2018-10-26 17:39:23 -0700778 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800779 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700780 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800781 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800782 break;
783
chen xu6dac5ab2018-10-26 17:39:23 -0700784 case EVENT_RESET_MODEM_CONFIG_DONE:
785 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800786 break;
787
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700788 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
789 request = (MainThreadRequest) msg.obj;
790 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
791 request);
792 Phone phone = getPhoneFromRequest(request);
793 if (phone != null) {
794 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
795 } else {
796 loge("isNRDualConnectivityEnabled: No phone object");
797 request.result = false;
798 notifyRequester(request);
799 }
800 break;
801 }
802
803 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
804 ar = (AsyncResult) msg.obj;
805 request = (MainThreadRequest) ar.userObj;
806 if (ar.exception == null && ar.result != null) {
807 request.result = ar.result;
808 } else {
809 // request.result must be set to something non-null
810 // for the calling thread to unblock
811 if (request.result != null) {
812 request.result = ar.result;
813 } else {
814 request.result = false;
815 }
816 if (ar.result == null) {
817 loge("isNRDualConnectivityEnabled: Empty response");
818 } else if (ar.exception instanceof CommandException) {
819 loge("isNRDualConnectivityEnabled: CommandException: "
820 + ar.exception);
821 } else {
822 loge("isNRDualConnectivityEnabled: Unknown exception");
823 }
824 }
825 notifyRequester(request);
826 break;
827
828 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
829 request = (MainThreadRequest) msg.obj;
830 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
831 Phone phone = getPhoneFromRequest(request);
832 if (phone != null) {
833 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
834 request.workSource);
835 } else {
836 loge("enableNrDualConnectivity: No phone object");
837 request.result =
838 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
839 notifyRequester(request);
840 }
841 break;
842 }
843
844 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
845 ar = (AsyncResult) msg.obj;
846 request = (MainThreadRequest) ar.userObj;
847 if (ar.exception == null) {
848 request.result =
849 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
850 } else {
851 request.result =
852 TelephonyManager
853 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
854 if (ar.exception instanceof CommandException) {
855 CommandException.Error error =
856 ((CommandException) (ar.exception)).getCommandError();
857 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
858 request.result =
859 TelephonyManager
860 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
861 }
862 loge("enableNrDualConnectivity" + ": CommandException: "
863 + ar.exception);
864 } else {
865 loge("enableNrDualConnectivity" + ": Unknown exception");
866 }
867 }
868 notifyRequester(request);
869 break;
870 }
871
Jake Hamby7c27be32014-03-03 13:25:59 -0800872 case CMD_GET_PREFERRED_NETWORK_TYPE:
873 request = (MainThreadRequest) msg.obj;
874 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700875 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800876 break;
877
878 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
879 ar = (AsyncResult) msg.obj;
880 request = (MainThreadRequest) ar.userObj;
881 if (ar.exception == null && ar.result != null) {
882 request.result = ar.result; // Integer
883 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530884 // request.result must be set to something non-null
885 // for the calling thread to unblock
886 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800887 if (ar.result == null) {
888 loge("getPreferredNetworkType: Empty response");
889 } else if (ar.exception instanceof CommandException) {
890 loge("getPreferredNetworkType: CommandException: " +
891 ar.exception);
892 } else {
893 loge("getPreferredNetworkType: Unknown exception");
894 }
895 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700896 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800897 break;
898
899 case CMD_SET_PREFERRED_NETWORK_TYPE:
900 request = (MainThreadRequest) msg.obj;
901 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
902 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700903 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800904 break;
905
906 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
907 handleNullReturnEvent(msg, "setPreferredNetworkType");
908 break;
909
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000910 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
911 request = (MainThreadRequest)msg.obj;
912 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800913 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000914 break;
915
916 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
917 ar = (AsyncResult)msg.obj;
918 request = (MainThreadRequest)ar.userObj;
919 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700920 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000921 break;
922
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800923 case CMD_SET_VOICEMAIL_NUMBER:
924 request = (MainThreadRequest) msg.obj;
925 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
926 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800927 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
928 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800929 break;
930
931 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
932 handleNullReturnEvent(msg, "setVoicemailNumber");
933 break;
934
Stuart Scott54788802015-03-30 13:18:01 -0700935 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
936 request = (MainThreadRequest) msg.obj;
937 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
938 request);
939 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
940 break;
941
942 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
943 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
944 break;
945
Shishir Agrawal302c8692015-06-19 13:49:39 -0700946 case CMD_PERFORM_NETWORK_SCAN:
947 request = (MainThreadRequest) msg.obj;
948 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
949 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
950 break;
951
Hall Liua1acea22020-09-18 19:04:59 -0700952 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800953 request = (MainThreadRequest) msg.obj;
954 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700955 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
956 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
957 request.argument;
958 int callForwardingReason = args.first;
959 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800960 break;
Hall Liua1acea22020-09-18 19:04:59 -0700961 }
962 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800963 ar = (AsyncResult) msg.obj;
964 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700965 TelephonyManager.CallForwardingInfoCallback callback =
966 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
967 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800968 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700969 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800970 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
971 for (CallForwardInfo callForwardInfo : callForwardInfos) {
972 // Service Class is a bit mask per 3gpp 27.007. Search for
973 // any service for voice call.
974 if ((callForwardInfo.serviceClass
975 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700976 callForwardingInfo = new CallForwardingInfo(true,
977 callForwardInfo.reason,
978 callForwardInfo.number,
979 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800980 break;
981 }
982 }
983 // Didn't find a call forward info for voice call.
984 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700985 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
986 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800987 }
Hall Liua1acea22020-09-18 19:04:59 -0700988 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -0800989 } else {
990 if (ar.result == null) {
991 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
992 }
993 if (ar.exception != null) {
994 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
995 }
Hall Liuae527aa2020-09-29 17:10:18 -0700996 int errorCode = TelephonyManager
997 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -0800998 if (ar.exception instanceof CommandException) {
999 CommandException.Error error =
1000 ((CommandException) (ar.exception)).getCommandError();
1001 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001002 errorCode = TelephonyManager
1003 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001004 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001005 errorCode = TelephonyManager
1006 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001007 }
1008 }
Hall Liua1acea22020-09-18 19:04:59 -07001009 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001010 }
sqian80370722020-01-29 15:02:51 -08001011 break;
Hall Liua1acea22020-09-18 19:04:59 -07001012 }
sqian80370722020-01-29 15:02:51 -08001013
Hall Liua1acea22020-09-18 19:04:59 -07001014 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001015 request = (MainThreadRequest) msg.obj;
1016 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001017 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001018 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001019 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1020 request.argument).first;
1021 request.phone.setCallForwardingOption(
1022 callForwardingInfoToSet.isEnabled()
1023 ? CommandsInterface.CF_ACTION_ENABLE
1024 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001025 callForwardingInfoToSet.getReason(),
1026 callForwardingInfoToSet.getNumber(),
1027 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1028 break;
Hall Liua1acea22020-09-18 19:04:59 -07001029 }
sqian80370722020-01-29 15:02:51 -08001030
Hall Liua1acea22020-09-18 19:04:59 -07001031 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001032 ar = (AsyncResult) msg.obj;
1033 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001034 Consumer<Integer> callback =
1035 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1036 request.argument).second;
1037 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001038 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001039 int errorCode = TelephonyManager.CallForwardingInfoCallback
1040 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001041 if (ar.exception instanceof CommandException) {
1042 CommandException.Error error =
1043 ((CommandException) (ar.exception)).getCommandError();
1044 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001045 errorCode = TelephonyManager.CallForwardingInfoCallback
1046 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001047 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001048 errorCode = TelephonyManager.CallForwardingInfoCallback
1049 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001050 }
1051 }
1052 callback.accept(errorCode);
1053 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001054 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001055 }
sqian80370722020-01-29 15:02:51 -08001056 break;
Hall Liua1acea22020-09-18 19:04:59 -07001057 }
sqian80370722020-01-29 15:02:51 -08001058
Hall Liua1acea22020-09-18 19:04:59 -07001059 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001060 request = (MainThreadRequest) msg.obj;
1061 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1062 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1063 break;
Hall Liua1acea22020-09-18 19:04:59 -07001064 }
sqian80370722020-01-29 15:02:51 -08001065
Hall Liua1acea22020-09-18 19:04:59 -07001066 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001069 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001070 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1071 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001072 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001073 // Service Class is a bit mask per 3gpp 27.007.
1074 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001075 if (callForwardResults.length > 1
1076 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001077 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001078 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001079 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1080 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001081 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001082 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001083 }
1084 } else {
1085 if (ar.result == null) {
1086 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1087 }
1088 if (ar.exception != null) {
1089 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1090 }
1091 if (ar.exception instanceof CommandException) {
1092 CommandException.Error error =
1093 ((CommandException) (ar.exception)).getCommandError();
1094 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1095 callForwardingStatus =
1096 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1097 }
1098 }
1099 }
Hall Liua1acea22020-09-18 19:04:59 -07001100 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001101 break;
Hall Liua1acea22020-09-18 19:04:59 -07001102 }
sqian80370722020-01-29 15:02:51 -08001103
Hall Liua1acea22020-09-18 19:04:59 -07001104 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001105 request = (MainThreadRequest) msg.obj;
1106 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001107 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1108 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001109 break;
Hall Liua1acea22020-09-18 19:04:59 -07001110 }
sqian80370722020-01-29 15:02:51 -08001111
Hall Liua1acea22020-09-18 19:04:59 -07001112 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001113 ar = (AsyncResult) msg.obj;
1114 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001115 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1116 Consumer<Integer> callback =
1117 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1118 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001119 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001120 if (ar.exception instanceof CommandException) {
1121 CommandException.Error error =
1122 ((CommandException) (ar.exception)).getCommandError();
1123 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1124 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1125 } else {
1126 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1127 }
1128 } else {
1129 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1130 }
1131 } else {
1132 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1133 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001134 }
sqian80370722020-01-29 15:02:51 -08001135 break;
Hall Liua1acea22020-09-18 19:04:59 -07001136 }
sqian80370722020-01-29 15:02:51 -08001137
Shishir Agrawal302c8692015-06-19 13:49:39 -07001138 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1139 ar = (AsyncResult) msg.obj;
1140 request = (MainThreadRequest) ar.userObj;
1141 CellNetworkScanResult cellScanResult;
1142 if (ar.exception == null && ar.result != null) {
1143 cellScanResult = new CellNetworkScanResult(
1144 CellNetworkScanResult.STATUS_SUCCESS,
1145 (List<OperatorInfo>) ar.result);
1146 } else {
1147 if (ar.result == null) {
1148 loge("getCellNetworkScanResults: Empty response");
1149 }
1150 if (ar.exception != null) {
1151 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1152 }
1153 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1154 if (ar.exception instanceof CommandException) {
1155 CommandException.Error error =
1156 ((CommandException) (ar.exception)).getCommandError();
1157 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1158 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1159 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1160 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1161 }
1162 }
1163 cellScanResult = new CellNetworkScanResult(errorCode, null);
1164 }
1165 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001166 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001167 break;
1168
1169 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1170 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001171 ManualNetworkSelectionArgument selArg =
1172 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001173 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1174 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001175 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1176 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001177 break;
1178
1179 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001180 ar = (AsyncResult) msg.obj;
1181 request = (MainThreadRequest) ar.userObj;
1182 if (ar.exception == null) {
1183 request.result = true;
1184 } else {
1185 request.result = false;
1186 loge("setNetworkSelectionModeManual " + ar.exception);
1187 }
1188 notifyRequester(request);
1189 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001190 break;
1191
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001192 case CMD_GET_MODEM_ACTIVITY_INFO:
1193 request = (MainThreadRequest) msg.obj;
1194 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001195 if (defaultPhone != null) {
1196 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001197 } else {
1198 ResultReceiver result = (ResultReceiver) request.argument;
1199 Bundle bundle = new Bundle();
1200 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1201 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1202 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001203 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001204 break;
1205
1206 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1207 ar = (AsyncResult) msg.obj;
1208 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001209 ResultReceiver result = (ResultReceiver) request.argument;
1210
1211 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001212 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001213 // Update the last modem activity info and the result of the request.
1214 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1215 if (isModemActivityInfoValid(info)) {
1216 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1217 int[] txTimeMs = info.getTransmitTimeMillis();
1218 int[] lastModemTxTimeMs = mLastModemActivityInfo
1219 .getTransmitTimeMillis();
1220 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1221 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1222 }
1223 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1224 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1225 + mLastModemActivityInfo.getSleepTimeMillis());
1226 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1227 + mLastModemActivityInfo.getIdleTimeMillis());
1228 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1229 mLastModemActivityInfo.setReceiveTimeMillis(
1230 info.getReceiveTimeMillis()
1231 + mLastModemActivityInfo.getReceiveTimeMillis());
1232 }
1233 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1234 mLastModemActivityInfo.getSleepTimeMillis(),
1235 mLastModemActivityInfo.getIdleTimeMillis(),
1236 mLastModemActivityInfo.getTransmitTimeMillis(),
1237 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001238 } else {
1239 if (ar.result == null) {
1240 loge("queryModemActivityInfo: Empty response");
1241 } else if (ar.exception instanceof CommandException) {
1242 loge("queryModemActivityInfo: CommandException: " +
1243 ar.exception);
1244 } else {
1245 loge("queryModemActivityInfo: Unknown exception");
1246 }
1247 }
sqian1a1be542020-03-05 11:37:28 -08001248 Bundle bundle = new Bundle();
1249 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1250 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001251 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001252 break;
1253
Meng Wang1a7c35a2016-05-05 20:56:15 -07001254 case CMD_SET_ALLOWED_CARRIERS:
1255 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001256 CarrierRestrictionRules argument =
1257 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001258 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001259 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001260 break;
1261
1262 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1263 ar = (AsyncResult) msg.obj;
1264 request = (MainThreadRequest) ar.userObj;
1265 if (ar.exception == null && ar.result != null) {
1266 request.result = ar.result;
1267 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001268 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1269 if (ar.exception instanceof CommandException) {
1270 loge("setAllowedCarriers: CommandException: " + ar.exception);
1271 CommandException.Error error =
1272 ((CommandException) (ar.exception)).getCommandError();
1273 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1274 request.result =
1275 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1276 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001277 } else {
1278 loge("setAllowedCarriers: Unknown exception");
1279 }
1280 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001281 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001282 break;
1283
1284 case CMD_GET_ALLOWED_CARRIERS:
1285 request = (MainThreadRequest) msg.obj;
1286 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001287 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001288 break;
1289
1290 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1291 ar = (AsyncResult) msg.obj;
1292 request = (MainThreadRequest) ar.userObj;
1293 if (ar.exception == null && ar.result != null) {
1294 request.result = ar.result;
1295 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001296 request.result = new IllegalStateException(
1297 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001298 if (ar.result == null) {
1299 loge("getAllowedCarriers: Empty response");
1300 } else if (ar.exception instanceof CommandException) {
1301 loge("getAllowedCarriers: CommandException: " +
1302 ar.exception);
1303 } else {
1304 loge("getAllowedCarriers: Unknown exception");
1305 }
1306 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001307 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001308 break;
1309
Nathan Haroldb3014052017-01-25 15:57:32 -08001310 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1311 ar = (AsyncResult) msg.obj;
1312 request = (MainThreadRequest) ar.userObj;
1313 if (ar.exception == null && ar.result != null) {
1314 request.result = ar.result;
1315 } else {
1316 request.result = new IllegalArgumentException(
1317 "Failed to retrieve Forbidden Plmns");
1318 if (ar.result == null) {
1319 loge("getForbiddenPlmns: Empty response");
1320 } else {
1321 loge("getForbiddenPlmns: Unknown exception");
1322 }
1323 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001324 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001325 break;
1326
1327 case CMD_GET_FORBIDDEN_PLMNS:
1328 request = (MainThreadRequest) msg.obj;
1329 uiccCard = getUiccCardFromRequest(request);
1330 if (uiccCard == null) {
1331 loge("getForbiddenPlmns() UiccCard is null");
1332 request.result = new IllegalArgumentException(
1333 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001334 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001335 break;
1336 }
1337 Integer appType = (Integer) request.argument;
1338 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1339 if (uiccApp == null) {
1340 loge("getForbiddenPlmns() no app with specified type -- "
1341 + appType);
1342 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001343 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001344 break;
1345 } else {
1346 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1347 + " specified type -- " + appType);
1348 }
1349 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1350 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1351 onCompleted);
1352 break;
1353
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001354 case CMD_SWITCH_SLOTS:
1355 request = (MainThreadRequest) msg.obj;
1356 int[] physicalSlots = (int[]) request.argument;
1357 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1358 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1359 break;
1360
1361 case EVENT_SWITCH_SLOTS_DONE:
1362 ar = (AsyncResult) msg.obj;
1363 request = (MainThreadRequest) ar.userObj;
1364 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001365 notifyRequester(request);
1366 break;
1367 case CMD_GET_NETWORK_SELECTION_MODE:
1368 request = (MainThreadRequest) msg.obj;
1369 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1370 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1371 break;
1372
1373 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1374 ar = (AsyncResult) msg.obj;
1375 request = (MainThreadRequest) ar.userObj;
1376 if (ar.exception != null) {
1377 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1378 } else {
1379 int mode = ((int[]) ar.result)[0];
1380 if (mode == 0) {
1381 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1382 } else {
1383 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1384 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001385 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001386 notifyRequester(request);
1387 break;
1388 case CMD_GET_CDMA_ROAMING_MODE:
1389 request = (MainThreadRequest) msg.obj;
1390 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1391 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1392 break;
1393 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1394 ar = (AsyncResult) msg.obj;
1395 request = (MainThreadRequest) ar.userObj;
1396 if (ar.exception != null) {
1397 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1398 } else {
1399 request.result = ((int[]) ar.result)[0];
1400 }
1401 notifyRequester(request);
1402 break;
1403 case CMD_SET_CDMA_ROAMING_MODE:
1404 request = (MainThreadRequest) msg.obj;
1405 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1406 int mode = (int) request.argument;
1407 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1408 break;
1409 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1410 ar = (AsyncResult) msg.obj;
1411 request = (MainThreadRequest) ar.userObj;
1412 request.result = ar.exception == null;
1413 notifyRequester(request);
1414 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001415 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1416 request = (MainThreadRequest) msg.obj;
1417 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1418 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1419 break;
1420 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1421 ar = (AsyncResult) msg.obj;
1422 request = (MainThreadRequest) ar.userObj;
1423 if (ar.exception != null) {
1424 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1425 } else {
1426 request.result = ((int[]) ar.result)[0];
1427 }
1428 notifyRequester(request);
1429 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001430 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1431 request = (MainThreadRequest) msg.obj;
1432 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1433 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001434 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1435 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001436 break;
1437 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1438 ar = (AsyncResult) msg.obj;
1439 request = (MainThreadRequest) ar.userObj;
1440 request.result = ar.exception == null;
1441 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001442 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001443 case CMD_GET_ALL_CELL_INFO:
1444 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001445 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001446 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001447 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001448 case EVENT_GET_ALL_CELL_INFO_DONE:
1449 ar = (AsyncResult) msg.obj;
1450 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001451 // If a timeout occurs, the response will be null
1452 request.result = (ar.exception == null && ar.result != null)
1453 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001454 synchronized (request) {
1455 request.notifyAll();
1456 }
1457 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001458 case CMD_REQUEST_CELL_INFO_UPDATE:
1459 request = (MainThreadRequest) msg.obj;
1460 request.phone.requestCellInfoUpdate(request.workSource,
1461 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1462 break;
1463 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1464 ar = (AsyncResult) msg.obj;
1465 request = (MainThreadRequest) ar.userObj;
1466 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1467 try {
1468 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001469 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001470 cb.onError(
1471 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1472 ar.exception.getClass().getName(),
1473 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001474 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001475 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001476 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001477 } else {
1478 // use the result as returned
1479 cb.onCellInfo((List<CellInfo>) ar.result);
1480 }
1481 } catch (RemoteException re) {
1482 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1483 }
1484 break;
Sarah Chincc055732020-11-18 13:39:35 -08001485 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001486 request = (MainThreadRequest) msg.obj;
1487 WorkSource ws = (WorkSource) request.argument;
1488 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001489 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001490 break;
Sarah Chincc055732020-11-18 13:39:35 -08001491 }
1492 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001493 ar = (AsyncResult) msg.obj;
1494 request = (MainThreadRequest) ar.userObj;
1495 if (ar.exception == null) {
1496 request.result = ar.result;
1497 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001498 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001499 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001500 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001501 }
1502
1503 synchronized (request) {
1504 request.notifyAll();
1505 }
1506 break;
Sarah Chincc055732020-11-18 13:39:35 -08001507 }
chen xu6dac5ab2018-10-26 17:39:23 -07001508 case CMD_MODEM_REBOOT:
1509 request = (MainThreadRequest) msg.obj;
1510 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001511 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001512 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001513 case EVENT_CMD_MODEM_REBOOT_DONE:
1514 handleNullReturnEvent(msg, "rebootModem");
1515 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001516 case CMD_REQUEST_ENABLE_MODEM:
1517 request = (MainThreadRequest) msg.obj;
1518 boolean enable = (boolean) request.argument;
1519 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001520 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001521 PhoneConfigurationManager.getInstance()
1522 .enablePhone(request.phone, enable, onCompleted);
1523 break;
1524 case EVENT_ENABLE_MODEM_DONE:
1525 ar = (AsyncResult) msg.obj;
1526 request = (MainThreadRequest) ar.userObj;
1527 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001528 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001529 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001530 if ((boolean) request.result) {
1531 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1532 updateModemStateMetrics();
1533 } else {
1534 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1535 + ar.exception);
1536 }
1537 notifyRequester(request);
1538 break;
1539 case CMD_GET_MODEM_STATUS:
1540 request = (MainThreadRequest) msg.obj;
1541 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1542 PhoneConfigurationManager.getInstance()
1543 .getPhoneStatusFromModem(request.phone, onCompleted);
1544 break;
1545 case EVENT_GET_MODEM_STATUS_DONE:
1546 ar = (AsyncResult) msg.obj;
1547 request = (MainThreadRequest) ar.userObj;
1548 int id = request.phone.getPhoneId();
1549 if (ar.exception == null && ar.result != null) {
1550 request.result = ar.result;
1551 //update the cache as modem status has changed
1552 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1553 (boolean) request.result);
1554 } else {
1555 // Return true if modem status cannot be retrieved. For most cases,
1556 // modem status is on. And for older version modems, GET_MODEM_STATUS
1557 // and disable modem are not supported. Modem is always on.
1558 // TODO: this should be fixed in R to support a third
1559 // status UNKNOWN b/131631629
1560 request.result = true;
1561 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1562 + ar.exception);
1563 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001564 notifyRequester(request);
1565 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001566 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1567 request = (MainThreadRequest) msg.obj;
1568 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1569 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1570 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1571 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1572 break;
1573 }
1574 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1575 ar = (AsyncResult) msg.obj;
1576 request = (MainThreadRequest) ar.userObj;
1577 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1578 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1579 args.second.accept(ar.exception == null);
1580 notifyRequester(request);
1581 break;
1582 }
Sarah Chincc055732020-11-18 13:39:35 -08001583 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1584 request = (MainThreadRequest) msg.obj;
1585 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1586 Phone phone = getPhoneFromRequest(request);
1587 if (phone != null) {
1588 phone.getSystemSelectionChannels(onCompleted);
1589 } else {
1590 loge("getSystemSelectionChannels: No phone object");
1591 request.result = new ArrayList<RadioAccessSpecifier>();
1592 notifyRequester(request);
1593 }
1594 break;
1595 }
1596 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1597 ar = (AsyncResult) msg.obj;
1598 request = (MainThreadRequest) ar.userObj;
1599 if (ar.exception == null && ar.result != null) {
1600 request.result = ar.result;
1601 } else {
1602 request.result = new IllegalArgumentException(
1603 "Failed to retrieve system selection channels");
1604 if (ar.result == null) {
1605 loge("getSystemSelectionChannels: Empty response");
1606 } else {
1607 loge("getSystemSelectionChannels: Unknown exception");
1608 }
1609 }
1610 notifyRequester(request);
1611 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001612 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1613 ar = (AsyncResult) msg.obj;
1614 request = (MainThreadRequest) ar.userObj;
1615 if (ar.exception == null && ar.result != null) {
1616 request.result = ar.result;
1617 } else {
1618 request.result = -1;
1619 loge("Failed to set Forbidden Plmns");
1620 if (ar.result == null) {
1621 loge("setForbidenPlmns: Empty response");
1622 } else if (ar.exception != null) {
1623 loge("setForbiddenPlmns: Exception: " + ar.exception);
1624 request.result = -1;
1625 } else {
1626 loge("setForbiddenPlmns: Unknown exception");
1627 }
1628 }
1629 notifyRequester(request);
1630 break;
1631 case CMD_SET_FORBIDDEN_PLMNS:
1632 request = (MainThreadRequest) msg.obj;
1633 uiccCard = getUiccCardFromRequest(request);
1634 if (uiccCard == null) {
1635 loge("setForbiddenPlmns: UiccCard is null");
1636 request.result = -1;
1637 notifyRequester(request);
1638 break;
1639 }
1640 Pair<Integer, List<String>> setFplmnsArgs =
1641 (Pair<Integer, List<String>>) request.argument;
1642 appType = setFplmnsArgs.first;
1643 List<String> fplmns = setFplmnsArgs.second;
1644 uiccApp = uiccCard.getApplicationByType(appType);
1645 if (uiccApp == null) {
1646 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1647 request.result = -1;
1648 loge("Failed to get UICC App");
1649 notifyRequester(request);
1650 } else {
1651 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1652 ((SIMRecords) uiccApp.getIccRecords())
1653 .setForbiddenPlmns(onCompleted, fplmns);
1654 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001655 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001656 case CMD_ERASE_MODEM_CONFIG:
1657 request = (MainThreadRequest) msg.obj;
1658 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1659 defaultPhone.eraseModemConfig(onCompleted);
1660 break;
1661 case EVENT_ERASE_MODEM_CONFIG_DONE:
1662 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001663 break;
zoey chenf95ca592019-12-30 16:11:23 +08001664
1665 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1666 request = (MainThreadRequest) msg.obj;
1667 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1668 Pair<String, String> changed = (Pair<String, String>) request.argument;
1669 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1670 changed.first, changed.second, onCompleted);
1671 break;
1672 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1673 ar = (AsyncResult) msg.obj;
1674 request = (MainThreadRequest) ar.userObj;
1675 if (ar.exception == null) {
1676 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1677 } else {
1678 request.result = msg.arg1;
1679 }
1680 notifyRequester(request);
1681 break;
1682
1683 case CMD_SET_ICC_LOCK_ENABLED:
1684 request = (MainThreadRequest) msg.obj;
1685 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1686 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1687 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1688 enabled.first, enabled.second, onCompleted);
1689 break;
1690 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1691 ar = (AsyncResult) msg.obj;
1692 request = (MainThreadRequest) ar.userObj;
1693 if (ar.exception == null) {
1694 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1695 } else {
1696 request.result = msg.arg1;
1697 }
1698 notifyRequester(request);
1699 break;
1700
Peter Wangdafb9ac2020-01-15 14:13:38 -08001701 case MSG_NOTIFY_USER_ACTIVITY:
1702 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001703 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001704 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1705 getDefaultPhone().getContext().sendBroadcastAsUser(
1706 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1707 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001708
1709 case CMD_SET_DATA_THROTTLING: {
1710 request = (MainThreadRequest) msg.obj;
1711 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1712 DataThrottlingRequest dataThrottlingRequest =
1713 (DataThrottlingRequest) request.argument;
1714 Phone phone = getPhoneFromRequest(request);
1715 if (phone != null) {
1716 phone.setDataThrottling(onCompleted,
1717 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1718 dataThrottlingRequest.getCompletionDurationMillis());
1719 } else {
1720 loge("setDataThrottling: No phone object");
1721 request.result =
1722 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1723 notifyRequester(request);
1724 }
1725
1726 break;
1727 }
1728 case EVENT_SET_DATA_THROTTLING_DONE:
1729 ar = (AsyncResult) msg.obj;
1730 request = (MainThreadRequest) ar.userObj;
1731
1732 if (ar.exception == null) {
1733 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1734 } else if (ar.exception instanceof CommandException) {
1735 loge("setDataThrottling: CommandException: " + ar.exception);
1736 CommandException.Error error =
1737 ((CommandException) (ar.exception)).getCommandError();
1738
1739 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1740 request.result = TelephonyManager
1741 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1742 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1743 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1744 } else {
1745 request.result =
1746 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1747 }
1748 } else {
1749 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1750 }
1751 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1752 notifyRequester(request);
1753 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001754
1755 case CMD_SET_SIM_POWER: {
1756 request = (MainThreadRequest) msg.obj;
1757 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1758 request = (MainThreadRequest) msg.obj;
1759 int stateToSet =
1760 ((Pair<Integer, IIntegerConsumer>)
1761 request.argument).first;
1762 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1763 break;
1764 }
1765 case EVENT_SET_SIM_POWER_DONE: {
1766 ar = (AsyncResult) msg.obj;
1767 request = (MainThreadRequest) ar.userObj;
1768 IIntegerConsumer callback =
1769 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1770 if (ar.exception != null) {
1771 loge("setSimPower exception: " + ar.exception);
1772 int errorCode = TelephonyManager.CallForwardingInfoCallback
1773 .RESULT_ERROR_UNKNOWN;
1774 if (ar.exception instanceof CommandException) {
1775 CommandException.Error error =
1776 ((CommandException) (ar.exception)).getCommandError();
1777 if (error == CommandException.Error.SIM_ERR) {
1778 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1779 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1780 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1781 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1782 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1783 } else {
1784 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1785 }
1786 }
1787 try {
1788 callback.accept(errorCode);
1789 } catch (RemoteException e) {
1790 // Ignore if the remote process is no longer available to call back.
1791 Log.w(LOG_TAG, "setSimPower: callback not available.");
1792 }
1793 } else {
1794 try {
1795 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1796 } catch (RemoteException e) {
1797 // Ignore if the remote process is no longer available to call back.
1798 Log.w(LOG_TAG, "setSimPower: callback not available.");
1799 }
1800 }
1801 break;
1802 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001803 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1804 request = (MainThreadRequest) msg.obj;
1805
1806 final Phone phone = getPhoneFromRequest(request);
1807 if (phone == null || phone.getServiceStateTracker() == null) {
1808 request.result = new IllegalStateException("Phone or SST is null");
1809 notifyRequester(request);
1810 break;
1811 }
1812
1813 Pair<Integer, SignalStrengthUpdateRequest> pair =
1814 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1815 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1816 request);
1817 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1818 request.subId, pair.first /*callingUid*/,
1819 pair.second /*request*/, onCompleted);
1820 break;
1821 }
1822 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1823 ar = (AsyncResult) msg.obj;
1824 request = (MainThreadRequest) ar.userObj;
1825 // request.result will be the exception of ar if present, true otherwise.
1826 // Be cautious not to leave result null which will wait() forever
1827 request.result = ar.exception != null ? ar.exception : true;
1828 notifyRequester(request);
1829 break;
1830 }
1831 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1832 request = (MainThreadRequest) msg.obj;
1833
1834 Phone phone = getPhoneFromRequest(request);
1835 if (phone == null || phone.getServiceStateTracker() == null) {
1836 request.result = new IllegalStateException("Phone or SST is null");
1837 notifyRequester(request);
1838 break;
1839 }
1840
1841 Pair<Integer, SignalStrengthUpdateRequest> pair =
1842 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1843 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1844 request);
1845 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1846 request.subId, pair.first /*callingUid*/,
1847 pair.second /*request*/, onCompleted);
1848 break;
1849 }
1850 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1851 ar = (AsyncResult) msg.obj;
1852 request = (MainThreadRequest) ar.userObj;
1853 request.result = ar.exception != null ? ar.exception : true;
1854 notifyRequester(request);
1855 break;
1856 }
Jordan Liud5366d92020-11-24 14:50:34 -08001857
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 default:
1859 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1860 break;
1861 }
1862 }
Jake Hambye994d462014-02-03 13:10:13 -08001863
Pengquan Menga1bb6272018-09-06 09:59:22 -07001864 private void notifyRequester(MainThreadRequest request) {
1865 synchronized (request) {
1866 request.notifyAll();
1867 }
1868 }
1869
Jake Hambye994d462014-02-03 13:10:13 -08001870 private void handleNullReturnEvent(Message msg, String command) {
1871 AsyncResult ar = (AsyncResult) msg.obj;
1872 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1873 if (ar.exception == null) {
1874 request.result = true;
1875 } else {
1876 request.result = false;
1877 if (ar.exception instanceof CommandException) {
1878 loge(command + ": CommandException: " + ar.exception);
1879 } else {
1880 loge(command + ": Unknown exception");
1881 }
1882 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001883 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001884 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 }
1886
1887 /**
1888 * Posts the specified command to be executed on the main thread,
1889 * waits for the request to complete, and returns the result.
1890 * @see #sendRequestAsync
1891 */
1892 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001893 return sendRequest(
1894 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001895 }
1896
1897 /**
1898 * Posts the specified command to be executed on the main thread,
1899 * waits for the request to complete, and returns the result.
1900 * @see #sendRequestAsync
1901 */
1902 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1903 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001904 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001905 }
1906
1907 /**
1908 * Posts the specified command to be executed on the main thread,
1909 * waits for the request to complete, and returns the result.
1910 * @see #sendRequestAsync
1911 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001912 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001913 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001914 }
1915
1916 /**
1917 * Posts the specified command to be executed on the main thread,
1918 * waits for the request to complete, and returns the result.
1919 * @see #sendRequestAsync
1920 */
Nathan Harold92bed182018-10-12 18:16:49 -07001921 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1922 return sendRequest(command, argument, subId, null, workSource);
1923 }
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, Phone phone, WorkSource workSource) {
1931 return sendRequest(
1932 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1933 }
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 */
1940 private Object sendRequest(
1941 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1943 throw new RuntimeException("This method will deadlock if called from the main thread.");
1944 }
1945
Nathan Harold92bed182018-10-12 18:16:49 -07001946 MainThreadRequest request = null;
1947 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1948 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1949 } else if (phone != null) {
1950 request = new MainThreadRequest(argument, phone, workSource);
1951 } else {
1952 request = new MainThreadRequest(argument, subId, workSource);
1953 }
1954
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 Message msg = mMainThreadHandler.obtainMessage(command, request);
1956 msg.sendToTarget();
1957
1958 // Wait for the request to complete
1959 synchronized (request) {
1960 while (request.result == null) {
1961 try {
1962 request.wait();
1963 } catch (InterruptedException e) {
1964 // Do nothing, go back and wait until the request is complete
1965 }
1966 }
1967 }
1968 return request.result;
1969 }
1970
1971 /**
1972 * Asynchronous ("fire and forget") version of sendRequest():
1973 * Posts the specified command to be executed on the main thread, and
1974 * returns immediately.
1975 * @see #sendRequest
1976 */
1977 private void sendRequestAsync(int command) {
1978 mMainThreadHandler.sendEmptyMessage(command);
1979 }
1980
1981 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001982 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001983 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001984 */
1985 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001986 sendRequestAsync(command, argument, null, null);
1987 }
1988
1989 /**
1990 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1991 * @see {@link #sendRequest(int,Object)}
1992 */
1993 private void sendRequestAsync(
1994 int command, Object argument, Phone phone, WorkSource workSource) {
1995 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001996 Message msg = mMainThreadHandler.obtainMessage(command, request);
1997 msg.sendToTarget();
1998 }
1999
2000 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002001 * Initialize the singleton PhoneInterfaceManager instance.
2002 * This is only done once, at startup, from PhoneApp.onCreate().
2003 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002004 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002005 synchronized (PhoneInterfaceManager.class) {
2006 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002007 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002008 } else {
2009 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2010 }
2011 return sInstance;
2012 }
2013 }
2014
2015 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002016 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002018 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08002019 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002020 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002021 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2022 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002023 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002024 mTelephonySharedPreferences =
2025 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002026 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002027 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002028 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002029
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 publish();
2031 }
2032
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002033 private Phone getDefaultPhone() {
2034 Phone thePhone = getPhone(getDefaultSubscription());
2035 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2036 }
2037
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002038 private void publish() {
2039 if (DBG) log("publish: " + this);
2040
Peter Wangc035ce42020-01-08 21:00:22 -08002041 TelephonyFrameworkInitializer
2042 .getTelephonyServiceManager()
2043 .getTelephonyServiceRegisterer()
2044 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045 }
2046
Stuart Scott584921c2015-01-15 17:10:34 -08002047 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002048 if (request.phone != null) {
2049 return request.phone;
2050 } else {
2051 return getPhoneFromSubId(request.subId);
2052 }
2053 }
2054
2055 private Phone getPhoneFromSubId(int subId) {
2056 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2057 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002058 }
2059
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002060 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2061 Phone phone = getPhoneFromRequest(request);
2062 return phone == null ? null :
2063 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2064 }
2065
Wink Saville36469e72014-06-11 15:17:00 -07002066 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002067 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002068 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002069 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002070
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002071 private void sendEraseModemConfig(Phone phone) {
2072 if (phone != null) {
2073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2074 mApp, phone.getSubId(), "eraseModemConfig");
2075 final long identity = Binder.clearCallingIdentity();
2076 try {
2077 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2078 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2079 } finally {
2080 Binder.restoreCallingIdentity(identity);
2081 }
2082 }
2083 }
2084
Peter Wang050bb052020-01-13 23:33:09 -08002085 private boolean isImsAvailableOnDevice() {
2086 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2087 if (pm == null) {
2088 // For some reason package manger is not available.. This will fail internally anyway,
2089 // so do not throw error and allow.
2090 return true;
2091 }
2092 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2093 }
2094
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002096 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002097 }
2098
Wink Savilleb564aae2014-10-23 10:18:09 -07002099 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 if (DBG) log("dial: " + number);
2101 // No permission check needed here: This is just a wrapper around the
2102 // ACTION_DIAL intent, which is available to any app since it puts up
2103 // the UI before it does anything.
2104
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002105 final long identity = Binder.clearCallingIdentity();
2106 try {
2107 String url = createTelUrl(number);
2108 if (url == null) {
2109 return;
2110 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002112 // PENDING: should we just silently fail if phone is offhook or ringing?
2113 PhoneConstants.State state = mCM.getState(subId);
2114 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2115 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2116 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2117 mApp.startActivity(intent);
2118 }
2119 } finally {
2120 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002121 }
2122 }
2123
2124 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002125 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002126 }
2127
Wink Savilleb564aae2014-10-23 10:18:09 -07002128 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002129 if (DBG) log("call: " + number);
2130
2131 // This is just a wrapper around the ACTION_CALL intent, but we still
2132 // need to do a permission check since we're calling startActivity()
2133 // from the context of the phone app.
2134 enforceCallPermission();
2135
Jordan Liu1617b712019-07-10 15:06:26 -07002136 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002137 != AppOpsManager.MODE_ALLOWED) {
2138 return;
2139 }
2140
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002141 final long identity = Binder.clearCallingIdentity();
2142 try {
2143 String url = createTelUrl(number);
2144 if (url == null) {
2145 return;
2146 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002148 boolean isValid = false;
2149 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2150 if (slist != null) {
2151 for (SubscriptionInfo subInfoRecord : slist) {
2152 if (subInfoRecord.getSubscriptionId() == subId) {
2153 isValid = true;
2154 break;
2155 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002156 }
Wink Saville08874612014-08-31 19:19:58 -07002157 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002158 if (!isValid) {
2159 return;
2160 }
Wink Saville08874612014-08-31 19:19:58 -07002161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002162 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2163 intent.putExtra(SUBSCRIPTION_KEY, subId);
2164 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2165 mApp.startActivity(intent);
2166 } finally {
2167 Binder.restoreCallingIdentity(identity);
2168 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 }
2170
Wink Savilleb564aae2014-10-23 10:18:09 -07002171 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002172 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002173 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2174 }
2175
Wink Savilleb564aae2014-10-23 10:18:09 -07002176 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002177 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002178 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2179 }
2180
Wink Savilleb564aae2014-10-23 10:18:09 -07002181 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002183
2184 final long identity = Binder.clearCallingIdentity();
2185 try {
2186 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2187 checkSimPin.start();
2188 return checkSimPin.unlockSim(null, pin);
2189 } finally {
2190 Binder.restoreCallingIdentity(identity);
2191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 }
2193
Wink Savilleb564aae2014-10-23 10:18:09 -07002194 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002196
2197 final long identity = Binder.clearCallingIdentity();
2198 try {
2199 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2200 checkSimPuk.start();
2201 return checkSimPuk.unlockSim(puk, pin);
2202 } finally {
2203 Binder.restoreCallingIdentity(identity);
2204 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002205 }
2206
2207 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002208 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002209 * a synchronous one.
2210 */
2211 private static class UnlockSim extends Thread {
2212
2213 private final IccCard mSimCard;
2214
2215 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002216 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2217 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002218
2219 // For replies from SimCard interface
2220 private Handler mHandler;
2221
2222 // For async handler to identify request type
2223 private static final int SUPPLY_PIN_COMPLETE = 100;
2224
2225 public UnlockSim(IccCard simCard) {
2226 mSimCard = simCard;
2227 }
2228
2229 @Override
2230 public void run() {
2231 Looper.prepare();
2232 synchronized (UnlockSim.this) {
2233 mHandler = new Handler() {
2234 @Override
2235 public void handleMessage(Message msg) {
2236 AsyncResult ar = (AsyncResult) msg.obj;
2237 switch (msg.what) {
2238 case SUPPLY_PIN_COMPLETE:
2239 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2240 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002241 mRetryCount = msg.arg1;
2242 if (ar.exception != null) {
2243 if (ar.exception instanceof CommandException &&
2244 ((CommandException)(ar.exception)).getCommandError()
2245 == CommandException.Error.PASSWORD_INCORRECT) {
2246 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002247 } //When UiccCardApp dispose,handle message and return exception
2248 else if (ar.exception instanceof CommandException &&
2249 ((CommandException) (ar.exception)).getCommandError()
2250 == CommandException.Error.ABORTED) {
2251 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002252 } else {
2253 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2254 }
2255 } else {
2256 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 mDone = true;
2259 UnlockSim.this.notifyAll();
2260 }
2261 break;
2262 }
2263 }
2264 };
2265 UnlockSim.this.notifyAll();
2266 }
2267 Looper.loop();
2268 }
2269
2270 /*
2271 * Use PIN or PUK to unlock SIM card
2272 *
2273 * If PUK is null, unlock SIM card with PIN
2274 *
2275 * If PUK is not null, unlock SIM card with PUK and set PIN code
2276 */
Wink Saville9de0f752013-10-22 19:04:03 -07002277 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278
2279 while (mHandler == null) {
2280 try {
2281 wait();
2282 } catch (InterruptedException e) {
2283 Thread.currentThread().interrupt();
2284 }
2285 }
2286 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2287
2288 if (puk == null) {
2289 mSimCard.supplyPin(pin, callback);
2290 } else {
2291 mSimCard.supplyPuk(puk, pin, callback);
2292 }
2293
2294 while (!mDone) {
2295 try {
2296 Log.d(LOG_TAG, "wait for done");
2297 wait();
2298 } catch (InterruptedException e) {
2299 // Restore the interrupted status
2300 Thread.currentThread().interrupt();
2301 }
2302 }
2303 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002304 int[] resultArray = new int[2];
2305 resultArray[0] = mResult;
2306 resultArray[1] = mRetryCount;
2307 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 }
2309 }
2310
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002311 /**
2312 * This method has been removed due to privacy and stability concerns.
2313 */
2314 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002316 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2317 return;
Wink Saville36469e72014-06-11 15:17:00 -07002318 }
2319
Nathan Harold1f889d82020-06-04 17:05:26 -07002320 @Override
2321 public void updateServiceLocationWithPackageName(String callingPackage) {
2322 mApp.getSystemService(AppOpsManager.class)
2323 .checkPackage(Binder.getCallingUid(), callingPackage);
2324
Nathan Haroldf096d982020-11-18 17:18:06 -08002325 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002326 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2327 // Callers targeting S have no business invoking this method.
2328 return;
2329 }
2330
2331 LocationAccessPolicy.LocationPermissionResult locationResult =
2332 LocationAccessPolicy.checkLocationPermission(mApp,
2333 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2334 .setCallingPackage(callingPackage)
2335 .setCallingFeatureId(null)
2336 .setCallingPid(Binder.getCallingPid())
2337 .setCallingUid(Binder.getCallingUid())
2338 .setMethod("updateServiceLocation")
2339 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2340 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2341 .build());
2342 // Apps that lack location permission have no business calling this method;
2343 // however, because no permission was declared in the public API, denials must
2344 // all be "soft".
2345 switch (locationResult) {
2346 case DENIED_HARD: /* fall through */
2347 case DENIED_SOFT:
2348 return;
2349 }
2350
2351 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002352 final long identity = Binder.clearCallingIdentity();
2353 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002354 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002355 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002356 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002357 }
2358 } finally {
2359 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002360 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361 }
2362
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002363 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002364 @Override
2365 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002366 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002367 }
2368
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002369
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002370 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002371 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2372 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2373 callingFeatureId);
2374 }
2375
2376 @Deprecated
2377 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002378 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002379 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2380 }
2381
2382 @Override
2383 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2384 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002385 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002386 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002387 return false;
2388 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002389
2390 final long identity = Binder.clearCallingIdentity();
2391 try {
2392 return isRadioOnForSubscriber(subId);
2393 } finally {
2394 Binder.restoreCallingIdentity(identity);
2395 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002396 }
2397
2398 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002399 final long identity = Binder.clearCallingIdentity();
2400 try {
2401 final Phone phone = getPhone(subId);
2402 if (phone != null) {
2403 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2404 } else {
2405 return false;
2406 }
2407 } finally {
2408 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002409 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 }
2411
2412 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002413 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002414 }
Wink Saville36469e72014-06-11 15:17:00 -07002415
Wink Savilleb564aae2014-10-23 10:18:09 -07002416 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002417 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002418
2419 final long identity = Binder.clearCallingIdentity();
2420 try {
2421 final Phone phone = getPhone(subId);
2422 if (phone != null) {
2423 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2424 }
2425 } finally {
2426 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002427 }
Wink Saville36469e72014-06-11 15:17:00 -07002428 }
2429
2430 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002431 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002432 }
2433
Wink Savilleb564aae2014-10-23 10:18:09 -07002434 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002435 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002436
2437 final long identity = Binder.clearCallingIdentity();
2438 try {
2439 final Phone phone = getPhone(subId);
2440 if (phone == null) {
2441 return false;
2442 }
2443 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2444 toggleRadioOnOffForSubscriber(subId);
2445 }
2446 return true;
2447 } finally {
2448 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002449 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 }
Wink Saville36469e72014-06-11 15:17:00 -07002451
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002452 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002453 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002454 /*
2455 * If any of the Radios are available, it will need to be
2456 * shutdown. So return true if any Radio is available.
2457 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002458 final long identity = Binder.clearCallingIdentity();
2459 try {
2460 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2461 Phone phone = PhoneFactory.getPhone(i);
2462 if (phone != null && phone.isRadioAvailable()) return true;
2463 }
2464 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2465 return false;
2466 } finally {
2467 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002468 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002469 }
2470
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002471 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002472 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002473 enforceModifyPermission();
2474
2475 final long identity = Binder.clearCallingIdentity();
2476 try {
2477 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2478 logv("Shutting down Phone " + i);
2479 shutdownRadioUsingPhoneId(i);
2480 }
2481 } finally {
2482 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002483 }
2484 }
2485
2486 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002487 Phone phone = PhoneFactory.getPhone(phoneId);
2488 if (phone != null && phone.isRadioAvailable()) {
2489 phone.shutdownRadio();
2490 }
2491 }
2492
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002494 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002495
2496 final long identity = Binder.clearCallingIdentity();
2497 try {
2498 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2499 if (defaultPhone != null) {
2500 defaultPhone.setRadioPower(turnOn);
2501 return true;
2502 } else {
2503 loge("There's no default phone.");
2504 return false;
2505 }
2506 } finally {
2507 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002508 }
Wink Saville36469e72014-06-11 15:17:00 -07002509 }
2510
Wink Savilleb564aae2014-10-23 10:18:09 -07002511 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002512 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513
2514 final long identity = Binder.clearCallingIdentity();
2515 try {
2516 final Phone phone = getPhone(subId);
2517 if (phone != null) {
2518 phone.setRadioPower(turnOn);
2519 return true;
2520 } else {
2521 return false;
2522 }
2523 } finally {
2524 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002526 }
2527
Wink Saville36469e72014-06-11 15:17:00 -07002528 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002529 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002530 public boolean enableDataConnectivity() {
2531 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002532
2533 final long identity = Binder.clearCallingIdentity();
2534 try {
2535 int subId = mSubscriptionController.getDefaultDataSubId();
2536 final Phone phone = getPhone(subId);
2537 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002538 phone.getDataEnabledSettings().setDataEnabled(
2539 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002540 return true;
2541 } else {
2542 return false;
2543 }
2544 } finally {
2545 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002546 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002547 }
2548
Wink Saville36469e72014-06-11 15:17:00 -07002549 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002550 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002551 public boolean disableDataConnectivity() {
2552 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002553
2554 final long identity = Binder.clearCallingIdentity();
2555 try {
2556 int subId = mSubscriptionController.getDefaultDataSubId();
2557 final Phone phone = getPhone(subId);
2558 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002559 phone.getDataEnabledSettings().setDataEnabled(
2560 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002561 return true;
2562 } else {
2563 return false;
2564 }
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 }
2569
Sanket Padawe356d7632015-06-22 14:03:32 -07002570 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002571 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002572 final long identity = Binder.clearCallingIdentity();
2573 try {
2574 final Phone phone = getPhone(subId);
2575 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002576 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002577 } else {
2578 return false;
2579 }
2580 } finally {
2581 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583 }
2584
2585 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002586 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002587 }
2588
pkanwarae03a6b2016-11-06 20:37:09 -08002589 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002590 enforceCallPermission();
2591
2592 final long identity = Binder.clearCallingIdentity();
2593 try {
2594 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2595 return;
2596 }
2597 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2598 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2599 } finally {
2600 Binder.restoreCallingIdentity(identity);
2601 }
pkanwar32d516d2016-10-14 19:37:38 -07002602 };
2603
Wink Savilleb564aae2014-10-23 10:18:09 -07002604 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002605 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002606
2607 final long identity = Binder.clearCallingIdentity();
2608 try {
2609 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2610 return false;
2611 }
2612 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2613 } finally {
2614 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002615 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002616 }
2617
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002619 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002620 }
2621
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002622 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 final long identity = Binder.clearCallingIdentity();
2624 try {
2625 Phone phone = PhoneFactory.getPhone(slotIndex);
2626 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2627 PhoneConstantConversions.convertCallState(phone.getState());
2628 } finally {
2629 Binder.restoreCallingIdentity(identity);
2630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002631 }
2632
Sanket Padawe356d7632015-06-22 14:03:32 -07002633 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002634 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002635 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2636 }
2637
2638 @Override
2639 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640 final long identity = Binder.clearCallingIdentity();
2641 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002642 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643 if (phone != null) {
2644 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2645 } else {
2646 return PhoneConstantConversions.convertDataState(
2647 PhoneConstants.DataState.DISCONNECTED);
2648 }
2649 } finally {
2650 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002652 }
2653
Sanket Padawe356d7632015-06-22 14:03:32 -07002654 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002655 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002656 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2657 }
2658
2659 @Override
2660 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661 final long identity = Binder.clearCallingIdentity();
2662 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002663 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002664 if (phone != null) {
2665 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2666 } else {
2667 return TelephonyManager.DATA_ACTIVITY_NONE;
2668 }
2669 } finally {
2670 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002671 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002672 }
2673
2674 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002675 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002676 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002677 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002678
2679 LocationAccessPolicy.LocationPermissionResult locationResult =
2680 LocationAccessPolicy.checkLocationPermission(mApp,
2681 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2682 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002683 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002684 .setCallingPid(Binder.getCallingPid())
2685 .setCallingUid(Binder.getCallingUid())
2686 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002687 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002688 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2689 .build());
2690 switch (locationResult) {
2691 case DENIED_HARD:
2692 throw new SecurityException("Not allowed to access cell location");
2693 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002694 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2695 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002696 }
2697
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002698 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002699 final long identity = Binder.clearCallingIdentity();
2700 try {
2701 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002702 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002703 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002704 } finally {
2705 Binder.restoreCallingIdentity(identity);
2706 }
Svetoslav64fad262015-04-14 14:35:21 -07002707 }
2708
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002709 @Override
Jack Yu01425032020-02-22 19:38:58 -08002710 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002711 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2712 // registered cell info, so return a NULL country instead.
2713 final long identity = Binder.clearCallingIdentity();
2714 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002715 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2716 // Get default phone in this case.
2717 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2718 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002719 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002721 if (phone == null) return "";
2722 ServiceStateTracker sst = phone.getServiceStateTracker();
2723 if (sst == null) return "";
2724 LocaleTracker lt = sst.getLocaleTracker();
2725 if (lt == null) return "";
2726 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2727 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2728 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002729 } finally {
2730 Binder.restoreCallingIdentity(identity);
2731 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002732 }
2733
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002734 /**
2735 * This method was removed due to potential issues caused by performing partial
2736 * updates of service state, and lack of a credible use case.
2737 *
2738 * This has the ability to break the telephony implementation by disabling notification of
2739 * changes in device connectivity. DO NOT USE THIS!
2740 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002741 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 public void enableLocationUpdates() {
2743 mApp.enforceCallingOrSelfPermission(
2744 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745 }
2746
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002747 /**
2748 * This method was removed due to potential issues caused by performing partial
2749 * updates of service state, and lack of a credible use case.
2750 *
2751 * This has the ability to break the telephony implementation by disabling notification of
2752 * changes in device connectivity. DO NOT USE THIS!
2753 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002754 @Override
2755 public void disableLocationUpdates() {
2756 mApp.enforceCallingOrSelfPermission(
2757 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002758 }
2759
2760 @Override
2761 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002762 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2763 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002764 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002765 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2766 throw new SecurityException(
2767 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2768 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002769
Jordan Liu1617b712019-07-10 15:06:26 -07002770 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002771 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2772 return null;
2773 }
Svetoslav64fad262015-04-14 14:35:21 -07002774
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002775 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002777 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002778 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779
Nathan Haroldf180aac2018-06-01 18:43:55 -07002780 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2781 for (CellInfo ci : info) {
2782 if (ci instanceof CellInfoGsm) {
2783 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2784 } else if (ci instanceof CellInfoWcdma) {
2785 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2786 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002787 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002788 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002789 }
2790
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002791 private List<CellInfo> getCachedCellInfo() {
2792 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2793 for (Phone phone : PhoneFactory.getPhones()) {
2794 List<CellInfo> info = phone.getAllCellInfo();
2795 if (info != null) cellInfos.addAll(info);
2796 }
2797 return cellInfos;
2798 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002799
2800 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002801 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002802 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002803 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002804
2805 LocationAccessPolicy.LocationPermissionResult locationResult =
2806 LocationAccessPolicy.checkLocationPermission(mApp,
2807 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2808 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002809 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002810 .setCallingPid(Binder.getCallingPid())
2811 .setCallingUid(Binder.getCallingUid())
2812 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002813 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002814 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2815 .build());
2816 switch (locationResult) {
2817 case DENIED_HARD:
2818 throw new SecurityException("Not allowed to access cell info");
2819 case DENIED_SOFT:
2820 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002821 }
2822
Nathan Haroldf096d982020-11-18 17:18:06 -08002823 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002824 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2825 return getCachedCellInfo();
2826 }
2827
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002828 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002829 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002830 final long identity = Binder.clearCallingIdentity();
2831 try {
2832 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2833 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002834 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002835 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002836 if (info != null) cellInfos.addAll(info);
2837 }
2838 return cellInfos;
2839 } finally {
2840 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002841 }
2842 }
2843
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002844 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002845 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2846 String callingFeatureId) {
2847 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2848 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002849 }
2850
2851 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002852 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2853 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002854 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002855 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002856 }
2857
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002858 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2859 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002860 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002861 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002862
2863 LocationAccessPolicy.LocationPermissionResult locationResult =
2864 LocationAccessPolicy.checkLocationPermission(mApp,
2865 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2866 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002867 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002868 .setCallingPid(Binder.getCallingPid())
2869 .setCallingUid(Binder.getCallingUid())
2870 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002871 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2872 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002873 .build());
2874 switch (locationResult) {
2875 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002876 if (TelephonyPermissions
2877 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002878 // Safetynet logging for b/154934934
2879 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2880 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002881 throw new SecurityException("Not allowed to access cell info");
2882 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002883 if (TelephonyPermissions
2884 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002885 // Safetynet logging for b/154934934
2886 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2887 }
Nathan Harold5320c422019-05-09 10:26:08 -07002888 try {
2889 cb.onCellInfo(new ArrayList<CellInfo>());
2890 } catch (RemoteException re) {
2891 // Drop without consequences
2892 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002893 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002894 }
2895
Nathan Harolda939a962019-05-09 10:13:47 -07002896
2897 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002898 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2899
2900 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2901 }
2902
2903 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002904 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002905 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002906 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907
2908 final long identity = Binder.clearCallingIdentity();
2909 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002910 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002911 } finally {
2912 Binder.restoreCallingIdentity(identity);
2913 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002914 }
2915
Shishir Agrawala9f32182016-04-12 12:00:16 -07002916 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002917 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002918 Phone phone = PhoneFactory.getPhone(slotIndex);
2919 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002920 return null;
2921 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002922 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002923 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002924 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002925 return null;
2926 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002927
2928 final long identity = Binder.clearCallingIdentity();
2929 try {
2930 return phone.getImei();
2931 } finally {
2932 Binder.restoreCallingIdentity(identity);
2933 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002934 }
2935
2936 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002937 public String getTypeAllocationCodeForSlot(int slotIndex) {
2938 Phone phone = PhoneFactory.getPhone(slotIndex);
2939 String tac = null;
2940 if (phone != null) {
2941 String imei = phone.getImei();
2942 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2943 }
2944 return tac;
2945 }
2946
2947 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002948 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002949 Phone phone = PhoneFactory.getPhone(slotIndex);
2950 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002951 return null;
2952 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002953
Jeff Davidson913390f2018-02-23 17:11:49 -08002954 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002955 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002956 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002957 return null;
2958 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002959
2960 final long identity = Binder.clearCallingIdentity();
2961 try {
2962 return phone.getMeid();
2963 } finally {
2964 Binder.restoreCallingIdentity(identity);
2965 }
Jack Yu2af8d712017-03-15 17:14:14 -07002966 }
2967
2968 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002969 public String getManufacturerCodeForSlot(int slotIndex) {
2970 Phone phone = PhoneFactory.getPhone(slotIndex);
2971 String manufacturerCode = null;
2972 if (phone != null) {
2973 String meid = phone.getMeid();
2974 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2975 }
2976 return manufacturerCode;
2977 }
2978
2979 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002980 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2981 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002982 Phone phone = PhoneFactory.getPhone(slotIndex);
2983 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002984 return null;
2985 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002986 int subId = phone.getSubId();
2987 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002988 mApp, subId, callingPackage, callingFeatureId,
2989 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002990 return null;
2991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002992
2993 final long identity = Binder.clearCallingIdentity();
2994 try {
2995 return phone.getDeviceSvn();
2996 } finally {
2997 Binder.restoreCallingIdentity(identity);
2998 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002999 }
3000
fionaxu43304da2017-11-27 22:51:16 -08003001 @Override
3002 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003 final long identity = Binder.clearCallingIdentity();
3004 try {
3005 final Phone phone = getPhone(subId);
3006 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3007 } finally {
3008 Binder.restoreCallingIdentity(identity);
3009 }
fionaxu43304da2017-11-27 22:51:16 -08003010 }
3011
3012 @Override
3013 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003014 final long identity = Binder.clearCallingIdentity();
3015 try {
3016 final Phone phone = getPhone(subId);
3017 return phone == null ? null : phone.getCarrierName();
3018 } finally {
3019 Binder.restoreCallingIdentity(identity);
3020 }
fionaxu43304da2017-11-27 22:51:16 -08003021 }
3022
calvinpanffe225e2018-11-01 19:43:06 +08003023 @Override
chen xu0026ca62019-03-06 15:28:50 -08003024 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003025 final long identity = Binder.clearCallingIdentity();
3026 try {
3027 final Phone phone = getPhone(subId);
3028 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003029 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003030 } finally {
3031 Binder.restoreCallingIdentity(identity);
3032 }
3033 }
3034
3035 @Override
chen xu0026ca62019-03-06 15:28:50 -08003036 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003037 final long identity = Binder.clearCallingIdentity();
3038 try {
3039 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003040 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
3044 }
3045
chen xu651eec72018-11-11 19:03:44 -08003046 @Override
chen xu864e11c2018-12-06 22:10:03 -08003047 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3048 if (!isSubscriptionMccMnc) {
3049 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3050 }
chen xu651eec72018-11-11 19:03:44 -08003051 final Phone phone = PhoneFactory.getPhone(slotIndex);
3052 if (phone == null) {
3053 return TelephonyManager.UNKNOWN_CARRIER_ID;
3054 }
3055 final long identity = Binder.clearCallingIdentity();
3056 try {
3057 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3058 } finally {
3059 Binder.restoreCallingIdentity(identity);
3060 }
3061 }
3062
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003063 //
3064 // Internal helper methods.
3065 //
3066
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003067 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003068 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3069 *
3070 * @throws SecurityException if the caller does not have the required permission
3071 */
3072 private void enforceModifyPermission() {
3073 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3074 }
3075
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003076 /**
3077 * Make sure the caller is system.
3078 *
3079 * @throws SecurityException if the caller is not system.
3080 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003081 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003082 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3083 throw new SecurityException("Caller must be system");
3084 }
3085 }
3086
Shuo Qianf2b2df42019-11-13 17:43:31 -08003087 private void enforceActiveEmergencySessionPermission() {
3088 mApp.enforceCallingOrSelfPermission(
3089 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3090 }
3091
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003092 /**
3093 * Make sure the caller has the CALL_PHONE permission.
3094 *
3095 * @throws SecurityException if the caller does not have the required permission
3096 */
3097 private void enforceCallPermission() {
3098 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3099 }
3100
paulhu423b5f22019-08-23 19:17:33 +08003101 private void enforceSettingsPermission() {
3102 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003103 }
3104
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003105 private String createTelUrl(String number) {
3106 if (TextUtils.isEmpty(number)) {
3107 return null;
3108 }
3109
Jake Hambye994d462014-02-03 13:10:13 -08003110 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003111 }
3112
Ihab Awadf9e92732013-12-05 18:02:52 -08003113 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003114 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3115 }
3116
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003117 private static void logv(String msg) {
3118 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3119 }
3120
Ihab Awadf9e92732013-12-05 18:02:52 -08003121 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003122 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3123 }
3124
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003125 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003126 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003127 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003128 }
3129
Sanket Padawe356d7632015-06-22 14:03:32 -07003130 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003131 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003132 final long identity = Binder.clearCallingIdentity();
3133 try {
3134 final Phone phone = PhoneFactory.getPhone(slotIndex);
3135 if (phone == null) {
3136 return PhoneConstants.PHONE_TYPE_NONE;
3137 } else {
3138 return phone.getPhoneType();
3139 }
3140 } finally {
3141 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003142 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003143 }
3144
3145 /**
3146 * Returns the CDMA ERI icon index to display
3147 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003148 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003149 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3150 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3151 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003152 }
3153
Sanket Padawe356d7632015-06-22 14:03:32 -07003154 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003155 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3156 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003157 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003158 mApp, subId, callingPackage, callingFeatureId,
3159 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003160 return -1;
3161 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003162
3163 final long identity = Binder.clearCallingIdentity();
3164 try {
3165 final Phone phone = getPhone(subId);
3166 if (phone != null) {
3167 return phone.getCdmaEriIconIndex();
3168 } else {
3169 return -1;
3170 }
3171 } finally {
3172 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003173 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003174 }
3175
3176 /**
3177 * Returns the CDMA ERI icon mode,
3178 * 0 - ON
3179 * 1 - FLASHING
3180 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003181 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003182 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3183 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3184 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003185 }
3186
Sanket Padawe356d7632015-06-22 14:03:32 -07003187 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003188 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3189 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003190 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003191 mApp, subId, callingPackage, callingFeatureId,
3192 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003193 return -1;
3194 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003195
3196 final long identity = Binder.clearCallingIdentity();
3197 try {
3198 final Phone phone = getPhone(subId);
3199 if (phone != null) {
3200 return phone.getCdmaEriIconMode();
3201 } else {
3202 return -1;
3203 }
3204 } finally {
3205 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003206 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003207 }
3208
3209 /**
3210 * Returns the CDMA ERI text,
3211 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003212 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003213 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3214 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3215 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003216 }
3217
Sanket Padawe356d7632015-06-22 14:03:32 -07003218 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003219 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3220 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003221 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003222 mApp, subId, callingPackage, callingFeatureId,
3223 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003224 return null;
3225 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003226
3227 final long identity = Binder.clearCallingIdentity();
3228 try {
3229 final Phone phone = getPhone(subId);
3230 if (phone != null) {
3231 return phone.getCdmaEriText();
3232 } else {
3233 return null;
3234 }
3235 } finally {
3236 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003237 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003238 }
3239
3240 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003241 * Returns the CDMA MDN.
3242 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003243 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003244 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3246 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003247
3248 final long identity = Binder.clearCallingIdentity();
3249 try {
3250 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003251 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003252 return phone.getLine1Number();
3253 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003254 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003255 return null;
3256 }
3257 } finally {
3258 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003259 }
3260 }
3261
3262 /**
3263 * Returns the CDMA MIN.
3264 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003265 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003266 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3268 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003269
3270 final long identity = Binder.clearCallingIdentity();
3271 try {
3272 final Phone phone = getPhone(subId);
3273 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3274 return phone.getCdmaMin();
3275 } else {
3276 return null;
3277 }
3278 } finally {
3279 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003280 }
3281 }
3282
Hall Liud892bec2018-11-30 14:51:45 -08003283 @Override
3284 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3285 INumberVerificationCallback callback, String callingPackage) {
3286 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3287 != PERMISSION_GRANTED) {
3288 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3289 }
3290 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3291
3292 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3293 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003294 throw new SecurityException("Calling package must be configured in the device config: "
3295 + "calling package: " + callingPackage
3296 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003297 }
3298
3299 if (range == null) {
3300 throw new NullPointerException("Range must be non-null");
3301 }
3302
3303 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003304 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003305
3306 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3307 }
3308
Junda Liuca05d5d2014-08-14 22:36:34 -07003309 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003310 * Returns true if CDMA provisioning needs to run.
3311 */
3312 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003313 final long identity = Binder.clearCallingIdentity();
3314 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003315 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003316 } finally {
3317 Binder.restoreCallingIdentity(identity);
3318 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003319 }
3320
3321 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003322 * Sets the voice mail number of a given subId.
3323 */
3324 @Override
3325 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003326 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3327 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003328
3329 final long identity = Binder.clearCallingIdentity();
3330 try {
3331 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3332 new Pair<String, String>(alphaTag, number), new Integer(subId));
3333 return success;
3334 } finally {
3335 Binder.restoreCallingIdentity(identity);
3336 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003337 }
3338
Ta-wei Yen87c49842016-05-13 21:19:52 -07003339 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003340 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3341 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003342 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3343 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003344 if (!TextUtils.equals(callingPackage, systemDialer)) {
3345 throw new SecurityException("caller must be system dialer");
3346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347
3348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3351 if (phoneAccountHandle == null) {
3352 return null;
3353 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003354 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003355 } finally {
3356 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003357 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003358 }
3359
3360 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003361 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3362 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003363 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003364 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003365 mApp, subId, callingPackage, callingFeatureId,
3366 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003367 return null;
3368 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003369
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003370 final long identity = Binder.clearCallingIdentity();
3371 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003372 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003373 } finally {
3374 Binder.restoreCallingIdentity(identity);
3375 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003376 }
3377
3378 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003379 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3380 VisualVoicemailSmsFilterSettings settings) {
3381 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003382
3383 final long identity = Binder.clearCallingIdentity();
3384 try {
3385 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003386 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003387 } finally {
3388 Binder.restoreCallingIdentity(identity);
3389 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003390 }
3391
3392 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003393 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3394 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003395
3396 final long identity = Binder.clearCallingIdentity();
3397 try {
3398 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003399 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003400 } finally {
3401 Binder.restoreCallingIdentity(identity);
3402 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003403 }
3404
3405 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003406 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3407 String callingPackage, int subId) {
3408 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003409
3410 final long identity = Binder.clearCallingIdentity();
3411 try {
3412 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003413 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003414 } finally {
3415 Binder.restoreCallingIdentity(identity);
3416 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003417 }
3418
3419 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003420 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003421 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003422
3423 final long identity = Binder.clearCallingIdentity();
3424 try {
3425 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003426 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003427 } finally {
3428 Binder.restoreCallingIdentity(identity);
3429 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003430 }
3431
3432 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003433 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3434 String callingAttributionTag, int subId, String number, int port, String text,
3435 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003436 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003437 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003438 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003439 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003440 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3441 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003442 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003443
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003444 /**
fionaxu0152e512016-11-14 13:36:14 -08003445 * Sets the voice activation state of a given subId.
3446 */
3447 @Override
3448 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3450 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003451
3452 final long identity = Binder.clearCallingIdentity();
3453 try {
3454 final Phone phone = getPhone(subId);
3455 if (phone != null) {
3456 phone.setVoiceActivationState(activationState);
3457 } else {
3458 loge("setVoiceActivationState fails with invalid subId: " + subId);
3459 }
3460 } finally {
3461 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003462 }
3463 }
3464
3465 /**
3466 * Sets the data activation state of a given subId.
3467 */
3468 @Override
3469 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003470 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3471 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003472
3473 final long identity = Binder.clearCallingIdentity();
3474 try {
3475 final Phone phone = getPhone(subId);
3476 if (phone != null) {
3477 phone.setDataActivationState(activationState);
3478 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003479 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003480 }
3481 } finally {
3482 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003483 }
3484 }
3485
3486 /**
3487 * Returns the voice activation state of a given subId.
3488 */
3489 @Override
3490 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003491 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003492
fionaxu0152e512016-11-14 13:36:14 -08003493 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003494 final long identity = Binder.clearCallingIdentity();
3495 try {
3496 if (phone != null) {
3497 return phone.getVoiceActivationState();
3498 } else {
3499 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3500 }
3501 } finally {
3502 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003503 }
3504 }
3505
3506 /**
3507 * Returns the data activation state of a given subId.
3508 */
3509 @Override
3510 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003511 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003512
fionaxu0152e512016-11-14 13:36:14 -08003513 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003514 final long identity = Binder.clearCallingIdentity();
3515 try {
3516 if (phone != null) {
3517 return phone.getDataActivationState();
3518 } else {
3519 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3520 }
3521 } finally {
3522 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003523 }
3524 }
3525
3526 /**
Wink Saville36469e72014-06-11 15:17:00 -07003527 * Returns the unread count of voicemails for a subId
3528 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003529 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003530 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3531 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003532 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003533 mApp, subId, callingPackage, callingFeatureId,
3534 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003535 return 0;
3536 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003537 final long identity = Binder.clearCallingIdentity();
3538 try {
3539 final Phone phone = getPhone(subId);
3540 if (phone != null) {
3541 return phone.getVoiceMessageCount();
3542 } else {
3543 return 0;
3544 }
3545 } finally {
3546 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003548 }
3549
3550 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003551 * returns true, if the device is in a state where both voice and data
3552 * are supported simultaneously. This can change based on location or network condition.
3553 */
3554 @Override
3555 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003556 final long identity = Binder.clearCallingIdentity();
3557 try {
3558 final Phone phone = getPhone(subId);
3559 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3560 } finally {
3561 Binder.restoreCallingIdentity(identity);
3562 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003563 }
3564
3565 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003566 * Send the dialer code if called from the current default dialer or the caller has
3567 * carrier privilege.
3568 * @param inputCode The dialer code to send
3569 */
3570 @Override
3571 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003572 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003573 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003574 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3575 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003576 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003577 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003578 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003579 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003580
3581 final long identity = Binder.clearCallingIdentity();
3582 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003583 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003584 } finally {
3585 Binder.restoreCallingIdentity(identity);
3586 }
fionaxu235cc5e2017-03-06 22:25:57 -08003587 }
3588
Pengquan Menga1bb6272018-09-06 09:59:22 -07003589 @Override
3590 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003591 TelephonyPermissions
3592 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3593 mApp, subId, "getNetworkSelectionMode");
3594 final long identity = Binder.clearCallingIdentity();
3595 try {
3596 if (!isActiveSubscription(subId)) {
3597 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3598 }
3599 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3600 } finally {
3601 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003602 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003603 }
3604
Brad Ebinger35c841c2018-10-01 10:40:55 -07003605 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003606 public boolean isInEmergencySmsMode() {
3607 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3608 final long identity = Binder.clearCallingIdentity();
3609 try {
3610 for (Phone phone : PhoneFactory.getPhones()) {
3611 if (phone.isInEmergencySmsMode()) {
3612 return true;
3613 }
3614 }
3615 } finally {
3616 Binder.restoreCallingIdentity(identity);
3617 }
3618 return false;
3619 }
3620
shilu366312e2019-12-17 09:28:10 -08003621 /**
3622 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3623 * @param subId The subscription to use to check the configuration.
3624 * @param c The callback that will be used to send the result.
3625 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003626 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003627 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3628 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003629 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3630 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003631
Brad Ebinger77b832e2019-10-17 17:03:22 -07003632 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3633 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3634 "IMS not available on device.");
3635 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003636 final long token = Binder.clearCallingIdentity();
3637 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003638 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003639 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003640 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003641 } catch (ImsException e) {
3642 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003643 } finally {
3644 Binder.restoreCallingIdentity(token);
3645 }
3646 }
3647
shilu366312e2019-12-17 09:28:10 -08003648 /**
3649 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3650 * @param subId The subscription to use to check the configuration.
3651 * @param c The callback that will be used to send the result.
3652 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003653 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003654 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003655 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3656 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003657 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3658 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3659 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003660 final long token = Binder.clearCallingIdentity();
3661 try {
3662 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3663 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3664 .removeRegistrationCallbackForSubscription(c, subId);
3665 } catch (ImsException e) {
3666 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3667 + "is inactive, ignoring unregister.");
3668 // If the subscription is no longer active, just return, since the callback
3669 // will already have been removed internally.
3670 } finally {
3671 Binder.restoreCallingIdentity(token);
3672 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003673 }
3674
Brad Ebinger774ba362019-10-22 17:36:18 -07003675 /**
3676 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3677 */
3678 @Override
3679 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3680 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3681 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3682 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3683 "IMS not available on device.");
3684 }
3685 final long token = Binder.clearCallingIdentity();
3686 try {
3687 Phone phone = getPhone(subId);
3688 if (phone == null) {
3689 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3690 + subId + "'");
3691 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3692 }
3693 phone.getImsRegistrationState(regState -> {
3694 try {
3695 consumer.accept((regState == null)
3696 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3697 } catch (RemoteException e) {
3698 // Ignore if the remote process is no longer available to call back.
3699 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3700 }
3701 });
3702 } finally {
3703 Binder.restoreCallingIdentity(token);
3704 }
3705 }
3706
3707 /**
3708 * Get the transport type for the IMS service registration state.
3709 */
3710 @Override
3711 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003712 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3713 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003714 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3715 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3716 "IMS not available on device.");
3717 }
3718 final long token = Binder.clearCallingIdentity();
3719 try {
3720 Phone phone = getPhone(subId);
3721 if (phone == null) {
3722 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3723 + subId + "'");
3724 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3725 }
3726 phone.getImsRegistrationTech(regTech -> {
3727 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3728 int regTechConverted = (regTech == null)
3729 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3730 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3731 regTechConverted);
3732 try {
3733 consumer.accept(regTechConverted);
3734 } catch (RemoteException e) {
3735 // Ignore if the remote process is no longer available to call back.
3736 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3737 }
3738 });
3739 } finally {
3740 Binder.restoreCallingIdentity(token);
3741 }
3742 }
3743
shilu366312e2019-12-17 09:28:10 -08003744 /**
3745 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3746 * @param subId The subscription to use to check the configuration.
3747 * @param c The callback that will be used to send the result.
3748 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003749 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003750 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3751 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003752 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3753 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003754 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3755 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3756 "IMS not available on device.");
3757 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003758 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3759 final long token = Binder.clearCallingIdentity();
3760 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003761 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003762 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003763 } catch (ImsException e) {
3764 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003765 } finally {
3766 Binder.restoreCallingIdentity(token);
3767 }
3768 }
3769
shilu366312e2019-12-17 09:28:10 -08003770 /**
3771 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3772 * @param subId The subscription to use to check the configuration.
3773 * @param c The callback that will be used to send the result.
3774 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003775 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003776 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003777 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3778 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003779 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3780 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3781 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003782
3783 final long token = Binder.clearCallingIdentity();
3784 try {
3785 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3786 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003787 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003788 } catch (ImsException e) {
3789 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3790 + "is inactive, ignoring unregister.");
3791 // If the subscription is no longer active, just return, since the callback
3792 // will already have been removed internally.
3793 } finally {
3794 Binder.restoreCallingIdentity(token);
3795 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003796 }
3797
3798 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003799 public boolean isCapable(int subId, int capability, int regTech) {
3800 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003801 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3802 final long token = Binder.clearCallingIdentity();
3803 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003804 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003805 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003806 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003807 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3808 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003809 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003810 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3811 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003812 } finally {
3813 Binder.restoreCallingIdentity(token);
3814 }
3815 }
3816
3817 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003818 public boolean isAvailable(int subId, int capability, int regTech) {
3819 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003820 final long token = Binder.clearCallingIdentity();
3821 try {
3822 Phone phone = getPhone(subId);
3823 if (phone == null) return false;
3824 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003825 } catch (com.android.ims.ImsException e) {
3826 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3827 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003828 } finally {
3829 Binder.restoreCallingIdentity(token);
3830 }
3831 }
3832
Brad Ebinger77b832e2019-10-17 17:03:22 -07003833 /**
3834 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3835 * subscription.
3836 * @param subId The subscription to use to check the configuration.
3837 * @param callback The callback that will be used to send the result.
3838 * @param capability The MmTelFeature capability that will be used to send the result.
3839 * @param transportType The transport type of the MmTelFeature capability.
3840 */
3841 @Override
3842 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3843 int transportType) {
3844 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3845 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3846 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3847 "IMS not available on device.");
3848 }
3849 final long token = Binder.clearCallingIdentity();
3850 try {
3851 int slotId = getSlotIndex(subId);
3852 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3853 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3854 + subId + "'");
3855 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3856 }
3857 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3858 transportType, aBoolean -> {
3859 try {
3860 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3861 } catch (RemoteException e) {
3862 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3863 + "running. Ignore");
3864 }
3865 });
3866 } finally {
3867 Binder.restoreCallingIdentity(token);
3868 }
3869 }
3870
shilu366312e2019-12-17 09:28:10 -08003871 /**
3872 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3873 * @param subId The subscription to use to check the configuration.
3874 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003875 @Override
3876 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003877 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3878 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003879
Brad Ebinger35c841c2018-10-01 10:40:55 -07003880 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3881 final long token = Binder.clearCallingIdentity();
3882 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003883 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003884 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003885 } catch (ImsException e) {
3886 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003887 } finally {
3888 Binder.restoreCallingIdentity(token);
3889 }
3890 }
3891
3892 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003893 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003895 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003896 final long identity = Binder.clearCallingIdentity();
3897 try {
3898 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003899 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003900 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003901 } catch (ImsException e) {
3902 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003903 } finally {
3904 Binder.restoreCallingIdentity(identity);
3905 }
3906 }
3907
shilu366312e2019-12-17 09:28:10 -08003908 /**
3909 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3910 * @param subId The subscription to use to check the configuration.
3911 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003912 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003913 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003914 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3915 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003916 final long identity = Binder.clearCallingIdentity();
3917 try {
3918 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003919 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3920 } catch (ImsException e) {
3921 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003922 } finally {
3923 Binder.restoreCallingIdentity(identity);
3924 }
3925 }
3926
3927 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003928 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003930 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003931 final long identity = Binder.clearCallingIdentity();
3932 try {
3933 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003934 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003935 } catch (ImsException e) {
3936 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003937 } finally {
3938 Binder.restoreCallingIdentity(identity);
3939 }
3940 }
3941
shilu366312e2019-12-17 09:28:10 -08003942 /**
3943 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3944 * @param subId The subscription to use to check the configuration.
3945 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003946 @Override
3947 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003948 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3949 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003950 final long identity = Binder.clearCallingIdentity();
3951 try {
3952 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003953 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003954 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003955 } catch (ImsException e) {
3956 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003957 } finally {
3958 Binder.restoreCallingIdentity(identity);
3959 }
3960 }
3961
3962 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003963 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003964 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003965 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003966 final long identity = Binder.clearCallingIdentity();
3967 try {
3968 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003969 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003970 } catch (ImsException e) {
3971 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 } finally {
3973 Binder.restoreCallingIdentity(identity);
3974 }
3975 }
3976
shilu366312e2019-12-17 09:28:10 -08003977 /**
3978 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3979 * @param subId The subscription to use to check the configuration.
3980 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003981 @Override
3982 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003983 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3984 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003985 final long identity = Binder.clearCallingIdentity();
3986 try {
3987 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003988 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003989 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003990 } catch (ImsException e) {
3991 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003992 } finally {
3993 Binder.restoreCallingIdentity(identity);
3994 }
3995 }
3996
3997 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003998 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004000 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004001 final long identity = Binder.clearCallingIdentity();
4002 try {
4003 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004004 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004005 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004006 } catch (ImsException e) {
4007 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004008 } finally {
4009 Binder.restoreCallingIdentity(identity);
4010 }
4011 }
4012
4013 @Override
4014 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4016 "setVoWiFiNonPersistent");
4017 final long identity = Binder.clearCallingIdentity();
4018 try {
4019 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004020 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004021 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004022 } catch (ImsException e) {
4023 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004024 } finally {
4025 Binder.restoreCallingIdentity(identity);
4026 }
4027 }
4028
shilu366312e2019-12-17 09:28:10 -08004029 /**
4030 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4031 * @param subId The subscription to use to check the configuration.
4032 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004033 @Override
4034 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004035 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4036 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004037 final long identity = Binder.clearCallingIdentity();
4038 try {
4039 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004040 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004041 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004042 } catch (ImsException e) {
4043 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004044 } finally {
4045 Binder.restoreCallingIdentity(identity);
4046 }
4047 }
4048
4049 @Override
4050 public void setVoWiFiModeSetting(int subId, int mode) {
4051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4052 "setVoWiFiModeSetting");
4053 final long identity = Binder.clearCallingIdentity();
4054 try {
4055 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004056 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004057 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004058 } catch (ImsException e) {
4059 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004060 } finally {
4061 Binder.restoreCallingIdentity(identity);
4062 }
4063 }
4064
4065 @Override
4066 public int getVoWiFiRoamingModeSetting(int subId) {
4067 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4068 final long identity = Binder.clearCallingIdentity();
4069 try {
4070 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004071 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004072 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004073 } catch (ImsException e) {
4074 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004075 } finally {
4076 Binder.restoreCallingIdentity(identity);
4077 }
4078 }
4079
4080 @Override
4081 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4083 "setVoWiFiRoamingModeSetting");
4084 final long identity = Binder.clearCallingIdentity();
4085 try {
4086 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004087 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004088 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004089 } catch (ImsException e) {
4090 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004091 } finally {
4092 Binder.restoreCallingIdentity(identity);
4093 }
4094 }
4095
4096 @Override
4097 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4099 "setRttCapabilityEnabled");
4100 final long identity = Binder.clearCallingIdentity();
4101 try {
4102 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004103 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4104 } catch (ImsException e) {
4105 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004106 } finally {
4107 Binder.restoreCallingIdentity(identity);
4108 }
4109 }
4110
shilu366312e2019-12-17 09:28:10 -08004111 /**
4112 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4113 * @param subId The subscription to use to check the configuration.
4114 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004115 @Override
4116 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004117 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4118 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004119 final long identity = Binder.clearCallingIdentity();
4120 try {
4121 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004122 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004123 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004124 } catch (ImsException e) {
4125 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004126 } finally {
4127 Binder.restoreCallingIdentity(identity);
4128 }
4129 }
4130
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004131 @Override
4132 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4133 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4134 final long identity = Binder.clearCallingIdentity();
4135 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004136 if (!isImsAvailableOnDevice()) {
4137 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4138 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004139 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004140 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004141 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004142 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004143 } catch (ImsException e) {
4144 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004145 } finally {
4146 Binder.restoreCallingIdentity(identity);
4147 }
4148 }
4149
4150 @Override
4151 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4152 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4153 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004154 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4155 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4156 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004157 try {
4158 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004159 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004160 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004161 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004162 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4163 + "is inactive, ignoring unregister.");
4164 // If the subscription is no longer active, just return, since the callback will already
4165 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004166 } finally {
4167 Binder.restoreCallingIdentity(identity);
4168 }
4169 }
4170
allenwtsu99c623b2020-01-03 18:24:23 +08004171
4172 private void checkModifyPhoneStatePermission(int subId, String message) {
4173 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4174 message);
4175 }
4176
4177 private boolean isImsProvisioningRequired(int subId, int capability,
4178 boolean isMmtelCapability) {
4179 Phone phone = getPhone(subId);
4180 if (phone == null) {
4181 loge("phone instance null for subid " + subId);
4182 return false;
4183 }
4184 if (isMmtelCapability) {
4185 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4186 return false;
4187 }
4188 } else {
4189 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4190 return false;
4191 }
4192 }
4193 return true;
4194 }
4195
4196 @Override
4197 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4198 boolean isProvisioned) {
4199 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4200
4201 final long identity = Binder.clearCallingIdentity();
4202 try {
4203 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4204 if (!isImsProvisioningRequired(subId, capability, false)) {
4205 return;
4206 }
4207
4208 // this capability requires provisioning, route to the correct API.
4209 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4210 switch (capability) {
4211 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4212 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4213 ims.setEabProvisioned(isProvisioned);
4214 break;
4215 default: {
4216 throw new IllegalArgumentException("Tried to set provisioning for "
4217 + "rcs capability '" + capability + "', which does not require "
4218 + "provisioning.");
4219 }
4220 }
4221 } finally {
4222 Binder.restoreCallingIdentity(identity);
4223 }
4224
4225 }
4226
4227
4228 @Override
4229 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4230 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4231 final long identity = Binder.clearCallingIdentity();
4232 try {
4233 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4234 if (!isImsProvisioningRequired(subId, capability, false)) {
4235 return true;
4236 }
4237
4238 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4239 switch (capability) {
4240 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4241 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4242 return ims.isEabProvisionedOnDevice();
4243
4244 default: {
4245 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4246 + "capability '" + capability + "', which does not require "
4247 + "provisioning.");
4248 }
4249 }
4250
4251 } finally {
4252 Binder.restoreCallingIdentity(identity);
4253 }
4254 }
4255
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004256 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004257 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4258 boolean isProvisioned) {
4259 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4260 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4261 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4262 }
allenwtsu99c623b2020-01-03 18:24:23 +08004263 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004264 final long identity = Binder.clearCallingIdentity();
4265 try {
4266 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004267 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004268 return;
4269 }
4270
4271 // this capability requires provisioning, route to the correct API.
4272 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4273 switch (capability) {
4274 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4275 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4276 ims.setVolteProvisioned(isProvisioned);
4277 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4278 ims.setWfcProvisioned(isProvisioned);
4279 }
4280 break;
4281 }
4282 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4283 // There is currently no difference in VT provisioning type.
4284 ims.setVtProvisioned(isProvisioned);
4285 break;
4286 }
4287 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4288 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4289 // change the capability of the feature instead if needed.
4290 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4291 == isProvisioned) {
4292 // No change in provisioning.
4293 return;
4294 }
4295 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4296 try {
4297 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004298 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004299 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4300 + ", Exception" + e.getMessage());
4301 }
4302 break;
4303 }
4304 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004305 throw new IllegalArgumentException("Tried to set provisioning for "
4306 + "MmTel capability '" + capability + "', which does not require "
4307 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004308 }
4309 }
4310
4311 } finally {
4312 Binder.restoreCallingIdentity(identity);
4313 }
4314 }
4315
4316 @Override
4317 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4318 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4319 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4320 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4321 }
4322 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4323 final long identity = Binder.clearCallingIdentity();
4324 try {
4325 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004326 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004327 return true;
4328 }
4329
4330 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4331 switch (capability) {
4332 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4333 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4334 return ims.isVolteProvisionedOnDevice();
4335 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4336 return ims.isWfcProvisionedOnDevice();
4337 }
4338 // This should never happen, since we are checking tech above to make sure it
4339 // is either LTE or IWLAN.
4340 throw new IllegalArgumentException("Invalid radio technology for voice "
4341 + "capability.");
4342 }
4343 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4344 // There is currently no difference in VT provisioning type.
4345 return ims.isVtProvisionedOnDevice();
4346 }
4347 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4348 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4349 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4350 }
4351 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004352 throw new IllegalArgumentException(
4353 "Tried to get provisioning for MmTel capability '" + capability
4354 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004355 }
4356 }
4357
4358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
4361 }
4362
4363 @Override
4364 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4365 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4366 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4367 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4368 }
4369 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4370 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4371 return (provisionedBits & capability) > 0;
4372 }
4373
4374 @Override
4375 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4376 boolean isProvisioned) {
4377 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4378 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4379 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4380 }
4381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4382 "setProvisioningStatusForCapability");
4383 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4384 // If the current provisioning status for capability already matches isProvisioned,
4385 // do nothing.
4386 if (((provisionedBits & capability) > 0) == isProvisioned) {
4387 return;
4388 }
4389 if (isProvisioned) {
4390 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4391 } else {
4392 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4393 }
4394 }
4395
4396 /**
4397 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4398 * technology. The bitfield should mirror the bitfield defined by
4399 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4400 */
4401 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4402 String key = getMmTelProvisioningKey(subId, tech);
4403 // Default is no capabilities are provisioned.
4404 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4405 }
4406
4407 /**
4408 * Sets the MmTel capability provisioning bitfield (defined by
4409 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4410 * technology specified.
4411 *
4412 * Note: This is a synchronous command and should not be called on UI thread.
4413 */
4414 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4415 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4416 String key = getMmTelProvisioningKey(subId, tech);
4417 editor.putInt(key, newField);
4418 editor.commit();
4419 }
4420
4421 private static String getMmTelProvisioningKey(int subId, int tech) {
4422 // resulting key is provision_ims_mmtel_{subId}_{tech}
4423 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4424 }
4425
4426 /**
4427 * Query CarrierConfig to see if the specified capability requires provisioning for the
4428 * carrier associated with the subscription id.
4429 */
4430 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4431 int capability) {
4432 CarrierConfigManager configManager = new CarrierConfigManager(context);
4433 PersistableBundle c = configManager.getConfigForSubId(subId);
4434 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004435 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004436 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4437 false);
4438 boolean requireVoiceVtProvisioning = c.getBoolean(
4439 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4440
4441 // First check to make sure that the capability requires provisioning.
4442 switch (capability) {
4443 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4444 // intentional fallthrough
4445 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4446 if (requireVoiceVtProvisioning) {
4447 // Voice and Video requires provisioning
4448 return true;
4449 }
4450 break;
4451 }
4452 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4453 if (requireUtProvisioning) {
4454 // UT requires provisioning
4455 return true;
4456 }
4457 break;
4458 }
4459 }
4460 return false;
4461 }
4462
allenwtsu99c623b2020-01-03 18:24:23 +08004463 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4464 int capability) {
4465 CarrierConfigManager configManager = new CarrierConfigManager(context);
4466 PersistableBundle c = configManager.getConfigForSubId(subId);
4467
4468 boolean requireRcsProvisioning = c.getBoolean(
4469 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4470
4471 // First check to make sure that the capability requires provisioning.
4472 switch (capability) {
4473 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4474 // intentional fallthrough
4475 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4476 if (requireRcsProvisioning) {
4477 // OPTION or PRESENCE requires provisioning
4478 return true;
4479 }
4480 break;
4481 }
4482 }
4483 return false;
4484 }
4485
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004486 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004487 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004488 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4489 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4490 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004491 enforceReadPrivilegedPermission("getImsProvisioningInt");
4492 final long identity = Binder.clearCallingIdentity();
4493 try {
4494 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004495 int slotId = getSlotIndex(subId);
4496 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4497 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4498 + subId + "' for key:" + key);
4499 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4500 }
4501 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004502 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004503 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4504 + subId + "' for key:" + key);
4505 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004506 } finally {
4507 Binder.restoreCallingIdentity(identity);
4508 }
4509 }
4510
4511 @Override
4512 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004513 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4514 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4515 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004516 enforceReadPrivilegedPermission("getImsProvisioningString");
4517 final long identity = Binder.clearCallingIdentity();
4518 try {
4519 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004520 int slotId = getSlotIndex(subId);
4521 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4522 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4523 + subId + "' for key:" + key);
4524 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4525 }
4526 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004527 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004528 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4529 + subId + "' for key:" + key);
4530 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004531 } finally {
4532 Binder.restoreCallingIdentity(identity);
4533 }
4534 }
4535
4536 @Override
4537 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004538 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4539 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4540 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4542 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004543 final long identity = Binder.clearCallingIdentity();
4544 try {
4545 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004546 int slotId = getSlotIndex(subId);
4547 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4548 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4549 + subId + "' for key:" + key);
4550 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4551 }
4552 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004553 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004554 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4555 + "' for key:" + key);
4556 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004557 } finally {
4558 Binder.restoreCallingIdentity(identity);
4559 }
4560 }
4561
4562 @Override
4563 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004564 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4565 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4566 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4568 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004569 final long identity = Binder.clearCallingIdentity();
4570 try {
4571 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004572 int slotId = getSlotIndex(subId);
4573 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4574 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4575 + subId + "' for key:" + key);
4576 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4577 }
4578 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004579 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004580 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4581 + "' for key:" + key);
4582 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004583 } finally {
4584 Binder.restoreCallingIdentity(identity);
4585 }
4586 }
4587
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004588 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004589 int slotId = SubscriptionManager.getSlotIndex(subId);
4590 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004591 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4592 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004593 }
4594 return slotId;
4595 }
4596
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004597 private int getSlotIndex(int subId) {
4598 int slotId = SubscriptionManager.getSlotIndex(subId);
4599 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4600 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4601 }
4602 return slotId;
4603 }
4604
Wink Saville36469e72014-06-11 15:17:00 -07004605 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004606 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004607 */
4608 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004609 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4610 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004611 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004612 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004613 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004614 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004615 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004616 mApp, subId, callingPackage, callingFeatureId,
4617 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004618 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4619 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004621 final long identity = Binder.clearCallingIdentity();
4622 try {
4623 final Phone phone = getPhone(subId);
4624 if (phone != null) {
4625 return phone.getServiceState().getDataNetworkType();
4626 } else {
4627 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4628 }
4629 } finally {
4630 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004631 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004632 }
4633
4634 /**
4635 * Returns the data network type
4636 */
4637 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004638 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4639 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4640 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004641 }
4642
4643 /**
4644 * Returns the data network type for a subId
4645 */
4646 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004647 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4648 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004649 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004650 mApp, subId, callingPackage, callingFeatureId,
4651 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004652 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4653 }
4654
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004655 final long identity = Binder.clearCallingIdentity();
4656 try {
4657 final Phone phone = getPhone(subId);
4658 if (phone != null) {
4659 return phone.getServiceState().getDataNetworkType();
4660 } else {
4661 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4662 }
4663 } finally {
4664 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004665 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004666 }
4667
4668 /**
Wink Saville36469e72014-06-11 15:17:00 -07004669 * Returns the Voice network type for a subId
4670 */
4671 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004672 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4673 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004674 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004675 mApp, subId, callingPackage, callingFeatureId,
4676 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004677 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4678 }
4679
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004680 final long identity = Binder.clearCallingIdentity();
4681 try {
4682 final Phone phone = getPhone(subId);
4683 if (phone != null) {
4684 return phone.getServiceState().getVoiceNetworkType();
4685 } else {
4686 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4687 }
4688 } finally {
4689 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004691 }
4692
4693 /**
4694 * @return true if a ICC card is present
4695 */
4696 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004697 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004698 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4699 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004700 }
4701
4702 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004703 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004704 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004705 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004706 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004707 final long identity = Binder.clearCallingIdentity();
4708 try {
4709 final Phone phone = PhoneFactory.getPhone(slotIndex);
4710 if (phone != null) {
4711 return phone.getIccCard().hasIccCard();
4712 } else {
4713 return false;
4714 }
4715 } finally {
4716 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004718 }
4719
4720 /**
4721 * Return if the current radio is LTE on CDMA. This
4722 * is a tri-state return value as for a period of time
4723 * the mode may be unknown.
4724 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004725 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004726 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004727 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004728 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004729 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004730 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4731 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4732 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004733 }
4734
Sanket Padawe356d7632015-06-22 14:03:32 -07004735 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004736 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4737 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004738 try {
4739 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4740 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004741 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4742 }
4743
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004744 final long identity = Binder.clearCallingIdentity();
4745 try {
4746 final Phone phone = getPhone(subId);
4747 if (phone == null) {
4748 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4749 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004750 return TelephonyProperties.lte_on_cdma_device()
4751 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004752 }
4753 } finally {
4754 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004755 }
Wink Saville36469e72014-06-11 15:17:00 -07004756 }
4757
Wink Saville36469e72014-06-11 15:17:00 -07004758 /**
4759 * {@hide}
4760 * Returns Default subId, 0 in the case of single standby.
4761 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004762 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004763 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004764 }
4765
Shishir Agrawala9f32182016-04-12 12:00:16 -07004766 private int getSlotForDefaultSubscription() {
4767 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4768 }
4769
Wink Savilleb564aae2014-10-23 10:18:09 -07004770 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004771 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004772 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004773
Pengquan Menge92a50d2018-09-21 15:54:48 -07004774 private boolean isActiveSubscription(int subId) {
4775 return mSubscriptionController.isActiveSubId(subId);
4776 }
4777
Ihab Awadf2177b72013-11-25 13:33:23 -08004778 /**
4779 * @see android.telephony.TelephonyManager.WifiCallingChoices
4780 */
4781 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004782 final long identity = Binder.clearCallingIdentity();
4783 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004784 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004785 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4786 getWhenToMakeWifiCallsDefaultPreference());
4787 } finally {
4788 Binder.restoreCallingIdentity(identity);
4789 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004790 }
4791
4792 /**
4793 * @see android.telephony.TelephonyManager.WifiCallingChoices
4794 */
4795 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004796 final long identity = Binder.clearCallingIdentity();
4797 try {
4798 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004799 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004800 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4801 } finally {
4802 Binder.restoreCallingIdentity(identity);
4803 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004804 }
4805
Sailesh Nepald1e68152013-12-12 19:08:02 -08004806 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004807 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004808 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004809 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004810
Jordan Liu4c733742019-02-28 12:03:40 -08004811 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4812 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4813 if (phoneId == -1) {
4814 throw new IllegalArgumentException("Given slot index: " + slotIndex
4815 + " does not correspond to an active phone");
4816 }
4817 return PhoneFactory.getPhone(phoneId);
4818 }
4819
Shishir Agrawal566b7612013-10-28 14:41:00 -07004820 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004821 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4822 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4824 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004825 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004826 if (DBG) {
4827 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4828 }
4829 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4830 p2);
4831 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004832
Jordan Liu4c733742019-02-28 12:03:40 -08004833
4834 @Override
4835 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4836 int slotIndex, String callingPackage, String aid, int p2) {
4837 enforceModifyPermission();
4838 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4839 if (DBG) {
4840 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4841 }
4842 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4843 callingPackage, aid, p2);
4844 }
4845
4846 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4847 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004848 final long identity = Binder.clearCallingIdentity();
4849 try {
4850 if (TextUtils.equals(ISDR_AID, aid)) {
4851 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004852 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4853 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004854 if (bestComponent == null
4855 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4856 loge("The calling package is not allowed to access ISD-R.");
4857 throw new SecurityException(
4858 "The calling package is not allowed to access ISD-R.");
4859 }
Derek Tan740e1672017-06-27 14:56:27 -07004860 }
Derek Tan740e1672017-06-27 14:56:27 -07004861
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004862 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004863 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4864 null /* workSource */);
4865 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004866 return response;
4867 } finally {
4868 Binder.restoreCallingIdentity(identity);
4869 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004870 }
4871
4872 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004873 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4875 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004876 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4877 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4878 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004879
Jordan Liu4c733742019-02-28 12:03:40 -08004880 @Override
4881 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4882 enforceModifyPermission();
4883 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4884 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4885 channel);
4886 }
4887
4888 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004889 final long identity = Binder.clearCallingIdentity();
4890 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004891 if (channel < 0) {
4892 return false;
4893 }
Jordan Liu4c733742019-02-28 12:03:40 -08004894 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4895 null /* workSource */);
4896 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004897 return success;
4898 } finally {
4899 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004900 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004901 }
4902
4903 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004904 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004905 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4907 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004908 if (DBG) {
4909 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4910 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4911 + p3 + " data=" + data);
4912 }
4913 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4914 command, p1, p2, p3, data);
4915 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004916
Jordan Liu4c733742019-02-28 12:03:40 -08004917 @Override
4918 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4919 int command, int p1, int p2, int p3, String data) {
4920 enforceModifyPermission();
4921 if (DBG) {
4922 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4923 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4924 + p3 + " data=" + data);
4925 }
4926 return iccTransmitApduLogicalChannelWithPermission(
4927 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4928 data);
4929 }
4930
4931 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4932 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933 final long identity = Binder.clearCallingIdentity();
4934 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004935 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004936 return "";
4937 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004938
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004939 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004940 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4941 null /* workSource */);
4942 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004943
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944 // Append the returned status code to the end of the response payload.
4945 String s = Integer.toHexString(
4946 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4947 if (response.payload != null) {
4948 s = IccUtils.bytesToHexString(response.payload) + s;
4949 }
4950 return s;
4951 } finally {
4952 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004953 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004954 }
Jake Hambye994d462014-02-03 13:10:13 -08004955
Evan Charltonc66da362014-05-16 14:06:40 -07004956 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004957 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4958 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4960 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004961 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004962 if (DBG) {
4963 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4964 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4965 }
4966 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4967 cla, command, p1, p2, p3, data);
4968 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004969
Jordan Liu4c733742019-02-28 12:03:40 -08004970 @Override
4971 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4972 int command, int p1, int p2, int p3, String data) {
4973 enforceModifyPermission();
4974 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4975 if (DBG) {
4976 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4977 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4978 + " data=" + data);
4979 }
4980
4981 return iccTransmitApduBasicChannelWithPermission(
4982 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4983 p2, p3, data);
4984 }
4985
4986 // open APDU basic channel assuming the caller has sufficient permissions
4987 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4988 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989 final long identity = Binder.clearCallingIdentity();
4990 try {
4991 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4992 && TextUtils.equals(ISDR_AID, data)) {
4993 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004994 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4995 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004996 if (bestComponent == null
4997 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4998 loge("The calling package is not allowed to select ISD-R.");
4999 throw new SecurityException(
5000 "The calling package is not allowed to select ISD-R.");
5001 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005002 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005003
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005005 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5006 null /* workSource */);
5007 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005008
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005009 // Append the returned status code to the end of the response payload.
5010 String s = Integer.toHexString(
5011 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5012 if (response.payload != null) {
5013 s = IccUtils.bytesToHexString(response.payload) + s;
5014 }
5015 return s;
5016 } finally {
5017 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005018 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005019 }
5020
5021 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005022 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005023 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5025 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005027 final long identity = Binder.clearCallingIdentity();
5028 try {
5029 if (DBG) {
5030 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5031 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5032 }
5033
5034 IccIoResult response =
5035 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5036 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5037 subId);
5038
5039 if (DBG) {
5040 log("Exchange SIM_IO [R]" + response);
5041 }
5042
5043 byte[] result = null;
5044 int length = 2;
5045 if (response.payload != null) {
5046 length = 2 + response.payload.length;
5047 result = new byte[length];
5048 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5049 } else {
5050 result = new byte[length];
5051 }
5052
5053 result[length - 1] = (byte) response.sw2;
5054 result[length - 2] = (byte) response.sw1;
5055 return result;
5056 } finally {
5057 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005058 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005059 }
5060
Nathan Haroldb3014052017-01-25 15:57:32 -08005061 /**
5062 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5063 * on a particular subscription
5064 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005065 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5066 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005068 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005069 return null;
5070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005071
5072 final long identity = Binder.clearCallingIdentity();
5073 try {
5074 if (appType != TelephonyManager.APPTYPE_USIM
5075 && appType != TelephonyManager.APPTYPE_SIM) {
5076 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5077 return null;
5078 }
5079 Object response = sendRequest(
5080 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5081 if (response instanceof String[]) {
5082 return (String[]) response;
5083 }
yincheng zhaod698b842019-09-06 17:06:54 -07005084 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005086 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005087 } finally {
5088 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005089 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005090 }
5091
yincheng zhaod698b842019-09-06 17:06:54 -07005092 /**
5093 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5094 * subscription.
5095 *
5096 * @param subId the id of the subscription.
5097 * @param appType the uicc app type, must be USIM or SIM.
5098 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5099 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005100 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005101 * @return number of fplmns that is successfully written to the SIM.
5102 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005103 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5104 String callingFeatureId) {
5105 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5106 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005107 if (DBG) logv("no permissions for setForbiddenplmns");
5108 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5109 }
5110 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5111 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5112 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5113 }
5114 if (fplmns == null) {
5115 throw new IllegalArgumentException("Fplmn List provided is null");
5116 }
5117 for (String fplmn : fplmns) {
5118 if (!CellIdentity.isValidPlmn(fplmn)) {
5119 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5120 }
5121 }
5122 final long identity = Binder.clearCallingIdentity();
5123 try {
5124 Object response = sendRequest(
5125 CMD_SET_FORBIDDEN_PLMNS,
5126 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5127 subId);
5128 return (int) response;
5129 } finally {
5130 Binder.restoreCallingIdentity(identity);
5131 }
5132 }
5133
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005134 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005135 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5137 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005138
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005139 final long identity = Binder.clearCallingIdentity();
5140 try {
5141 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5142 if (response.payload == null) {
5143 return "";
5144 }
Evan Charltonc66da362014-05-16 14:06:40 -07005145
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005146 // Append the returned status code to the end of the response payload.
5147 String s = Integer.toHexString(
5148 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5149 s = IccUtils.bytesToHexString(response.payload) + s;
5150 return s;
5151 } finally {
5152 Binder.restoreCallingIdentity(identity);
5153 }
Evan Charltonc66da362014-05-16 14:06:40 -07005154 }
5155
Jake Hambye994d462014-02-03 13:10:13 -08005156 /**
5157 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5158 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5159 *
5160 * @param itemID the ID of the item to read
5161 * @return the NV item as a String, or null on error.
5162 */
5163 @Override
5164 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005165 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5167 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168
5169 final long identity = Binder.clearCallingIdentity();
5170 try {
5171 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005172 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5174 return value;
5175 } finally {
5176 Binder.restoreCallingIdentity(identity);
5177 }
Jake Hambye994d462014-02-03 13:10:13 -08005178 }
5179
5180 /**
5181 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5182 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5183 *
5184 * @param itemID the ID of the item to read
5185 * @param itemValue the value to write, as a String
5186 * @return true on success; false on any failure
5187 */
5188 @Override
5189 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005190 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5192 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193
5194 final long identity = Binder.clearCallingIdentity();
5195 try {
5196 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5197 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005198 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5200 return success;
5201 } finally {
5202 Binder.restoreCallingIdentity(identity);
5203 }
Jake Hambye994d462014-02-03 13:10:13 -08005204 }
5205
5206 /**
5207 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5208 * Used for device configuration by some CDMA operators.
5209 *
5210 * @param preferredRoamingList byte array containing the new PRL
5211 * @return true on success; false on any failure
5212 */
5213 @Override
5214 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5216 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005217
5218 final long identity = Binder.clearCallingIdentity();
5219 try {
5220 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5221 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5222 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5223 return success;
5224 } finally {
5225 Binder.restoreCallingIdentity(identity);
5226 }
Jake Hambye994d462014-02-03 13:10:13 -08005227 }
5228
5229 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005230 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005231 * Used for device configuration by some CDMA operators.
5232 *
chen xu6dac5ab2018-10-26 17:39:23 -07005233 * @param slotIndex - device slot.
5234 *
Jake Hambye994d462014-02-03 13:10:13 -08005235 * @return true on success; false on any failure
5236 */
5237 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005238 public boolean resetModemConfig(int slotIndex) {
5239 Phone phone = PhoneFactory.getPhone(slotIndex);
5240 if (phone != null) {
5241 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5242 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243
chen xu6dac5ab2018-10-26 17:39:23 -07005244 final long identity = Binder.clearCallingIdentity();
5245 try {
5246 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5247 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5248 return success;
5249 } finally {
5250 Binder.restoreCallingIdentity(identity);
5251 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 }
chen xu6dac5ab2018-10-26 17:39:23 -07005253 return false;
5254 }
5255
5256 /**
5257 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5258 *
5259 * @param slotIndex - device slot.
5260 *
5261 * @return true on success; false on any failure
5262 */
5263 @Override
5264 public boolean rebootModem(int slotIndex) {
5265 Phone phone = PhoneFactory.getPhone(slotIndex);
5266 if (phone != null) {
5267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5268 mApp, phone.getSubId(), "rebootModem");
5269
5270 final long identity = Binder.clearCallingIdentity();
5271 try {
5272 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5273 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5274 return success;
5275 } finally {
5276 Binder.restoreCallingIdentity(identity);
5277 }
5278 }
5279 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005280 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005281
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005282 public String[] getPcscfAddress(String apnType, String callingPackage,
5283 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005284 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005285 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5286 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005287 return new String[0];
5288 }
5289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290 final long identity = Binder.clearCallingIdentity();
5291 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005292 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293 } finally {
5294 Binder.restoreCallingIdentity(identity);
5295 }
Wink Saville36469e72014-06-11 15:17:00 -07005296 }
5297
Brad Ebinger51f743a2017-01-23 13:50:20 -08005298 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005299 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5300 * {@link #disableIms(int)}.
5301 * @param slotIndex device slot.
5302 */
5303 public void resetIms(int slotIndex) {
5304 enforceModifyPermission();
5305
5306 final long identity = Binder.clearCallingIdentity();
5307 try {
5308 if (mImsResolver == null) {
5309 // may happen if the does not support IMS.
5310 return;
5311 }
5312 mImsResolver.disableIms(slotIndex);
5313 mImsResolver.enableIms(slotIndex);
5314 } finally {
5315 Binder.restoreCallingIdentity(identity);
5316 }
5317 }
5318
5319 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005320 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5321 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005322 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005323 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005324 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325
5326 final long identity = Binder.clearCallingIdentity();
5327 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005328 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005329 // may happen if the device does not support IMS.
5330 return;
5331 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005332 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 } finally {
5334 Binder.restoreCallingIdentity(identity);
5335 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005336 }
5337
5338 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005339 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5340 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005341 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005342 public void disableIms(int slotId) {
5343 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005344
5345 final long identity = Binder.clearCallingIdentity();
5346 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005347 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005348 // may happen if the device does not support IMS.
5349 return;
5350 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005351 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352 } finally {
5353 Binder.restoreCallingIdentity(identity);
5354 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005355 }
5356
5357 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005358 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5359 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005360 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005361 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005362 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005363 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005364
5365 final long identity = Binder.clearCallingIdentity();
5366 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005367 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005368 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5369 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005370 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005371 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372 } finally {
5373 Binder.restoreCallingIdentity(identity);
5374 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005375 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005376 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005377 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5378 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005379 @Override
5380 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005381 enforceModifyPermission();
5382
5383 final long identity = Binder.clearCallingIdentity();
5384 try {
5385 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005386 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005387 } finally {
5388 Binder.restoreCallingIdentity(identity);
5389 }
5390 }
5391
5392 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005393 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005394 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005395 */
5396 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5397 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 null;
5404 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005405 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 } finally {
5407 Binder.restoreCallingIdentity(identity);
5408 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005409 }
5410
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005411 /**
5412 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005413 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005414 */
5415 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
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 null;
5423 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005424 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425 } finally {
5426 Binder.restoreCallingIdentity(identity);
5427 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005428 }
5429
Brad Ebinger884c07b2018-02-15 16:17:40 -08005430 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005431 * Sets the ImsService Package Name that Telephony will bind to.
5432 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005433 * @param slotIndex the slot ID that the ImsService should bind for.
5434 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005435 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005436 * @param featureTypes An integer array of feature types associated with a packageName.
5437 * @param packageName The name of the package that the current configuration will be replaced
5438 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005439 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005440 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005441 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5442 int[] featureTypes, String packageName) {
5443 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5444 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5446 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005447 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005448
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449 final long identity = Binder.clearCallingIdentity();
5450 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005451 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005452 // may happen if the device does not support IMS.
5453 return false;
5454 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005455 Map<Integer, String> featureConfig = new HashMap<>();
5456 for (int featureType : featureTypes) {
5457 featureConfig.put(featureType, packageName);
5458 }
5459 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5460 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005461 } finally {
5462 Binder.restoreCallingIdentity(identity);
5463 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005464 }
5465
5466 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005467 * Clears any carrier ImsService overrides for the slot index specified that were previously
5468 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5469 *
5470 * This should only be used for testing.
5471 *
5472 * @param slotIndex the slot ID that the ImsService should bind for.
5473 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5474 */
5475 @Override
5476 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5477 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5478 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5479 "clearCarrierImsServiceOverride");
5480 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5481 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5482 "clearCarrierImsServiceOverride");
5483
5484 final long identity = Binder.clearCallingIdentity();
5485 try {
5486 if (mImsResolver == null) {
5487 // may happen if the device does not support IMS.
5488 return false;
5489 }
5490 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5491 } finally {
5492 Binder.restoreCallingIdentity(identity);
5493 }
5494 }
5495
5496 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005497 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005498 *
5499 * @param slotId The slot that the ImsService is associated with.
5500 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5501 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005502 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005503 * @return the package name of the ImsService configuration.
5504 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005505 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5506 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005507 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005508 TelephonyPermissions
5509 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5510 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5511 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005513 final long identity = Binder.clearCallingIdentity();
5514 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005515 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005516 // may happen if the device does not support IMS.
5517 return "";
5518 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005519 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005520 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5521 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522 } finally {
5523 Binder.restoreCallingIdentity(identity);
5524 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005525 }
5526
Brad Ebinger77b832e2019-10-17 17:03:22 -07005527 /**
5528 * Get the MmTelFeature state associated with the requested subscription id.
5529 * @param subId The subscription that the MmTelFeature is associated with.
5530 * @param callback A callback with an integer containing the
5531 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5532 */
5533 @Override
5534 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5535 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5536 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5537 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5538 "IMS not available on device.");
5539 }
5540 final long token = Binder.clearCallingIdentity();
5541 try {
5542 int slotId = getSlotIndex(subId);
5543 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5544 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5545 + subId + "'");
5546 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5547 }
5548 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5549 try {
5550 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5551 } catch (RemoteException e) {
5552 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5553 + "Ignore");
5554 }
5555 });
5556 } finally {
5557 Binder.restoreCallingIdentity(token);
5558 }
5559 }
5560
Daniel Brightbb5840b2021-01-12 15:48:18 -08005561 /**
5562 * Sets the ims registration state on all valid {@link Phone}s.
5563 */
5564 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005565 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005566
5567 final long identity = Binder.clearCallingIdentity();
5568 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005569 // NOTE: Before S, this method only set the default phone.
5570 for (final Phone phone : PhoneFactory.getPhones()) {
5571 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5572 phone.setImsRegistrationState(registered);
5573 }
5574 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005575 } finally {
5576 Binder.restoreCallingIdentity(identity);
5577 }
Wink Saville36469e72014-06-11 15:17:00 -07005578 }
5579
5580 /**
Stuart Scott54788802015-03-30 13:18:01 -07005581 * Set the network selection mode to automatic.
5582 *
5583 */
5584 @Override
5585 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5587 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005588
5589 final long identity = Binder.clearCallingIdentity();
5590 try {
shilufc958392020-01-20 11:36:01 -08005591 if (!isActiveSubscription(subId)) {
5592 return;
5593 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005594 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5595 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5596 } finally {
5597 Binder.restoreCallingIdentity(identity);
5598 }
Stuart Scott54788802015-03-30 13:18:01 -07005599 }
5600
Jack Yud10cdd42020-09-28 20:28:01 -07005601 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005602 * Ask the radio to connect to the input network and change selection mode to manual.
5603 *
5604 * @param subId the id of the subscription.
5605 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5606 * the operator to attach to.
5607 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5608 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5609 * normal network selection next time.
5610 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005611 */
5612 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005613 public boolean setNetworkSelectionModeManual(
5614 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5616 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005617
5618 if (!isActiveSubscription(subId)) {
5619 return false;
5620 }
5621
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005622 final long identity = Binder.clearCallingIdentity();
5623 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005624 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005625 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005626 if (DBG) {
5627 log("setNetworkSelectionModeManual: subId: " + subId
5628 + " operator: " + operatorInfo);
5629 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005630 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5631 } finally {
5632 Binder.restoreCallingIdentity(identity);
5633 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005634 }
shilu84f6e8b2019-12-19 13:58:01 -08005635 /**
5636 * Get the manual network selection
5637 *
5638 * @param subId the id of the subscription.
5639 *
5640 * @return the previously saved user selected PLMN
5641 */
5642 @Override
5643 public String getManualNetworkSelectionPlmn(int subId) {
5644 TelephonyPermissions
5645 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5646 mApp, subId, "getManualNetworkSelectionPlmn");
5647
5648 final long identity = Binder.clearCallingIdentity();
5649 try {
5650 if (!isActiveSubscription(subId)) {
5651 return "";
5652 }
5653
5654 final Phone phone = getPhone(subId);
5655 if (phone == null) {
5656 return "";
5657 }
5658 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5659 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5660 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5661 } finally {
5662 Binder.restoreCallingIdentity(identity);
5663 }
5664 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005665
5666 /**
5667 * Scans for available networks.
5668 */
5669 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005670 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5671 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5673 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005674 LocationAccessPolicy.LocationPermissionResult locationResult =
5675 LocationAccessPolicy.checkLocationPermission(mApp,
5676 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5677 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005678 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005679 .setCallingPid(Binder.getCallingPid())
5680 .setCallingUid(Binder.getCallingUid())
5681 .setMethod("getCellNetworkScanResults")
5682 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5683 .build());
5684 switch (locationResult) {
5685 case DENIED_HARD:
5686 throw new SecurityException("Not allowed to access scan results -- location");
5687 case DENIED_SOFT:
5688 return null;
5689 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005690
Pengquan Menga1bb6272018-09-06 09:59:22 -07005691 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692 try {
5693 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005694 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696 } finally {
5697 Binder.restoreCallingIdentity(identity);
5698 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005699 }
5700
5701 /**
sqian80370722020-01-29 15:02:51 -08005702 * Get the call forwarding info, given the call forwarding reason.
5703 */
5704 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005705 public void getCallForwarding(int subId, int callForwardingReason,
5706 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005707 enforceReadPrivilegedPermission("getCallForwarding");
5708 long identity = Binder.clearCallingIdentity();
5709 try {
5710 if (DBG) {
5711 log("getCallForwarding: subId " + subId
5712 + " callForwardingReason" + callForwardingReason);
5713 }
Hall Liua1acea22020-09-18 19:04:59 -07005714
5715 Phone phone = getPhone(subId);
5716 if (phone == null) {
5717 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005718 callback.onError(
5719 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005720 } catch (RemoteException e) {
5721 // ignore
5722 }
5723 return;
5724 }
5725
5726 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5727 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5728 @Override
5729 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5730 try {
5731 callback.onCallForwardingInfoAvailable(info);
5732 } catch (RemoteException e) {
5733 // ignore
5734 }
5735 }
5736
5737 @Override
5738 public void onError(int error) {
5739 try {
5740 callback.onError(error);
5741 } catch (RemoteException e) {
5742 // ignore
5743 }
5744 }
5745 });
5746 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005747 } finally {
5748 Binder.restoreCallingIdentity(identity);
5749 }
5750 }
5751
5752 /**
5753 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5754 * reason, the number to forward, and the timeout before the forwarding is attempted.
5755 */
5756 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005757 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5758 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005759 enforceModifyPermission();
5760 long identity = Binder.clearCallingIdentity();
5761 try {
5762 if (DBG) {
5763 log("setCallForwarding: subId " + subId
5764 + " callForwardingInfo" + callForwardingInfo);
5765 }
Hall Liua1acea22020-09-18 19:04:59 -07005766
5767 Phone phone = getPhone(subId);
5768 if (phone == null) {
5769 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005770 callback.accept(
5771 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005772 } catch (RemoteException e) {
5773 // ignore
5774 }
5775 return;
5776 }
5777
5778 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5779 FunctionalUtils.ignoreRemoteException(callback::accept));
5780
5781 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005782 } finally {
5783 Binder.restoreCallingIdentity(identity);
5784 }
5785 }
5786
5787 /**
Hall Liua1acea22020-09-18 19:04:59 -07005788 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005789 */
5790 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005791 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005792 enforceReadPrivilegedPermission("getCallForwarding");
5793 long identity = Binder.clearCallingIdentity();
5794 try {
Hall Liua1acea22020-09-18 19:04:59 -07005795
5796 Phone phone = getPhone(subId);
5797 if (phone == null) {
5798 try {
5799 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5800 } catch (RemoteException e) {
5801 // ignore
5802 }
5803 return;
5804 }
5805
5806 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5807
sqian80370722020-01-29 15:02:51 -08005808 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005809 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005810 } finally {
5811 Binder.restoreCallingIdentity(identity);
5812 }
5813 }
5814
5815 /**
Hall Liua1acea22020-09-18 19:04:59 -07005816 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005817 */
5818 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005819 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005820 enforceModifyPermission();
5821 long identity = Binder.clearCallingIdentity();
5822 try {
Hall Liua1acea22020-09-18 19:04:59 -07005823 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5824
5825 Phone phone = getPhone(subId);
5826 if (phone == null) {
5827 try {
5828 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5829 } catch (RemoteException e) {
5830 // ignore
5831 }
5832 return;
5833 }
5834
5835 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5836 FunctionalUtils.ignoreRemoteException(callback::accept));
5837
5838 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005839 } finally {
5840 Binder.restoreCallingIdentity(identity);
5841 }
5842 }
5843
5844 /**
yinxub1bed742017-04-17 11:45:04 -07005845 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005846 *
yinxub1bed742017-04-17 11:45:04 -07005847 * @param subId id of the subscription
5848 * @param request contains the radio access networks with bands/channels to scan
5849 * @param messenger callback messenger for scan results or errors
5850 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005851 * @return the id of the requested scan which can be used to stop the scan.
5852 */
5853 @Override
5854 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005855 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005856 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5857 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005858 LocationAccessPolicy.LocationPermissionResult locationResult =
5859 LocationAccessPolicy.checkLocationPermission(mApp,
5860 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5861 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005862 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005863 .setCallingPid(Binder.getCallingPid())
5864 .setCallingUid(Binder.getCallingUid())
5865 .setMethod("requestNetworkScan")
5866 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5867 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005868 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005869 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5870 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005871 if (e != null) {
5872 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5873 throw e;
5874 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005875 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005876 return TelephonyScanManager.INVALID_SCAN_ID;
5877 }
5878 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879 }
Hall Liu912dfd32019-04-25 14:02:26 -07005880 int callingUid = Binder.getCallingUid();
5881 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005882 final long identity = Binder.clearCallingIdentity();
5883 try {
5884 return mNetworkScanRequestTracker.startNetworkScan(
5885 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005886 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005887 } finally {
5888 Binder.restoreCallingIdentity(identity);
5889 }
yinxu504e1392017-04-12 16:03:22 -07005890 }
5891
Hall Liub2ac8ef2019-02-28 15:56:23 -08005892 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005893 NetworkScanRequest request, int subId, String callingPackage) {
5894 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005895 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5896 boolean hasNetworkScanPermission =
5897 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5898 == PERMISSION_GRANTED;
5899
5900 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5901 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5902 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005903 }
5904
5905 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5906 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005907 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5908 return new SecurityException("Specific channels must not be"
5909 + " scanned without location access.");
5910 }
5911 }
5912 }
5913
Hall Liub2ac8ef2019-02-28 15:56:23 -08005914 return null;
5915 }
5916
yinxu504e1392017-04-12 16:03:22 -07005917 /**
5918 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005919 *
5920 * @param subId id of the subscription
5921 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005922 */
5923 @Override
5924 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5926 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005927
Hall Liu912dfd32019-04-25 14:02:26 -07005928 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929 final long identity = Binder.clearCallingIdentity();
5930 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005931 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005932 } finally {
5933 Binder.restoreCallingIdentity(identity);
5934 }
yinxu504e1392017-04-12 16:03:22 -07005935 }
5936
5937 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005938 * Get the calculated preferred network type.
5939 * Used for debugging incorrect network type.
5940 *
5941 * @return the preferred network type, defined in RILConstants.java.
5942 */
5943 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005944 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005945 final Phone defaultPhone = getDefaultPhone();
5946 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005947 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005948 return RILConstants.PREFERRED_NETWORK_MODE;
5949 }
5950
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005951 final long identity = Binder.clearCallingIdentity();
5952 try {
5953 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005954 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005955 } finally {
5956 Binder.restoreCallingIdentity(identity);
5957 }
Junda Liu84d15a22014-07-02 11:21:04 -07005958 }
5959
5960 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005961 * Get the preferred network type.
5962 * Used for device configuration by some CDMA operators.
5963 *
5964 * @return the preferred network type, defined in RILConstants.java.
5965 */
5966 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005967 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005968 TelephonyPermissions
5969 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5970 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971
5972 final long identity = Binder.clearCallingIdentity();
5973 try {
5974 if (DBG) log("getPreferredNetworkType");
5975 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5976 int networkType = (result != null ? result[0] : -1);
5977 if (DBG) log("getPreferredNetworkType: " + networkType);
5978 return networkType;
5979 } finally {
5980 Binder.restoreCallingIdentity(identity);
5981 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005982 }
5983
5984 /**
5985 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005986 *
5987 * @param networkType the preferred network type, defined in RILConstants.java.
5988 * @return true on success; false on any failure.
5989 */
5990 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005991 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5993 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994
5995 final long identity = Binder.clearCallingIdentity();
5996 try {
calvinpan089c2a62020-03-12 14:17:55 +08005997 Boolean success = (Boolean) sendRequest(
5998 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005999
6000 if (success) {
6001 Settings.Global.putInt(mApp.getContentResolver(),
6002 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
6003 }
calvinpan089c2a62020-03-12 14:17:55 +08006004 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
6005 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 } finally {
6007 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07006008 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006009 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006010
6011 /**
calvinpan677fc2b2020-01-14 20:42:55 +08006012 * Get the allowed network types that store in the telephony provider.
6013 *
6014 * @param subId the id of the subscription.
6015 * @return allowedNetworkTypes the allowed network types.
6016 */
6017 @Override
6018 public long getAllowedNetworkTypes(int subId) {
6019 TelephonyPermissions
6020 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6021 mApp, subId, "getAllowedNetworkTypes");
6022
6023 final long identity = Binder.clearCallingIdentity();
6024 try {
6025 return SubscriptionManager.getLongSubscriptionProperty(
6026 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
6027 } finally {
6028 Binder.restoreCallingIdentity(identity);
6029 }
6030 }
6031
6032 /**
6033 * Set the allowed network types.
6034 *
6035 * @param subId the id of the subscription.
6036 * @param allowedNetworkTypes the allowed network types.
6037 * @return true on success; false on any failure.
6038 */
6039 @Override
6040 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
6041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6042 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08006043
calvinpan089c2a62020-03-12 14:17:55 +08006044 SubscriptionManager.setSubscriptionProperty(subId,
6045 SubscriptionManager.ALLOWED_NETWORK_TYPES,
6046 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08006047
calvinpan089c2a62020-03-12 14:17:55 +08006048 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6049 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6050 RILConstants.PREFERRED_NETWORK_MODE);
6051 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08006052 }
6053
6054 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006055 * Get the allowed network types for certain reason.
6056 *
6057 * @param subId the id of the subscription.
6058 * @param reason the reason the allowed network type change is taking place
6059 * @return the allowed network types.
6060 */
6061 @Override
6062 public long getAllowedNetworkTypesForReason(int subId,
6063 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6064 TelephonyPermissions
6065 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6066 mApp, subId, "getAllowedNetworkTypesForReason");
6067 final long identity = Binder.clearCallingIdentity();
6068 try {
6069 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6070 } finally {
6071 Binder.restoreCallingIdentity(identity);
6072 }
6073 }
6074
6075 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006076 * Enable/Disable E-UTRA-NR Dual Connectivity
6077 * @param subId subscription id of the sim card
6078 * @param nrDualConnectivityState expected NR dual connectivity state
6079 * This can be passed following states
6080 * <ol>
6081 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6082 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6083 * <li>Disable NR dual connectivity and force secondary cell to be released
6084 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6085 * </ol>
6086 * @return operation result.
6087 */
6088 @Override
6089 public int setNrDualConnectivityState(int subId,
6090 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6092 mApp, subId, "enableNRDualConnectivity");
6093 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6094 final long identity = Binder.clearCallingIdentity();
6095 try {
6096 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6097 nrDualConnectivityState, subId,
6098 workSource);
6099 if (DBG) log("enableNRDualConnectivity result: " + result);
6100 return result;
6101 } finally {
6102 Binder.restoreCallingIdentity(identity);
6103 }
6104 }
6105
6106 /**
6107 * Is E-UTRA-NR Dual Connectivity enabled
6108 * @return true if dual connectivity is enabled else false
6109 */
6110 @Override
6111 public boolean isNrDualConnectivityEnabled(int subId) {
6112 TelephonyPermissions
6113 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6114 mApp, subId, "isNRDualConnectivityEnabled");
6115 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6116 final long identity = Binder.clearCallingIdentity();
6117 try {
6118 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6119 null, subId, workSource);
6120 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6121 return isEnabled;
6122 } finally {
6123 Binder.restoreCallingIdentity(identity);
6124 }
6125 }
6126
6127 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006128 * get carrier bandwidth per primary and secondary carrier
6129 * @param subId subscription id of the sim card
6130 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6131 */
6132 @Override
6133 public CarrierBandwidth getCarrierBandwidth(int subId) {
6134 TelephonyPermissions
6135 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6136 mApp, subId, "isNRDualConnectivityEnabled");
6137 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6138 final long identity = Binder.clearCallingIdentity();
6139 try {
6140 CarrierBandwidth carrierBandwidth =
6141 getPhoneFromSubId(subId).getCarrierBandwidth();
6142 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6143 return carrierBandwidth;
6144 } finally {
6145 Binder.restoreCallingIdentity(identity);
6146 }
6147 }
6148
6149 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006150 * Get the effective allowed network types on the device.
6151 * This API will return an intersection of allowed network types for all reasons,
6152 * including the configuration done through setAllowedNetworkTypes
6153 *
6154 * @param subId the id of the subscription.
6155 * @return the allowed network types
6156 */
6157 @Override
6158 public long getEffectiveAllowedNetworkTypes(int subId) {
6159 TelephonyPermissions
6160 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6161 mApp, subId, "getEffectiveAllowedNetworkTypes");
6162 final long identity = Binder.clearCallingIdentity();
6163 try {
6164 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6165 } finally {
6166 Binder.restoreCallingIdentity(identity);
6167 }
6168 }
6169
6170 /**
6171 * Set the allowed network types of the device and
6172 * provide the reason triggering the allowed network change.
6173 *
6174 * @param subId the id of the subscription.
6175 * @param reason the reason the allowed network type change is taking place
6176 * @param allowedNetworkTypes the allowed network types.
6177 * @return true on success; false on any failure.
6178 */
6179 @Override
6180 public boolean setAllowedNetworkTypesForReason(int subId,
6181 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6183 mApp, subId, "setAllowedNetworkTypesForReason");
6184 final long identity = Binder.clearCallingIdentity();
6185 try {
6186 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6187 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6188 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6189 RILConstants.PREFERRED_NETWORK_MODE);
6190 return setPreferredNetworkType(subId, preferredNetworkMode);
6191 } finally {
6192 Binder.restoreCallingIdentity(identity);
6193 }
6194 }
6195
6196 /**
Miaoa84611c2019-03-15 09:21:10 +08006197 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006198 *
Miaoa84611c2019-03-15 09:21:10 +08006199 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006200 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006201 * @hide
6202 */
6203 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006204 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006205 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006206 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006207 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006208 try {
Miaoa84611c2019-03-15 09:21:10 +08006209 if (phone != null) {
6210 return phone.hasMatchedTetherApnSetting();
6211 } else {
6212 return false;
6213 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006214 } finally {
6215 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006216 }
Junda Liu475951f2014-11-07 16:45:03 -08006217 }
6218
6219 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006220 * Enable or disable always reporting signal strength changes from radio.
6221 *
6222 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6223 */
6224 @Override
6225 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6226 enforceModifyPermission();
6227 enforceSystemCaller();
6228
6229 final long identity = Binder.clearCallingIdentity();
6230 final Phone phone = getPhone(subId);
6231 try {
6232 if (phone != null) {
6233 if (DBG) {
6234 log("setAlwaysReportSignalStrength: subId=" + subId
6235 + " isEnable=" + isEnable);
6236 }
6237 phone.setAlwaysReportSignalStrength(isEnable);
6238 } else {
6239 loge("setAlwaysReportSignalStrength: no phone found for subId="
6240 + subId);
6241 }
6242 } finally {
6243 Binder.restoreCallingIdentity(identity);
6244 }
6245 }
6246
6247 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006248 * Get the user enabled state of Mobile Data.
6249 *
6250 * TODO: remove and use isUserDataEnabled.
6251 * This can't be removed now because some vendor codes
6252 * calls through ITelephony directly while they should
6253 * use TelephonyManager.
6254 *
6255 * @return true on enabled
6256 */
6257 @Override
6258 public boolean getDataEnabled(int subId) {
6259 return isUserDataEnabled(subId);
6260 }
6261
6262 /**
6263 * Get whether mobile data is enabled per user setting.
6264 *
6265 * There are other factors deciding whether mobile data is actually enabled, but they are
6266 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006267 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006268 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006269 *
6270 * @return {@code true} if data is enabled else {@code false}
6271 */
6272 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006273 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006274 try {
6275 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6276 null);
6277 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6279 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006280 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006281
6282 final long identity = Binder.clearCallingIdentity();
6283 try {
6284 int phoneId = mSubscriptionController.getPhoneId(subId);
6285 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6286 Phone phone = PhoneFactory.getPhone(phoneId);
6287 if (phone != null) {
6288 boolean retVal = phone.isUserDataEnabled();
6289 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6290 return retVal;
6291 } else {
6292 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6293 return false;
6294 }
6295 } finally {
6296 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006297 }
6298 }
6299
6300 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006301 * Checks if the device is capable of mobile data by considering whether whether the
6302 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6303 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006304 *
Shuo Qian985d1232020-01-08 14:30:06 -08006305 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006306 */
6307 @Override
6308 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006309 try {
6310 try {
6311 mApp.enforceCallingOrSelfPermission(
6312 android.Manifest.permission.ACCESS_NETWORK_STATE,
6313 null);
6314 } catch (Exception e) {
6315 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6316 "isDataEnabled");
6317 }
6318 } catch (Exception e) {
6319 enforceReadPrivilegedPermission("isDataEnabled");
6320 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006321
6322 final long identity = Binder.clearCallingIdentity();
6323 try {
6324 int phoneId = mSubscriptionController.getPhoneId(subId);
6325 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6326 Phone phone = PhoneFactory.getPhone(phoneId);
6327 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006328 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006329 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6330 return retVal;
6331 } else {
6332 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6333 return false;
6334 }
6335 } finally {
6336 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006337 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006338 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006339
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006340 /**
6341 * Check if data is enabled for a specific reason
6342 * @param subId Subscription index
6343 * @param reason the reason the data enable change is taking place
6344 * @return {@code true} if the overall data is enabled; {@code false} if not.
6345 */
6346 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006347 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006348 @TelephonyManager.DataEnabledReason int reason) {
6349 try {
6350 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6351 null);
6352 } catch (Exception e) {
6353 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006354 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006355 }
6356
6357
6358 final long identity = Binder.clearCallingIdentity();
6359 try {
6360 int phoneId = mSubscriptionController.getPhoneId(subId);
6361 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006362 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006363 + " reason=" + reason);
6364 }
6365 Phone phone = PhoneFactory.getPhone(phoneId);
6366 if (phone != null) {
6367 boolean retVal;
6368 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6369 retVal = phone.isUserDataEnabled();
6370 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006371 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006372 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006373 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006374 return retVal;
6375 } else {
6376 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006377 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006378 + subId + " retVal=false");
6379 }
6380 return false;
6381 }
6382 } finally {
6383 Binder.restoreCallingIdentity(identity);
6384 }
6385 }
6386
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006387 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006388 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006389 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6390 // Skip the check if it's one of these special uids
6391 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6392 }
6393
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006394 //load access rules from carrier configs, and check those as well: b/139133814
6395 SubscriptionController subController = SubscriptionController.getInstance();
6396 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6397 || subController == null) return privilegeFromSim;
6398
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006399 PackageManager pkgMgr = phone.getContext().getPackageManager();
6400 String[] packages = pkgMgr.getPackagesForUid(uid);
6401
6402 final long identity = Binder.clearCallingIdentity();
6403 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006404 int subId = phone.getSubId();
6405 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6406 // A test override is in place for the privileges for this subId, so don't try to
6407 // read the subscription privileges.
6408 return privilegeFromSim;
6409 }
6410 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006411 SubscriptionManager subManager = (SubscriptionManager)
6412 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6413 for (String pkg : packages) {
6414 if (subManager.canManageSubscription(subInfo, pkg)) {
6415 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6416 }
6417 }
6418 return privilegeFromSim;
6419 } finally {
6420 Binder.restoreCallingIdentity(identity);
6421 }
6422 }
6423
6424 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6425 String pkgName) {
6426 //load access rules from carrier configs, and check those as well: b/139133814
6427 SubscriptionController subController = SubscriptionController.getInstance();
6428 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6429 || subController == null) return privilegeFromSim;
6430
6431 final long identity = Binder.clearCallingIdentity();
6432 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006433 int subId = phone.getSubId();
6434 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6435 // A test override is in place for the privileges for this subId, so don't try to
6436 // read the subscription privileges.
6437 return privilegeFromSim;
6438 }
6439 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006440 SubscriptionManager subManager = (SubscriptionManager)
6441 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6442 return subManager.canManageSubscription(subInfo, pkgName)
6443 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6444 } finally {
6445 Binder.restoreCallingIdentity(identity);
6446 }
6447 }
6448
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006449 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006450 public int getCarrierPrivilegeStatus(int subId) {
6451 final Phone phone = getPhone(subId);
6452 if (phone == null) {
6453 loge("getCarrierPrivilegeStatus: Invalid subId");
6454 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6455 }
6456 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006457 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006458 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006459 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6460 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006461
6462 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6463 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006464 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006465 }
Junda Liu29340342014-07-10 15:23:27 -07006466
6467 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006468 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006469 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006470 final Phone phone = getPhone(subId);
6471 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006472 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006473 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6474 }
6475 UiccProfile profile =
6476 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6477 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006478 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006479 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6480 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006481 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006482 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006483 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006484 }
6485
6486 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006487 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6488 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006489 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006490 }
6491
6492 int phoneId = SubscriptionManager.getPhoneId(subId);
6493 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006494 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006495 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006496 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6497 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006498 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6499 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6500 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006501 }
6502
6503 @Override
6504 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006505 if (TextUtils.isEmpty(pkgName))
6506 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006507 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6508 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6509 UiccCard card = UiccController.getInstance().getUiccCard(i);
6510 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006511 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006512 continue;
6513 }
6514
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006515 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6516 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6517 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006518 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6519 break;
6520 }
6521 }
6522
6523 return result;
Junda Liu29340342014-07-10 15:23:27 -07006524 }
Derek Tan89e89d42014-07-08 17:00:10 -07006525
6526 @Override
Junda Liue64de782015-04-16 17:19:16 -07006527 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6528 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6529 loge("phoneId " + phoneId + " is not valid.");
6530 return null;
6531 }
6532 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006533 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006534 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006535 return null ;
6536 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006537 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006538 }
6539
Amith Yamasani6e118872016-02-19 12:53:51 -08006540 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006541 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006542 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006543 List<String> privilegedPackages = new ArrayList<>();
6544 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006545 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6546 // has UICC in that slot.
6547 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006548 if (card.hasCarrierPrivilegeRules()) {
6549 if (packages == null) {
6550 // Only check packages in user 0 for now
6551 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006552 PackageManager.MATCH_DISABLED_COMPONENTS
6553 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006554 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006555 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006556 }
6557 for (int p = packages.size() - 1; p >= 0; p--) {
6558 PackageInfo pkgInfo = packages.get(p);
6559 if (pkgInfo != null && pkgInfo.packageName != null
6560 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006561 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006562 privilegedPackages.add(pkgInfo.packageName);
6563 }
6564 }
6565 }
6566 }
6567 return privilegedPackages;
6568 }
6569
chen xuf7e9fe82019-05-09 19:31:02 -07006570 @Override
6571 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006572 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6573
6574 final long identity = Binder.clearCallingIdentity();
6575
chen xuf7e9fe82019-05-09 19:31:02 -07006576 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006577 try {
6578 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6579 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6580 }
6581 } finally {
6582 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006583 }
6584 return privilegedPackages;
6585 }
6586
Wink Savilleb564aae2014-10-23 10:18:09 -07006587 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006588 final Phone phone = getPhone(subId);
6589 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006590 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006591 return null;
6592 }
6593 String iccId = card.getIccId();
6594 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006595 return null;
6596 }
6597 return iccId;
6598 }
6599
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006600 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006601 public void setCallComposerStatus(int subId, int status) {
6602 enforceModifyPermission();
6603
6604 final long identity = Binder.clearCallingIdentity();
6605 try {
6606 Phone phone = getPhone(subId);
6607 if (phone != null) {
6608 Phone defaultPhone = phone.getImsPhone();
6609 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6610 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6611 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006612 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6613 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006614 }
6615 }
Shuo Qiand8782462020-12-22 19:10:14 -08006616 } catch (ImsException e) {
6617 throw new ServiceSpecificException(e.getCode());
6618 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006619 Binder.restoreCallingIdentity(identity);
6620 }
6621 }
6622
6623 @Override
6624 public int getCallComposerStatus(int subId) {
6625 enforceReadPrivilegedPermission("getCallComposerStatus");
6626
6627 final long identity = Binder.clearCallingIdentity();
6628 try {
6629 Phone phone = getPhone(subId);
6630 if (phone != null) {
6631 Phone defaultPhone = phone.getImsPhone();
6632 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6633 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6634 return imsPhone.getCallComposerStatus();
6635 }
6636 }
6637 } finally {
6638 Binder.restoreCallingIdentity(identity);
6639 }
6640 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6641 }
6642
6643 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006644 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6645 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006646 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006647 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006648
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006649 final long identity = Binder.clearCallingIdentity();
6650 try {
6651 final String iccId = getIccId(subId);
6652 final Phone phone = getPhone(subId);
6653 if (phone == null) {
6654 return false;
6655 }
6656 final String subscriberId = phone.getSubscriberId();
6657
6658 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006659 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006660 + subscriberId + " to " + number);
6661 }
6662
6663 if (TextUtils.isEmpty(iccId)) {
6664 return false;
6665 }
6666
6667 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6668
6669 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6670 if (alphaTag == null) {
6671 editor.remove(alphaTagPrefKey);
6672 } else {
6673 editor.putString(alphaTagPrefKey, alphaTag);
6674 }
6675
6676 // Record both the line number and IMSI for this ICCID, since we need to
6677 // track all merged IMSIs based on line number
6678 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6679 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6680 if (number == null) {
6681 editor.remove(numberPrefKey);
6682 editor.remove(subscriberPrefKey);
6683 } else {
6684 editor.putString(numberPrefKey, number);
6685 editor.putString(subscriberPrefKey, subscriberId);
6686 }
6687
6688 editor.commit();
6689 return true;
6690 } finally {
6691 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006692 }
Derek Tan7226c842014-07-02 17:42:23 -07006693 }
6694
6695 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006696 public String getLine1NumberForDisplay(int subId, String callingPackage,
6697 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006698 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006699 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006700 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006701 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006702 return null;
6703 }
Derek Tan97ebb422014-09-05 16:55:38 -07006704
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006705 final long identity = Binder.clearCallingIdentity();
6706 try {
6707 String iccId = getIccId(subId);
6708 if (iccId != null) {
6709 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6710 if (DBG_MERGE) {
6711 log("getLine1NumberForDisplay returning "
6712 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6713 }
6714 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006716 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6717 return null;
6718 } finally {
6719 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006720 }
Derek Tan7226c842014-07-02 17:42:23 -07006721 }
6722
6723 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006724 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6725 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006726 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006727 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006728 return null;
6729 }
Derek Tan97ebb422014-09-05 16:55:38 -07006730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006731 final long identity = Binder.clearCallingIdentity();
6732 try {
6733 String iccId = getIccId(subId);
6734 if (iccId != null) {
6735 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6736 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6737 }
6738 return null;
6739 } finally {
6740 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006741 }
Derek Tan7226c842014-07-02 17:42:23 -07006742 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006743
6744 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006745 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6746 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006747 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6748 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006749 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006750 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006751 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006752 return null;
6753 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006754
Jordan Liub49b04b2019-05-06 14:45:15 -07006755 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6756 // the process, where TelephonyManager was instantiated.
6757 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006758 final long identity = Binder.clearCallingIdentity();
6759 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006760 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006761 final TelephonyManager tele = TelephonyManager.from(context);
6762 final SubscriptionManager sub = SubscriptionManager.from(context);
6763
6764 // Figure out what subscribers are currently active
6765 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006766
Jordan Liub49b04b2019-05-06 14:45:15 -07006767 // Only consider subs which match the current subId
6768 // This logic can be simplified. See b/131189269 for progress.
6769 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006770 activeSubscriberIds.add(tele.getSubscriberId(subId));
6771 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772
6773 // First pass, find a number override for an active subscriber
6774 String mergeNumber = null;
6775 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6776 for (String key : prefs.keySet()) {
6777 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6778 final String subscriberId = (String) prefs.get(key);
6779 if (activeSubscriberIds.contains(subscriberId)) {
6780 final String iccId = key.substring(
6781 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6782 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6783 mergeNumber = (String) prefs.get(numberKey);
6784 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006785 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006786 + " for active subscriber " + subscriberId);
6787 }
6788 if (!TextUtils.isEmpty(mergeNumber)) {
6789 break;
6790 }
6791 }
6792 }
6793 }
6794
6795 // Shortcut when no active merged subscribers
6796 if (TextUtils.isEmpty(mergeNumber)) {
6797 return null;
6798 }
6799
6800 // Second pass, find all subscribers under that line override
6801 final ArraySet<String> result = new ArraySet<>();
6802 for (String key : prefs.keySet()) {
6803 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6804 final String number = (String) prefs.get(key);
6805 if (mergeNumber.equals(number)) {
6806 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6807 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6808 final String subscriberId = (String) prefs.get(subscriberKey);
6809 if (!TextUtils.isEmpty(subscriberId)) {
6810 result.add(subscriberId);
6811 }
6812 }
6813 }
6814 }
6815
6816 final String[] resultArray = result.toArray(new String[result.size()]);
6817 Arrays.sort(resultArray);
6818 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006819 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006820 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6821 }
6822 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006823 } finally {
6824 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006825 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006826 }
6827
6828 @Override
zoey chen38003472019-12-13 17:16:31 +08006829 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6830 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006831
6832 final long identity = Binder.clearCallingIdentity();
6833 try {
6834 final TelephonyManager telephonyManager = mApp.getSystemService(
6835 TelephonyManager.class);
6836 String subscriberId = telephonyManager.getSubscriberId(subId);
6837 if (subscriberId == null) {
6838 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006839 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006840 + subId);
6841 }
6842 return null;
6843 }
6844
6845 final SubscriptionInfo info = SubscriptionController.getInstance()
6846 .getSubscriptionInfo(subId);
6847 final ParcelUuid groupUuid = info.getGroupUuid();
6848 // If it doesn't belong to any group, return just subscriberId of itself.
6849 if (groupUuid == null) {
6850 return new String[]{subscriberId};
6851 }
6852
6853 // Get all subscriberIds from the group.
6854 final List<String> mergedSubscriberIds = new ArrayList<>();
6855 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006856 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006857 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006858 for (SubscriptionInfo subInfo : groupInfos) {
6859 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6860 if (subscriberId != null) {
6861 mergedSubscriberIds.add(subscriberId);
6862 }
6863 }
6864
6865 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6866 } finally {
6867 Binder.restoreCallingIdentity(identity);
6868
6869 }
6870 }
6871
6872 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006873 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006874 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006875 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006876
6877 final long identity = Binder.clearCallingIdentity();
6878 try {
6879 final Phone phone = getPhone(subId);
6880 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6881 } finally {
6882 Binder.restoreCallingIdentity(identity);
6883 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006884 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006885
6886 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006887 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006888 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6889 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006890 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6891 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006892
6893 final long identity = Binder.clearCallingIdentity();
6894 try {
6895 final Phone phone = getPhone(subId);
6896 if (phone == null) {
6897 return false;
6898 }
6899 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6900 cdmaNonRoamingList);
6901 } finally {
6902 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006903 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006904 }
6905
6906 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006907 @Deprecated
6908 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6909 enforceModifyPermission();
6910
6911 int returnValue = 0;
6912 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006913 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006914 if(result.exception == null) {
6915 if (result.result != null) {
6916 byte[] responseData = (byte[])(result.result);
6917 if(responseData.length > oemResp.length) {
6918 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6919 responseData.length + "bytes. Buffer Size is " +
6920 oemResp.length + "bytes.");
6921 }
6922 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6923 returnValue = responseData.length;
6924 }
6925 } else {
6926 CommandException ex = (CommandException) result.exception;
6927 returnValue = ex.getCommandError().ordinal();
6928 if(returnValue > 0) returnValue *= -1;
6929 }
6930 } catch (RuntimeException e) {
6931 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6932 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6933 if(returnValue > 0) returnValue *= -1;
6934 }
6935
6936 return returnValue;
6937 }
6938
6939 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006940 public void setRadioCapability(RadioAccessFamily[] rafs) {
6941 try {
6942 ProxyController.getInstance().setRadioCapability(rafs);
6943 } catch (RuntimeException e) {
6944 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6945 }
6946 }
6947
6948 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006949 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006950 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006951 try {
6952 TelephonyPermissions
6953 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6954 mApp, phone.getSubId(), "getRadioAccessFamily");
6955 } catch (SecurityException e) {
6956 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6957 throw e;
6958 }
chen xub97461a2018-10-26 14:17:57 -07006959 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006960 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006961 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006962 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006963 final long identity = Binder.clearCallingIdentity();
6964 try {
chen xub97461a2018-10-26 14:17:57 -07006965 TelephonyPermissions
6966 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6967 mApp, phone.getSubId(), "getRadioAccessFamily");
6968 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006969 } finally {
6970 Binder.restoreCallingIdentity(identity);
6971 }
chen xub97461a2018-10-26 14:17:57 -07006972 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006973 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006974
6975 @Override
6976 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006977 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006978 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006979
6980 final long identity = Binder.clearCallingIdentity();
6981 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006982 ImsManager.getInstance(defaultPhone.getContext(),
6983 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006984 } finally {
6985 Binder.restoreCallingIdentity(identity);
6986 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006987 }
6988
6989 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006990 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006991 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006992 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6993 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006994 return false;
6995 }
Svet Ganovb320e182015-04-16 12:30:10 -07006996
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006997 final long identity = Binder.clearCallingIdentity();
6998 try {
6999 // Check the user preference and the system-level IMS setting. Even if the user has
7000 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7001 // In the long run, we may instead need to check if there exists a connection service
7002 // which can support video calling.
7003 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007004 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007005 return imsManager.isVtEnabledByPlatform()
7006 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7007 && imsManager.isVtEnabledByUser();
7008 } finally {
7009 Binder.restoreCallingIdentity(identity);
7010 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007011 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007012
Andrew Leea1239f22015-03-02 17:44:07 -08007013 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007014 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7015 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007016 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007017 mApp, subId, callingPackage, callingFeatureId,
7018 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019 return false;
7020 }
7021
7022 final long identity = Binder.clearCallingIdentity();
7023 try {
7024 CarrierConfigManager configManager =
7025 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007026 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007027 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7028 } finally {
7029 Binder.restoreCallingIdentity(identity);
7030 }
Andrew Leea1239f22015-03-02 17:44:07 -08007031 }
7032
7033 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007034 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007036 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007037 return false;
7038 }
7039
7040 final long identity = Binder.clearCallingIdentity();
7041 try {
7042 CarrierConfigManager configManager =
7043 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007044 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007045 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7046 } finally {
7047 Binder.restoreCallingIdentity(identity);
7048 }
Andrew Leea1239f22015-03-02 17:44:07 -08007049 }
7050
Andrew Lee9431b832015-03-09 18:46:45 -07007051 @Override
7052 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007053 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007054 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007055 }
7056
7057 @Override
7058 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007059 final long identity = Binder.clearCallingIdentity();
7060 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007061 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007062 } finally {
7063 Binder.restoreCallingIdentity(identity);
7064 }
Andrew Lee9431b832015-03-09 18:46:45 -07007065 }
7066
Hall Liuf6668912018-10-31 17:05:23 -07007067 /**
7068 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7069 * support for the feature and device firmware support.
7070 *
7071 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7072 */
7073 @Override
7074 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007075 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007076 final Phone phone = getPhone(subscriptionId);
7077 if (phone == null) {
7078 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7079 return false;
7080 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007081 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007082 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7084 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007085 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007086 return isCarrierSupported && isDeviceSupported;
7087 } finally {
7088 Binder.restoreCallingIdentity(identity);
7089 }
Hall Liu98187582018-01-22 19:15:32 -08007090 }
7091
Hall Liuf6668912018-10-31 17:05:23 -07007092 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007093 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7094 * RTT setting, will return true if the device and carrier both support RTT.
7095 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007096 */
7097 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007098 final long identity = Binder.clearCallingIdentity();
7099 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007100 boolean isRttSupported = isRttSupported(subscriptionId);
7101 boolean isUserRttSettingOn = Settings.Secure.getInt(
7102 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7103 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7104 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7105 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106 } finally {
7107 Binder.restoreCallingIdentity(identity);
7108 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007109 }
7110
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007111 @Deprecated
7112 @Override
7113 public String getDeviceId(String callingPackage) {
7114 return getDeviceIdWithFeature(callingPackage, null);
7115 }
7116
Sanket Padawe7310cc72015-01-14 09:53:20 -08007117 /**
7118 * Returns the unique device ID of phone, for example, the IMEI for
7119 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7120 *
7121 * <p>Requires Permission:
7122 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7123 */
7124 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007125 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007126 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007127 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007128 return null;
7129 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007130 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007131 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007132 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007133 return null;
7134 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007135
7136 final long identity = Binder.clearCallingIdentity();
7137 try {
7138 return phone.getDeviceId();
7139 } finally {
7140 Binder.restoreCallingIdentity(identity);
7141 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007142 }
7143
Ping Sunc67b7c22016-03-02 19:16:45 +08007144 /**
7145 * {@hide}
7146 * Returns the IMS Registration Status on a particular subid
7147 *
7148 * @param subId
7149 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007150 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007151 Phone phone = getPhone(subId);
7152 if (phone != null) {
7153 return phone.isImsRegistered();
7154 } else {
7155 return false;
7156 }
7157 }
7158
Santos Cordon7a1885b2015-02-03 11:15:19 -08007159 @Override
7160 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007161 final long identity = Binder.clearCallingIdentity();
7162 try {
7163 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7164 } finally {
7165 Binder.restoreCallingIdentity(identity);
7166 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007167 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007168
Tyler Gunnf70ed162019-04-03 15:28:53 -07007169 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007170 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007171 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007173 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007174 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7175 }
7176 final long identity = Binder.clearCallingIdentity();
7177 try {
7178 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7179 } finally {
7180 Binder.restoreCallingIdentity(identity);
7181 }
7182 }
7183
7184 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007185 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007186 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7187 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007188 final long identity = Binder.clearCallingIdentity();
7189 try {
7190 Phone phone = getPhone(subscriptionId);
7191 if (phone == null) {
7192 return null;
7193 }
7194 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7195 } finally {
7196 Binder.restoreCallingIdentity(identity);
7197 }
7198 }
7199
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007200 /**
7201 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007202 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007203 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007204 final long identity = Binder.clearCallingIdentity();
7205 try {
7206 Phone phone = getPhone(subId);
7207 if (phone != null) {
7208 return phone.isWifiCallingEnabled();
7209 } else {
7210 return false;
7211 }
7212 } finally {
7213 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007214 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007215 }
7216
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007217 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007218 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007219 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007220 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007221 final long identity = Binder.clearCallingIdentity();
7222 try {
7223 Phone phone = getPhone(subId);
7224 if (phone != null) {
7225 return phone.isVideoEnabled();
7226 } else {
7227 return false;
7228 }
7229 } finally {
7230 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007231 }
7232 }
7233
7234 /**
7235 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7236 * defined in {@link ImsRegistrationImplBase}.
7237 */
7238 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007239 final long identity = Binder.clearCallingIdentity();
7240 try {
7241 Phone phone = getPhone(subId);
7242 if (phone != null) {
7243 return phone.getImsRegistrationTech();
7244 } else {
7245 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7246 }
7247 } finally {
7248 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007249 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007250 }
7251
Stuart Scott8eef64f2015-04-08 15:13:54 -07007252 @Override
7253 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007254 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007255 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7256 return;
7257 }
7258
Svet Ganovcc087f82015-05-12 20:35:54 -07007259 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007260
Svet Ganovcc087f82015-05-12 20:35:54 -07007261 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007262 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7263 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007264 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007265 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007266 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007267 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007268 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7269 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007270 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007271 // There has been issues when Sms raw table somehow stores orphan
7272 // fragments. They lead to garbled message when new fragments come
7273 // in and combined with those stale ones. In case this happens again,
7274 // user can reset all network settings which will clean up this table.
7275 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007276 // Clean up IMS settings as well here.
7277 int slotId = getSlotIndex(subId);
7278 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7279 ImsManager.getInstance(mApp, slotId).factoryReset();
7280 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007281
7282 // Erase modem config if erase modem on network setting is enabled.
7283 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7284 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7285 if (configValue != null && Boolean.parseBoolean(configValue)) {
7286 sendEraseModemConfig(getDefaultPhone());
7287 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007288 } finally {
7289 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007290 }
7291 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007292
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007293 private void cleanUpSmsRawTable(Context context) {
7294 ContentResolver resolver = context.getContentResolver();
7295 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7296 resolver.delete(uri, null, null);
7297 }
7298
Narayan Kamath1c496c22015-04-16 14:40:19 +01007299 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007300 public String getSimLocaleForSubscriber(int subId) {
7301 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7302 final Phone phone = getPhone(subId);
7303 if (phone == null) {
7304 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007305 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007306 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007307 final long identity = Binder.clearCallingIdentity();
7308 try {
chen xu5d3637b2019-01-21 23:31:38 -08007309 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007310 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007311 if (info == null) {
7312 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7313 return null;
7314 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007315 // Try and fetch the locale from the carrier properties or from the SIM language
7316 // preferences (EF-PL and EF-LI)...
7317 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007318 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007319 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7320 if (localeFromDefaultSim != null) {
7321 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7322 if (DBG) log("Using locale from subId: " + subId + " locale: "
7323 + localeFromDefaultSim);
7324 return localeFromDefaultSim.toLanguageTag();
7325 } else {
7326 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327 }
7328 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007330 // The SIM language preferences only store a language (e.g. fr = French), not an
7331 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7332 // the SIM and carrier preferences does not include a country we add the country
7333 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007334 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007335 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007336 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007337 return mccLocale.toLanguageTag();
7338 }
7339
7340 if (DBG) log("No locale found - returning null");
7341 return null;
7342 } finally {
7343 Binder.restoreCallingIdentity(identity);
7344 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007345 }
7346
7347 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007348 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007349 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007350 }
7351
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007352 /**
7353 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7354 */
7355 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007356 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007357 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007358 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007359
Chenjie Yu1ba97252018-01-11 18:16:20 -08007360 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007361 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007362
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007363 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007364 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7365 * representing the state of the modem.
7366 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007367 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7368 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007369 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007370 */
7371 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007372 public void requestModemActivityInfo(ResultReceiver result) {
7373 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007374 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007375
7376 final long identity = Binder.clearCallingIdentity();
7377 try {
sqian1a1be542020-03-05 11:37:28 -08007378 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007379 } finally {
7380 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007381 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007382 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007383
Siddharth Rayb8114062018-06-17 15:02:38 -07007384 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7385 // less than total activity duration.
7386 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7387 if (info == null) {
7388 return false;
7389 }
7390 int activityDurationMs =
7391 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7392 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007393 int[] txTimeMs = info.getTransmitTimeMillis();
7394 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7395 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007396 }
7397 return (info.isValid()
7398 && (info.getSleepTimeMillis() <= activityDurationMs)
7399 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007400 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007401 && (totalTxTimeMs <= activityDurationMs));
7402 }
7403
Jack Yu85bd38a2015-11-09 11:34:32 -08007404 /**
7405 * {@hide}
7406 * Returns the service state information on specified subscription.
7407 */
7408 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007409 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7410 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007411 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007412 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007413 return null;
7414 }
7415
Hall Liuf19c44f2018-11-27 14:38:17 -08007416 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7417 LocationAccessPolicy.checkLocationPermission(mApp,
7418 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7419 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007420 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007421 .setCallingPid(Binder.getCallingPid())
7422 .setCallingUid(Binder.getCallingUid())
7423 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007424 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007425 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7426 .build());
7427
7428 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7429 LocationAccessPolicy.checkLocationPermission(mApp,
7430 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7431 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007432 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007433 .setCallingPid(Binder.getCallingPid())
7434 .setCallingUid(Binder.getCallingUid())
7435 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007436 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007437 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7438 .build());
7439 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7440 boolean hasFinePermission =
7441 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7442 boolean hasCoarsePermission =
7443 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7444
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445 final long identity = Binder.clearCallingIdentity();
7446 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007447 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7448 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7449 Rlog.d(LOG_TAG,
7450 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7451 return null;
7452 }
7453
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007454 final Phone phone = getPhone(subId);
7455 if (phone == null) {
7456 return null;
7457 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007458
Hall Liuf19c44f2018-11-27 14:38:17 -08007459 ServiceState ss = phone.getServiceState();
7460
7461 // Scrub out the location info in ServiceState depending on what level of access
7462 // the caller has.
7463 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007464 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7465 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007466 } finally {
7467 Binder.restoreCallingIdentity(identity);
7468 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007469 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007470
7471 /**
7472 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7473 *
7474 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7475 * voicemail ringtone.
7476 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7477 * PhoneAccount.
7478 */
7479 @Override
7480 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481 final long identity = Binder.clearCallingIdentity();
7482 try {
7483 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7484 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007485 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007487
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7489 } finally {
7490 Binder.restoreCallingIdentity(identity);
7491 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007492 }
7493
7494 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007495 * Sets the per-account voicemail ringtone.
7496 *
7497 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7498 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7499 *
7500 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7501 * voicemail ringtone.
7502 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7503 * PhoneAccount.
7504 */
7505 @Override
7506 public void setVoicemailRingtoneUri(String callingPackage,
7507 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007508 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007509 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007510 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7511 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007512 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7513 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7514 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007515 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007516
7517 final long identity = Binder.clearCallingIdentity();
7518 try {
7519 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7520 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007521 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 }
7523 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7524 } finally {
7525 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007526 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007527 }
7528
7529 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007530 * Returns whether vibration is set for voicemail notification in Phone settings.
7531 *
7532 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7533 * voicemail vibration setting.
7534 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7535 */
7536 @Override
7537 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538 final long identity = Binder.clearCallingIdentity();
7539 try {
7540 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7541 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007542 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007544
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7546 } finally {
7547 Binder.restoreCallingIdentity(identity);
7548 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007549 }
7550
Youhan Wange64578a2016-05-02 15:32:42 -07007551 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007552 * Sets the per-account voicemail vibration.
7553 *
7554 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7555 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7556 *
7557 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7558 * voicemail vibration setting.
7559 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7560 * specific PhoneAccount.
7561 */
7562 @Override
7563 public void setVoicemailVibrationEnabled(String callingPackage,
7564 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007565 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007566 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007567 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7568 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7570 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7571 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007572 }
7573
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007574 final long identity = Binder.clearCallingIdentity();
7575 try {
7576 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7577 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007578 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007579 }
7580 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7581 } finally {
7582 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007583 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007584 }
7585
7586 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007587 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7588 *
7589 * @throws SecurityException if the caller does not have the required permission
7590 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007591 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007592 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007593 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007594 }
7595
7596 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007597 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7598 * permission.
7599 *
7600 * @throws SecurityException if the caller does not have the required permission
7601 */
7602 private void enforceSendSmsPermission() {
7603 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7604 }
7605
7606 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007607 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007608 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007609 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007610 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007611 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007612 final long identity = Binder.clearCallingIdentity();
7613 try {
7614 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007615 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007616 if (componentName == null) {
7617 throw new SecurityException(
7618 "Caller not current active visual voicemail package[null]");
7619 }
7620 String vvmPackage = componentName.getPackageName();
7621 if (!callingPackage.equals(vvmPackage)) {
7622 throw new SecurityException("Caller not current active visual voicemail package["
7623 + vvmPackage + "]");
7624 }
7625 } finally {
7626 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007627 }
7628 }
7629
7630 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007631 * Return the application ID for the app type.
7632 *
7633 * @param subId the subscription ID that this request applies to.
7634 * @param appType the uicc app type.
7635 * @return Application ID for specificied app type, or null if no uicc.
7636 */
7637 @Override
7638 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007639 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007640 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007641
7642 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007643 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007644 if (phone == null) {
7645 return null;
7646 }
7647 String aid = null;
7648 try {
7649 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7650 .getApplicationByType(appType).getAid();
7651 } catch (Exception e) {
7652 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7653 }
7654 return aid;
7655 } finally {
7656 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007657 }
Youhan Wange64578a2016-05-02 15:32:42 -07007658 }
7659
Youhan Wang4001d252016-05-11 10:29:41 -07007660 /**
7661 * Return the Electronic Serial Number.
7662 *
7663 * @param subId the subscription ID that this request applies to.
7664 * @return ESN or null if error.
7665 */
7666 @Override
7667 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007668 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007669 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007670
7671 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007672 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007673 if (phone == null) {
7674 return null;
7675 }
7676 String esn = null;
7677 try {
7678 esn = phone.getEsn();
7679 } catch (Exception e) {
7680 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7681 }
7682 return esn;
7683 } finally {
7684 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007685 }
Youhan Wang4001d252016-05-11 10:29:41 -07007686 }
7687
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007688 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007689 * Return the Preferred Roaming List Version.
7690 *
7691 * @param subId the subscription ID that this request applies to.
7692 * @return PRLVersion or null if error.
7693 */
7694 @Override
7695 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007696 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007697 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007698
7699 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007700 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701 if (phone == null) {
7702 return null;
7703 }
7704 String cdmaPrlVersion = null;
7705 try {
7706 cdmaPrlVersion = phone.getCdmaPrlVersion();
7707 } catch (Exception e) {
7708 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7709 }
7710 return cdmaPrlVersion;
7711 } finally {
7712 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007713 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007714 }
7715
7716 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007717 * Get snapshot of Telephony histograms
7718 * @return List of Telephony histograms
7719 * @hide
7720 */
7721 @Override
7722 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007723 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7724 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007725
7726 final long identity = Binder.clearCallingIdentity();
7727 try {
7728 return RIL.getTelephonyRILTimingHistograms();
7729 } finally {
7730 Binder.restoreCallingIdentity(identity);
7731 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007732 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007733
7734 /**
7735 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007736 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7737 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007738 * Require system privileges. In the future we may add this to carrier APIs.
7739 *
Michele Berionne482f8202018-11-27 18:57:59 -08007740 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007741 */
7742 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007743 @TelephonyManager.SetCarrierRestrictionResult
7744 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007745 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007746 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007747
Michele Berionne482f8202018-11-27 18:57:59 -08007748 if (carrierRestrictionRules == null) {
7749 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007750 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007752 final long identity = Binder.clearCallingIdentity();
7753 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007754 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007755 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007756 } finally {
7757 Binder.restoreCallingIdentity(identity);
7758 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007759 }
7760
7761 /**
7762 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007763 * Get the allowed carrier list and the excluded carrier list, including the priority between
7764 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007765 * Require system privileges. In the future we may add this to carrier APIs.
7766 *
Michele Berionne482f8202018-11-27 18:57:59 -08007767 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007768 */
7769 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007770 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007771 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007772 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007773
7774 final long identity = Binder.clearCallingIdentity();
7775 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007776 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7777 if (response instanceof CarrierRestrictionRules) {
7778 return (CarrierRestrictionRules) response;
7779 }
7780 // Response is an Exception of some kind,
7781 // which is signalled to the user as a NULL retval
7782 return null;
7783 } catch (Exception e) {
7784 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7785 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007786 } finally {
7787 Binder.restoreCallingIdentity(identity);
7788 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007789 }
7790
fionaxu59545b42016-05-25 15:53:37 -07007791 /**
fionaxu59545b42016-05-25 15:53:37 -07007792 * Action set from carrier signalling broadcast receivers to enable/disable radio
7793 * @param subId the subscription ID that this action applies to.
7794 * @param enabled control enable or disable radio.
7795 * {@hide}
7796 */
7797 @Override
7798 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7799 enforceModifyPermission();
7800 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007801
7802 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007803 if (phone == null) {
7804 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7805 return;
7806 }
7807 try {
7808 phone.carrierActionSetRadioEnabled(enabled);
7809 } catch (Exception e) {
7810 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007811 } finally {
7812 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007813 }
7814 }
7815
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007816 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007817 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7818 * network status based on which carrier apps could apply actions accordingly,
7819 * enable/disable default url handler for example.
7820 *
7821 * @param subId the subscription ID that this action applies to.
7822 * @param report control start/stop reporting the default network status.
7823 * {@hide}
7824 */
7825 @Override
7826 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7827 enforceModifyPermission();
7828 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007829
7830 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007831 if (phone == null) {
7832 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7833 return;
7834 }
7835 try {
7836 phone.carrierActionReportDefaultNetworkStatus(report);
7837 } catch (Exception e) {
7838 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007839 } finally {
7840 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007841 }
7842 }
7843
7844 /**
fionaxud9622282017-07-17 17:51:30 -07007845 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7846 * @param subId the subscription ID that this action applies to.
7847 * {@hide}
7848 */
7849 @Override
7850 public void carrierActionResetAll(int subId) {
7851 enforceModifyPermission();
7852 final Phone phone = getPhone(subId);
7853 if (phone == null) {
7854 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7855 return;
7856 }
7857 try {
7858 phone.carrierActionResetAll();
7859 } catch (Exception e) {
7860 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7861 }
7862 }
7863
7864 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007865 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7866 * bug report is being generated.
7867 */
7868 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007869 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007870 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7871 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007872 writer.println("Permission Denial: can't dump Phone from pid="
7873 + Binder.getCallingPid()
7874 + ", uid=" + Binder.getCallingUid()
7875 + "without permission "
7876 + android.Manifest.permission.DUMP);
7877 return;
7878 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007879 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007880 }
Jack Yueb89b242016-06-22 13:27:47 -07007881
Brad Ebingerdac2f002018-04-03 15:17:52 -07007882 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007883 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7884 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7885 @NonNull String[] args) {
7886 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7887 this, in.getFileDescriptor(), out.getFileDescriptor(),
7888 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007889 }
7890
Jack Yueb89b242016-06-22 13:27:47 -07007891 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007892 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007893 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007894 * @param reason the reason the data enable change is taking place
7895 * @param enabled True if enabling the data, otherwise disabling.
7896 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007897 */
7898 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007899 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007900 boolean enabled) {
7901 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7902 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7903 try {
7904 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007905 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007906 } catch (SecurityException se) {
7907 enforceModifyPermission();
7908 }
7909 } else {
7910 enforceModifyPermission();
7911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007912
7913 final long identity = Binder.clearCallingIdentity();
7914 try {
7915 Phone phone = getPhone(subId);
7916 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007917 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7918 phone.carrierActionSetMeteredApnsEnabled(enabled);
7919 } else {
7920 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7921 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007922 }
7923 } finally {
7924 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007925 }
7926 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007927
7928 /**
7929 * Get Client request stats
7930 * @return List of Client Request Stats
7931 * @hide
7932 */
7933 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007934 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7935 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007936 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007937 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007938 return null;
7939 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007940 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007941
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007942 final long identity = Binder.clearCallingIdentity();
7943 try {
7944 if (phone != null) {
7945 return phone.getClientRequestStats();
7946 }
7947
7948 return null;
7949 } finally {
7950 Binder.restoreCallingIdentity(identity);
7951 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007952 }
7953
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007954 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007955 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007956 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007957 }
Jack Yueb4124c2017-02-16 15:32:43 -08007958
7959 /**
Grace Chen70990072017-03-24 17:21:30 -07007960 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007961 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007962 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007963 * @param state State of SIM (power down, power up, pass through)
7964 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7965 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7966 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007967 *
7968 **/
7969 @Override
Grace Chen70990072017-03-24 17:21:30 -07007970 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007971 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007972 Phone phone = PhoneFactory.getPhone(slotIndex);
7973
vagdeviaf9a5b92018-08-15 16:01:53 -07007974 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7975
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007976 final long identity = Binder.clearCallingIdentity();
7977 try {
7978 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08007979 phone.setSimPowerState(state, null, workSource);
7980 }
7981 } finally {
7982 Binder.restoreCallingIdentity(identity);
7983 }
7984 }
7985
7986 /**
7987 * Set SIM card power state.
7988 *
7989 * @param slotIndex SIM slot id.
7990 * @param state State of SIM (power down, power up, pass through)
7991 * @param callback callback to trigger after success or failure
7992 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7993 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7994 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7995 *
7996 **/
7997 @Override
7998 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7999 IIntegerConsumer callback) {
8000 enforceModifyPermission();
8001 Phone phone = PhoneFactory.getPhone(slotIndex);
8002
8003 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8004
8005 final long identity = Binder.clearCallingIdentity();
8006 try {
8007 if (phone != null) {
8008 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8009 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008010 }
8011 } finally {
8012 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008013 }
8014 }
Shuo Qiandd210312017-04-12 22:11:33 +00008015
Tyler Gunn65d45c22017-06-05 11:22:26 -07008016 private boolean isUssdApiAllowed(int subId) {
8017 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008018 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008019 if (configManager == null) {
8020 return false;
8021 }
8022 PersistableBundle pb = configManager.getConfigForSubId(subId);
8023 if (pb == null) {
8024 return false;
8025 }
8026 return pb.getBoolean(
8027 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8028 }
8029
Shuo Qiandd210312017-04-12 22:11:33 +00008030 /**
8031 * Check if phone is in emergency callback mode
8032 * @return true if phone is in emergency callback mode
8033 * @param subId sub id
8034 */
goneil9c5f4872017-12-05 14:07:56 -08008035 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008036 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008037 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008038 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008039
8040 final long identity = Binder.clearCallingIdentity();
8041 try {
8042 if (phone != null) {
8043 return phone.isInEcm();
8044 } else {
8045 return false;
8046 }
8047 } finally {
8048 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008049 }
8050 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008051
8052 /**
8053 * Get the current signal strength information for the given subscription.
8054 * Because this information is not updated when the device is in a low power state
8055 * it should not be relied-upon to be current.
8056 * @param subId Subscription index
8057 * @return the most recent cached signal strength info from the modem
8058 */
8059 @Override
8060 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008061 final long identity = Binder.clearCallingIdentity();
8062 try {
8063 Phone p = getPhone(subId);
8064 if (p == null) {
8065 return null;
8066 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008067
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008068 return p.getSignalStrength();
8069 } finally {
8070 Binder.restoreCallingIdentity(identity);
8071 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008072 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008073
Pengquan Meng77b7f132018-08-22 14:49:57 -07008074 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008075 * Get the current modem radio state for the given slot.
8076 * @param slotIndex slot index.
8077 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008078 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008079 * @return the current radio power state from the modem
8080 */
8081 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008082 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008083 Phone phone = PhoneFactory.getPhone(slotIndex);
8084 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008085 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8086 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008087 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8088 }
8089
8090 final long identity = Binder.clearCallingIdentity();
8091 try {
8092 return phone.getRadioPowerState();
8093 } finally {
8094 Binder.restoreCallingIdentity(identity);
8095 }
8096 }
8097 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8098 }
8099
8100 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008101 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8102 *
8103 * <p>Requires one of the following permissions:
8104 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8105 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8106 * privileges.
8107 *
8108 * @param subId subscription id
8109 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8110 * {@code false}.
8111 */
8112 @Override
8113 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008114 try {
8115 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8116 null);
8117 } catch (Exception e) {
8118 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8119 mApp, subId, "isDataRoamingEnabled");
8120 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008121
Pengquan Menga1bb6272018-09-06 09:59:22 -07008122 boolean isEnabled = false;
8123 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008124 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008125 Phone phone = getPhone(subId);
8126 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008127 } finally {
8128 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008129 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008130 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008131 }
8132
8133
8134 /**
8135 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8136 *
8137 * <p> Requires permission:
8138 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8139 * privileges.
8140 *
8141 * @param subId subscription id
8142 * @param isEnabled {@code true} means enable, {@code false} means disable.
8143 */
8144 @Override
8145 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8147 mApp, subId, "setDataRoamingEnabled");
8148
Pengquan Menga1bb6272018-09-06 09:59:22 -07008149 final long identity = Binder.clearCallingIdentity();
8150 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008151 Phone phone = getPhone(subId);
8152 if (phone != null) {
8153 phone.setDataRoamingEnabled(isEnabled);
8154 }
8155 } finally {
8156 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008157 }
8158 }
8159
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008160 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008161 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008162 TelephonyPermissions
8163 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008164 mApp, subId, "isManualNetworkSelectionAllowed");
8165
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008166 boolean isAllowed = true;
8167 final long identity = Binder.clearCallingIdentity();
8168 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008169 Phone phone = getPhone(subId);
8170 if (phone != null) {
8171 isAllowed = phone.isCspPlmnEnabled();
8172 }
8173 } finally {
8174 Binder.restoreCallingIdentity(identity);
8175 }
8176 return isAllowed;
8177 }
8178
8179 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008180 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008181 // Verify that tha callingPackage belongs to the calling UID
8182 mApp.getSystemService(AppOpsManager.class)
8183 .checkPackage(Binder.getCallingUid(), callingPackage);
8184
Jordan Liu1e142fc2019-04-22 15:10:43 -07008185 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008186 try {
8187 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008188 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008189 } catch (SecurityException e) {
8190 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8191 // has carrier privileges on an active UICC
8192 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8193 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008194 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008195 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008196 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008197
8198 final long identity = Binder.clearCallingIdentity();
8199 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008200 UiccController uiccController = UiccController.getInstance();
8201 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008202 if (hasReadPermission) {
8203 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008204 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008205
8206 // Remove private info if the caller doesn't have access
8207 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8208 for (UiccCardInfo cardInfo : cardInfos) {
8209 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8210 // is available
8211 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8212 if (card == null || card.getUiccProfile() == null) {
8213 // assume no access if the card or profile is unavailable
8214 filteredInfos.add(cardInfo.getUnprivileged());
8215 continue;
8216 }
8217 UiccProfile profile = card.getUiccProfile();
8218 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8219 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8220 filteredInfos.add(cardInfo);
8221 } else {
8222 filteredInfos.add(cardInfo.getUnprivileged());
8223 }
8224 }
8225 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008226 } finally {
8227 Binder.restoreCallingIdentity(identity);
8228 }
8229 }
8230
8231 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008232 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008233 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008234
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008235 final long identity = Binder.clearCallingIdentity();
8236 try {
8237 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8238 if (slots == null) {
8239 Rlog.i(LOG_TAG, "slots is null.");
8240 return null;
8241 }
8242
8243 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8244 for (int i = 0; i < slots.length; i++) {
8245 UiccSlot slot = slots[i];
8246 if (slot == null) {
8247 continue;
8248 }
8249
Jordan Liu7be7e652019-05-06 18:55:02 +00008250 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008251 UiccCard card = slot.getUiccCard();
8252 if (card != null) {
8253 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008254 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008255 cardId = slot.getEid();
8256 if (TextUtils.isEmpty(cardId)) {
8257 cardId = slot.getIccId();
8258 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008259 }
8260
Jordan Liu857451f2019-05-09 16:35:35 -07008261 if (cardId != null) {
8262 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8263 // if cardId is an EID, it's all digits so this is fine
8264 cardId = IccUtils.stripTrailingFs(cardId);
8265 }
8266
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008267 int cardState = 0;
8268 switch (slot.getCardState()) {
8269 case CARDSTATE_ABSENT:
8270 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8271 break;
8272 case CARDSTATE_PRESENT:
8273 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8274 break;
8275 case CARDSTATE_ERROR:
8276 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8277 break;
8278 case CARDSTATE_RESTRICTED:
8279 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8280 break;
8281 default:
8282 break;
8283
8284 }
8285
8286 infos[i] = new UiccSlotInfo(
8287 slot.isActive(),
8288 slot.isEuicc(),
8289 cardId,
8290 cardState,
8291 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008292 slot.isExtendedApduSupported(),
8293 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008294 }
8295 return infos;
8296 } finally {
8297 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008298 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008299 }
8300
8301 @Override
8302 public boolean switchSlots(int[] physicalSlots) {
8303 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008304
8305 final long identity = Binder.clearCallingIdentity();
8306 try {
8307 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8308 } finally {
8309 Binder.restoreCallingIdentity(identity);
8310 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008311 }
Jack Yu4c988042018-02-27 15:30:01 -08008312
8313 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008314 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008315 final long identity = Binder.clearCallingIdentity();
8316 try {
8317 return UiccController.getInstance().getCardIdForDefaultEuicc();
8318 } finally {
8319 Binder.restoreCallingIdentity(identity);
8320 }
8321 }
8322
Pengquan Meng85728fb2018-03-12 16:31:21 -07008323 /**
goneil47ffb6e2018-04-06 15:40:58 -07008324 * A test API to reload the UICC profile.
8325 *
8326 * <p>Requires that the calling app has permission
8327 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8328 * @hide
8329 */
8330 @Override
8331 public void refreshUiccProfile(int subId) {
8332 enforceModifyPermission();
8333
8334 final long identity = Binder.clearCallingIdentity();
8335 try {
8336 Phone phone = getPhone(subId);
8337 if (phone == null) {
8338 return;
8339 }
8340 UiccCard uiccCard = phone.getUiccCard();
8341 if (uiccCard == null) {
8342 return;
8343 }
8344 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8345 if (uiccProfile == null) {
8346 return;
8347 }
8348 uiccProfile.refresh();
8349 } finally {
8350 Binder.restoreCallingIdentity(identity);
8351 }
8352 }
8353
8354 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008355 * Returns false if the mobile data is disabled by default, otherwise return true.
8356 */
8357 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008358 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008359 }
8360
8361 /**
8362 * Returns true if the data roaming is enabled by default, i.e the system property
8363 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8364 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8365 */
8366 private boolean getDefaultDataRoamingEnabled(int subId) {
8367 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008368 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008369 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008370 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8371 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8372 return isDataRoamingEnabled;
8373 }
8374
8375 /**
8376 * Returns the default network type for the given {@code subId}, if the default network type is
8377 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8378 */
8379 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008380 List<Integer> list = TelephonyProperties.default_network();
8381 int phoneId = mSubscriptionController.getPhoneId(subId);
8382 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8383 return list.get(phoneId);
8384 }
8385 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008386 }
fionaxua13278b2018-03-21 00:08:13 -07008387
8388 @Override
8389 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008390 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008391 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008392
8393 final long identity = Binder.clearCallingIdentity();
8394 try {
8395 final Phone phone = getPhone(subId);
8396 if (phone == null) {
8397 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8398 return;
8399 }
chen xueaba88a2019-03-15 13:15:10 -07008400 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8401 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008402 if (carrierPrivilegeRules == null) {
8403 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8404 } else {
8405 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8406 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008407 } finally {
8408 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008409 }
fionaxua13278b2018-03-21 00:08:13 -07008410 }
8411
8412 @Override
8413 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008414 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008415
8416 final long identity = Binder.clearCallingIdentity();
8417 try {
8418 final Phone phone = getPhone(subId);
8419 if (phone == null) {
8420 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8421 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8422 }
8423 return phone.getCarrierIdListVersion();
8424 } finally {
8425 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008426 }
fionaxua13278b2018-03-21 00:08:13 -07008427 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008428
8429 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008430 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8431 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008432 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008433 mApp, subId, callingPackage, callingFeatureId,
8434 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008435 return -1;
8436 }
8437
8438 final long identity = Binder.clearCallingIdentity();
8439 try {
8440 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8441 } finally {
8442 Binder.restoreCallingIdentity(identity);
8443 }
8444 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008445
8446 @Override
8447 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008448 TelephonyPermissions
8449 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008450 mApp, subId, "getCdmaRoamingMode");
8451
8452 final long identity = Binder.clearCallingIdentity();
8453 try {
8454 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8455 } finally {
8456 Binder.restoreCallingIdentity(identity);
8457 }
8458 }
8459
8460 @Override
8461 public boolean setCdmaRoamingMode(int subId, int mode) {
8462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8463 mApp, subId, "setCdmaRoamingMode");
8464
8465 final long identity = Binder.clearCallingIdentity();
8466 try {
8467 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8468 } finally {
8469 Binder.restoreCallingIdentity(identity);
8470 }
8471 }
8472
8473 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008474 public int getCdmaSubscriptionMode(int subId) {
8475 TelephonyPermissions
8476 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8477 mApp, subId, "getCdmaSubscriptionMode");
8478
8479 final long identity = Binder.clearCallingIdentity();
8480 try {
8481 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8482 } finally {
8483 Binder.restoreCallingIdentity(identity);
8484 }
8485 }
8486
8487 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008488 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8490 mApp, subId, "setCdmaSubscriptionMode");
8491
8492 final long identity = Binder.clearCallingIdentity();
8493 try {
8494 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8495 } finally {
8496 Binder.restoreCallingIdentity(identity);
8497 }
8498 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008499
sqianc5eccab2018-10-19 18:46:41 -07008500 @Override
sqian8c685422019-02-22 15:55:18 -08008501 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008502 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008503 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008504 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8505 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008506 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8507 }
8508 final long identity = Binder.clearCallingIdentity();
8509 try {
sqian854d44b2018-12-12 16:48:18 -08008510 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8511 for (Phone phone: PhoneFactory.getPhones()) {
8512 if (phone.getEmergencyNumberTracker() != null
8513 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8514 emergencyNumberListInternal.put(
8515 phone.getSubId(),
8516 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8517 }
sqian11b7a0e2018-12-05 18:48:28 -08008518 }
sqian854d44b2018-12-12 16:48:18 -08008519 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008520 } finally {
8521 Binder.restoreCallingIdentity(identity);
8522 }
sqianc5eccab2018-10-19 18:46:41 -07008523 }
8524
8525 @Override
sqian8c685422019-02-22 15:55:18 -08008526 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008527 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008528 if (!exactMatch) {
8529 TelephonyPermissions
8530 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008531 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008532 }
8533 final long identity = Binder.clearCallingIdentity();
8534 try {
sqian854d44b2018-12-12 16:48:18 -08008535 for (Phone phone: PhoneFactory.getPhones()) {
8536 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008537 && phone.getEmergencyNumberTracker()
8538 .isEmergencyNumber(number, exactMatch)) {
8539 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008540 }
sqian11b7a0e2018-12-05 18:48:28 -08008541 }
8542 return false;
8543 } finally {
8544 Binder.restoreCallingIdentity(identity);
8545 }
8546 }
8547
sqianf4ca7ed2019-01-15 18:32:07 -08008548 /**
8549 * Update emergency number list for test mode.
8550 */
8551 @Override
8552 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8553 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8554 "updateEmergencyNumberListTestMode");
8555
8556 final long identity = Binder.clearCallingIdentity();
8557 try {
8558 for (Phone phone: PhoneFactory.getPhones()) {
8559 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8560 if (tracker != null) {
8561 tracker.executeEmergencyNumberTestModeCommand(action, num);
8562 }
8563 }
8564 } finally {
8565 Binder.restoreCallingIdentity(identity);
8566 }
8567 }
8568
8569 /**
8570 * Get the full emergency number list for test mode.
8571 */
8572 @Override
8573 public List<String> getEmergencyNumberListTestMode() {
8574 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8575 "getEmergencyNumberListTestMode");
8576
8577 final long identity = Binder.clearCallingIdentity();
8578 try {
8579 Set<String> emergencyNumbers = new HashSet<>();
8580 for (Phone phone: PhoneFactory.getPhones()) {
8581 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8582 if (tracker != null) {
8583 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8584 emergencyNumbers.add(num.getNumber());
8585 }
8586 }
8587 }
8588 return new ArrayList<>(emergencyNumbers);
8589 } finally {
8590 Binder.restoreCallingIdentity(identity);
8591 }
8592 }
8593
chen xud6b45bd2018-10-30 22:27:10 -07008594 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008595 public int getEmergencyNumberDbVersion(int subId) {
8596 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8597
8598 final long identity = Binder.clearCallingIdentity();
8599 try {
8600 final Phone phone = getPhone(subId);
8601 if (phone == null) {
8602 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8603 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8604 }
8605 return phone.getEmergencyNumberDbVersion();
8606 } finally {
8607 Binder.restoreCallingIdentity(identity);
8608 }
8609 }
8610
8611 @Override
8612 public void notifyOtaEmergencyNumberDbInstalled() {
8613 enforceModifyPermission();
8614
8615 final long identity = Binder.clearCallingIdentity();
8616 try {
8617 for (Phone phone: PhoneFactory.getPhones()) {
8618 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8619 if (tracker != null) {
8620 tracker.updateOtaEmergencyNumberDatabase();
8621 }
8622 }
8623 } finally {
8624 Binder.restoreCallingIdentity(identity);
8625 }
8626 }
8627
8628 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008629 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008630 enforceActiveEmergencySessionPermission();
8631
8632 final long identity = Binder.clearCallingIdentity();
8633 try {
8634 for (Phone phone: PhoneFactory.getPhones()) {
8635 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8636 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008637 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8638 }
8639 }
8640 } finally {
8641 Binder.restoreCallingIdentity(identity);
8642 }
8643 }
8644
8645 @Override
8646 public void resetOtaEmergencyNumberDbFilePath() {
8647 enforceActiveEmergencySessionPermission();
8648
8649 final long identity = Binder.clearCallingIdentity();
8650 try {
8651 for (Phone phone: PhoneFactory.getPhones()) {
8652 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8653 if (tracker != null) {
8654 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008655 }
8656 }
8657 } finally {
8658 Binder.restoreCallingIdentity(identity);
8659 }
8660 }
8661
8662 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008663 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8664 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8665 Phone phone = getPhone(subId);
8666 if (phone == null) {
8667 return null;
8668 }
8669 final long identity = Binder.clearCallingIdentity();
8670 try {
8671 UiccProfile profile = UiccController.getInstance()
8672 .getUiccProfileForPhone(phone.getPhoneId());
8673 if (profile != null) {
8674 return profile.getCertsFromCarrierPrivilegeAccessRules();
8675 }
8676 } finally {
8677 Binder.restoreCallingIdentity(identity);
8678 }
8679 return null;
8680 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008681
8682 /**
8683 * Enable or disable a modem stack.
8684 */
8685 @Override
8686 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8687 enforceModifyPermission();
8688
8689 final long identity = Binder.clearCallingIdentity();
8690 try {
8691 Phone phone = PhoneFactory.getPhone(slotIndex);
8692 if (phone == null) {
8693 return false;
8694 } else {
8695 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8696 }
8697 } finally {
8698 Binder.restoreCallingIdentity(identity);
8699 }
8700 }
Michelecea4cf22018-12-21 15:00:11 -08008701
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008702 /**
8703 * Whether a modem stack is enabled or not.
8704 */
8705 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008706 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8707 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008708 Phone phone = PhoneFactory.getPhone(slotIndex);
8709 if (phone == null) return false;
8710
8711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008712 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8713 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008714 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8715 }
8716
8717 final long identity = Binder.clearCallingIdentity();
8718 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008719 try {
8720 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8721 } catch (NoSuchElementException ex) {
8722 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8723 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008724 } finally {
8725 Binder.restoreCallingIdentity(identity);
8726 }
8727 }
8728
Michelecea4cf22018-12-21 15:00:11 -08008729 @Override
Michele0ea7d782019-03-19 14:58:42 -07008730 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008731 enforceModifyPermission();
8732
8733 final long identity = Binder.clearCallingIdentity();
8734 try {
8735 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008736 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008737 .commit();
8738 } finally {
8739 Binder.restoreCallingIdentity(identity);
8740 }
8741 }
8742
8743 @Override
Michele0ea7d782019-03-19 14:58:42 -07008744 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008745 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008746 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008747 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8748 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008749 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008750 }
Michelecea4cf22018-12-21 15:00:11 -08008751
8752 final long identity = Binder.clearCallingIdentity();
8753 try {
Michele0ea7d782019-03-19 14:58:42 -07008754 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008755 } finally {
8756 Binder.restoreCallingIdentity(identity);
8757 }
8758 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008759
Michele0ea7d782019-03-19 14:58:42 -07008760 @TelephonyManager.IsMultiSimSupportedResult
8761 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008762 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8763 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8764 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008765 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8766 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008767 }
8768 // Check if the hardware supports multisim functionality. If usage of multisim is not
8769 // supported by the modem, indicate that it is restricted.
8770 PhoneCapability staticCapability =
8771 mPhoneConfigurationManager.getStaticPhoneCapability();
8772 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008773 loge("isMultiSimSupportedInternal: no static configuration available");
8774 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008775 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008776 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008777 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8778 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008779 }
8780 // Check if support of multiple SIMs is restricted by carrier
8781 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008782 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008783 }
8784
Michele0ea7d782019-03-19 14:58:42 -07008785 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008786 }
8787
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008788 /**
8789 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008790 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8791 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8792 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008793 * @param numOfSims number of active sims we want to switch to
8794 */
8795 @Override
8796 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008797 if (numOfSims == 1) {
8798 enforceModifyPermission();
8799 } else {
8800 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8801 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8802 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008803 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008804
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008805 try {
Michele30b57b22019-03-01 12:01:14 -08008806 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008807 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008808 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8809 return;
8810 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008811 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8812 } finally {
8813 Binder.restoreCallingIdentity(identity);
8814 }
8815 }
8816
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008817 @Override
8818 public boolean isApplicationOnUicc(int subId, int appType) {
8819 enforceReadPrivilegedPermission("isApplicationOnUicc");
8820 Phone phone = getPhone(subId);
8821 if (phone == null) {
8822 return false;
8823 }
8824 final long identity = Binder.clearCallingIdentity();
8825 try {
8826 UiccCard uiccCard = phone.getUiccCard();
8827 if (uiccCard == null) {
8828 return false;
8829 }
8830 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8831 if (uiccProfile == null) {
8832 return false;
8833 }
8834 if (TelephonyManager.APPTYPE_SIM <= appType
8835 && appType <= TelephonyManager.APPTYPE_ISIM) {
8836 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8837 }
8838 return false;
8839 } finally {
8840 Binder.restoreCallingIdentity(identity);
8841 }
8842 }
8843
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008844 /**
chen xub4baa772019-04-03 10:23:41 -07008845 * Get whether making changes to modem configurations will trigger reboot.
8846 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008847 */
8848 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008849 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8850 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008851 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008852 mApp, subId, callingPackage, callingFeatureId,
8853 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008854 return false;
8855 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008856 final long identity = Binder.clearCallingIdentity();
8857 try {
8858 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8859 } finally {
8860 Binder.restoreCallingIdentity(identity);
8861 }
8862 }
8863
Nathan Harold29f5f052019-02-15 13:41:57 -08008864 private void updateModemStateMetrics() {
8865 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8866 // TODO: check the state for each modem if the api is ready.
8867 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8868 }
8869
Pengquan Meng3889a572019-01-23 11:16:29 -08008870 @Override
8871 public int[] getSlotsMapping() {
8872 enforceReadPrivilegedPermission("getSlotsMapping");
8873
8874 final long identity = Binder.clearCallingIdentity();
8875 try {
8876 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8877 // All logical slots should have a mapping to a physical slot.
8878 int[] logicalSlotsMapping = new int[phoneCount];
8879 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8880 for (int i = 0; i < slotInfos.length; i++) {
8881 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8882 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8883 }
8884 }
8885 return logicalSlotsMapping;
8886 } finally {
8887 Binder.restoreCallingIdentity(identity);
8888 }
8889 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008890
8891 /**
8892 * Get the IRadio HAL Version
8893 */
8894 @Override
8895 public int getRadioHalVersion() {
8896 Phone phone = getDefaultPhone();
8897 if (phone == null) return -1;
8898 HalVersion hv = phone.getHalVersion();
8899 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8900 return hv.major * 100 + hv.minor;
8901 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008902
8903 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008904 * Get the current calling package name.
8905 * @return the current calling package name
8906 */
8907 @Override
8908 public String getCurrentPackageName() {
8909 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8910 }
8911
8912 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008913 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8914 * corresponding network requests on a subId.
8915 *
8916 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008917 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008918 * 2) APN is un-metered for this subscription, or
8919 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008920 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008921 *
8922 * @return whether data is allowed for a apn type.
8923 *
8924 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008925 */
8926 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008927 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008928 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8929 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008930
8931 // Now that all security checks passes, perform the operation as ourselves.
8932 final long identity = Binder.clearCallingIdentity();
8933 try {
8934 Phone phone = getPhone(subId);
8935 if (phone == null) return false;
8936
Jack Yu41407ee2019-05-13 16:54:09 -07008937 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008938 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8939 } finally {
8940 Binder.restoreCallingIdentity(identity);
8941 }
8942 }
8943
8944 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008945 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008946 enforceReadPrivilegedPermission("isApnMetered");
8947
8948 // Now that all security checks passes, perform the operation as ourselves.
8949 final long identity = Binder.clearCallingIdentity();
8950 try {
8951 Phone phone = getPhone(subId);
8952 if (phone == null) return true; // By default return true.
8953
Jack Yu41407ee2019-05-13 16:54:09 -07008954 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008955 } finally {
8956 Binder.restoreCallingIdentity(identity);
8957 }
8958 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008959
8960 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008961 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8962 int subscriptionId, IBooleanConsumer resultCallback) {
8963 enforceModifyPermission();
8964 long token = Binder.clearCallingIdentity();
8965 try {
8966 Phone phone = getPhone(subscriptionId);
8967 if (phone == null) {
8968 try {
8969 if (resultCallback != null) {
8970 resultCallback.accept(false);
8971 }
8972 } catch (RemoteException e) {
8973 // ignore
8974 }
8975 return;
8976 }
8977 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8978 Pair.create(specifiers, (x) -> {
8979 try {
8980 if (resultCallback != null) {
8981 resultCallback.accept(x);
8982 }
8983 } catch (RemoteException e) {
8984 // ignore
8985 }
8986 });
8987 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8988 } finally {
8989 Binder.restoreCallingIdentity(token);
8990 }
8991 }
8992
8993 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008994 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8995 TelephonyPermissions
8996 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8997 mApp, subId, "getSystemSelectionChannels");
8998 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8999 final long identity = Binder.clearCallingIdentity();
9000 try {
9001 List<RadioAccessSpecifier> specifiers =
9002 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9003 null, subId, workSource);
9004 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9005 return specifiers;
9006 } finally {
9007 Binder.restoreCallingIdentity(identity);
9008 }
9009 }
9010
9011 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009012 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009013 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009014 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9015 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9016 if (iccRecords == null) {
9017 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9018 return false;
9019 }
9020 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9021 }
9022
9023 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009024 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9025 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009026 if (callingPackage == null) {
9027 callingPackage = getCurrentPackageName();
9028 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009029 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9030 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009031 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9032 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009033 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9034 }
9035 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9036 Intent intent = new Intent();
9037 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9038 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9039 // Bring up choose default SMS subscription dialog right now
9040 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9041 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9042 mApp.startActivity(intent);
9043 }
chen xud5ca2d52019-05-28 15:20:57 -07009044
9045 @Override
9046 public String getMmsUAProfUrl(int subId) {
9047 //TODO investigate if this API should require proper permission check in R b/133791609
9048 final long identity = Binder.clearCallingIdentity();
9049 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009050 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9051 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9052 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9053 return carrierUAProfUrl;
9054 }
chen xud5ca2d52019-05-28 15:20:57 -07009055 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9056 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9057 } finally {
9058 Binder.restoreCallingIdentity(identity);
9059 }
9060 }
9061
9062 @Override
9063 public String getMmsUserAgent(int subId) {
9064 //TODO investigate if this API should require proper permission check in R b/133791609
9065 final long identity = Binder.clearCallingIdentity();
9066 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009067 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9068 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9069 if (!TextUtils.isEmpty(carrierUserAgent)) {
9070 return carrierUserAgent;
9071 }
chen xud5ca2d52019-05-28 15:20:57 -07009072 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9073 .getString(com.android.internal.R.string.config_mms_user_agent);
9074 } finally {
9075 Binder.restoreCallingIdentity(identity);
9076 }
9077 }
Jack Yub07d4972019-05-28 16:12:25 -07009078
9079 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009080 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9081 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9082
9083 final long identity = Binder.clearCallingIdentity();
9084 try {
9085 Phone phone = getPhone(subscriptionId);
9086 if (phone == null) return false;
9087
9088 switch (policy) {
9089 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9090 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9091 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9092 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9093 default:
9094 throw new IllegalArgumentException(policy + " is not a valid policy");
9095 }
9096 } finally {
9097 Binder.restoreCallingIdentity(identity);
9098 }
9099 }
9100
9101 @Override
9102 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9103 boolean enabled) {
9104 enforceModifyPermission();
9105
9106 final long identity = Binder.clearCallingIdentity();
9107 try {
9108 Phone phone = getPhone(subscriptionId);
9109 if (phone == null) return;
9110
9111 switch (policy) {
9112 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9113 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9114 break;
9115 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9116 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9117 break;
9118 default:
9119 throw new IllegalArgumentException(policy + " is not a valid policy");
9120 }
9121 } finally {
9122 Binder.restoreCallingIdentity(identity);
9123 }
9124 }
9125
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009126 /**
Hall Liub48cf452020-09-25 11:13:49 -07009127 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009128 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9129 * otherwise.
9130 */
9131 @Override
9132 public void setCepEnabled(boolean isCepEnabled) {
9133 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9134
9135 final long identity = Binder.clearCallingIdentity();
9136 try {
9137 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9138 for (Phone phone : PhoneFactory.getPhones()) {
9139 Phone defaultPhone = phone.getImsPhone();
9140 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9141 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9142 ImsPhoneCallTracker imsPhoneCallTracker =
9143 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9144 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9145 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9146 + imsPhone.getMsisdn());
9147 }
9148 }
9149 } finally {
9150 Binder.restoreCallingIdentity(identity);
9151 }
9152 }
allenwtsu46dcc572020-01-08 18:24:03 +08009153
9154 /**
9155 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9156 *
9157 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9158 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9159 * before being read.
9160 */
9161 @Override
9162 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9163 isCompressed) {
9164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9165 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009166 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9167 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9168 }
9169 if (!isImsAvailableOnDevice()) {
9170 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9171 "IMS not available on device.");
9172 }
9173
9174 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009175 try {
Hui Wang068ab862020-10-31 05:12:53 +00009176 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9177 } finally {
9178 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009179 }
9180 }
zoey chenf95ca592019-12-30 16:11:23 +08009181
9182 @Override
9183 public boolean isIccLockEnabled(int subId) {
9184 enforceReadPrivilegedPermission("isIccLockEnabled");
9185
9186 // Now that all security checks passes, perform the operation as ourselves.
9187 final long identity = Binder.clearCallingIdentity();
9188 try {
9189 Phone phone = getPhone(subId);
9190 if (phone != null && phone.getIccCard() != null) {
9191 return phone.getIccCard().getIccLockEnabled();
9192 } else {
9193 return false;
9194 }
9195 } finally {
9196 Binder.restoreCallingIdentity(identity);
9197 }
9198 }
9199
9200 /**
zoey chene02881a2019-12-30 16:11:23 +08009201 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009202 *
zoey chene02881a2019-12-30 16:11:23 +08009203 * @return an integer representing the status of IccLock enabled or disabled in the following
9204 * three cases:
9205 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9206 * successfully.
9207 * - Positive number and zero for remaining password attempts.
9208 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009209 *
9210 */
9211 @Override
9212 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9213 enforceModifyPermission();
9214
9215 Phone phone = getPhone(subId);
9216 if (phone == null) {
9217 return 0;
9218 }
9219 // Now that all security checks passes, perform the operation as ourselves.
9220 final long identity = Binder.clearCallingIdentity();
9221 try {
9222 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9223 new Pair<Boolean, String>(enabled, password), phone, null);
9224 return attemptsRemaining;
9225
9226 } catch (Exception e) {
9227 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9228 } finally {
9229 Binder.restoreCallingIdentity(identity);
9230 }
9231 return 0;
9232 }
9233
9234 /**
9235 * Change the ICC password used in ICC pin lock.
9236 *
zoey chene02881a2019-12-30 16:11:23 +08009237 * @return an integer representing the status of IccLock changed in the following three cases:
9238 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9239 * - Positive number and zero for remaining password attempts.
9240 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009241 *
9242 */
9243 @Override
9244 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9245 enforceModifyPermission();
9246
9247 Phone phone = getPhone(subId);
9248 if (phone == null) {
9249 return 0;
9250 }
9251 // Now that all security checks passes, perform the operation as ourselves.
9252 final long identity = Binder.clearCallingIdentity();
9253 try {
9254 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9255 new Pair<String, String>(oldPassword, newPassword), phone, null);
9256 return attemptsRemaining;
9257
9258 } catch (Exception e) {
9259 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9260 } finally {
9261 Binder.restoreCallingIdentity(identity);
9262 }
9263 return 0;
9264 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009265
Peter Wangdafb9ac2020-01-15 14:13:38 -08009266 /**
9267 * Request for receiving user activity notification
9268 */
9269 @Override
9270 public void requestUserActivityNotification() {
9271 if (!mNotifyUserActivity.get()
9272 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9273 mNotifyUserActivity.set(true);
9274 }
9275 }
9276
9277 /**
9278 * Called when userActivity is signalled in the power manager.
9279 * This is safe to call from any thread, with any window manager locks held or not.
9280 */
9281 @Override
9282 public void userActivity() {
9283 // ***************************************
9284 // * Inherited from PhoneWindowManager *
9285 // ***************************************
9286 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9287 // WITH ITS LOCKS HELD.
9288 //
9289 // This code must be VERY careful about the locks
9290 // it acquires.
9291 // In fact, the current code acquires way too many,
9292 // and probably has lurking deadlocks.
9293
9294 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9295 throw new SecurityException("Only the OS may call notifyUserActivity()");
9296 }
9297
9298 if (mNotifyUserActivity.getAndSet(false)) {
9299 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9300 USER_ACTIVITY_NOTIFICATION_DELAY);
9301 }
9302 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009303
Malcolm Chen884180b2020-04-13 11:59:40 -07009304 @Override
9305 public boolean canConnectTo5GInDsdsMode() {
9306 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9307 }
Jack Yud10cdd42020-09-28 20:28:01 -07009308
9309 @Override
9310 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9311 String callingFeatureId) {
9312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9313 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9314 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9315 }
9316
9317 Phone phone = getPhone(subId);
9318 if (phone == null) {
9319 throw new RuntimeException("phone is not available");
9320 }
9321 // Now that all security checks passes, perform the operation as ourselves.
9322 final long identity = Binder.clearCallingIdentity();
9323 try {
9324 return phone.getEquivalentHomePlmns();
9325 } finally {
9326 Binder.restoreCallingIdentity(identity);
9327 }
9328 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009329
Hui Wang0866fcc2020-10-12 12:14:23 -07009330 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009331 public boolean isRadioInterfaceCapabilitySupported(
9332 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9333 RadioInterfaceCapabilities radioInterfaceCapabilities =
9334 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9335 if (radioInterfaceCapabilities == null) {
9336 throw new RuntimeException("radio interface capabilities are not available");
9337 } else {
9338 return radioInterfaceCapabilities.isSupported(capability);
9339 }
9340 }
9341
9342 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009343 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9344 UaSecurityProtocolIdentifier securityProtocol,
9345 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9346 throws RemoteException {
9347 enforceModifyPermission();
9348 if (DBG) {
9349 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9350 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9351 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9352 }
9353
9354 if (!SubscriptionManager.isValidSubscriptionId(subId)
9355 || appType < TelephonyManager.APPTYPE_UNKNOWN
9356 || appType > TelephonyManager.APPTYPE_ISIM
9357 || nafUrl == null || securityProtocol == null || callback == null) {
9358 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9359 if (callback != null) {
9360 try {
9361 callback.onAuthenticationFailure(
9362 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9363 } catch (RemoteException exception) {
9364 log("Fail to notify onAuthenticationFailure due to " + exception);
9365 }
9366 return;
9367 }
9368 }
9369
9370 final long token = Binder.clearCallingIdentity();
9371 try {
9372 getGbaManager(subId).bootstrapAuthenticationRequest(
9373 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9374 forceBootStrapping, callback));
9375 } finally {
9376 Binder.restoreCallingIdentity(token);
9377 }
9378 }
9379
Jack Nudelman24d51a52020-11-24 12:08:04 -08009380 /**
9381 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9382 * requested radio power state will actually be set. See {@link
9383 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9384 *
9385 * @param subId the subscription ID of the phone requesting to set the radio power state.
9386 * @param enable {@code true} if trying to turn radio on.
9387 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9388 * false}.
9389 */
9390 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9391 Phone phone = getPhone(subId);
9392 if (phone != null) {
9393 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9394 return true;
9395 }
9396 return false;
9397 }
9398
9399 private int handleDataThrottlingRequest(int subId,
9400 DataThrottlingRequest dataThrottlingRequest) {
9401 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9402 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9403 if (!setRadioPowerForThermal(subId, true)) {
9404 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9405 }
9406
9407 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9408
9409 int thermalMitigationResult =
9410 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9411 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9412 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9413 }
9414 return thermalMitigationResult;
9415 }
9416
9417 /**
9418 * Thermal mitigation request to control functionalities at modem.
9419 *
9420 * @param subId the id of the subscription.
9421 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9422 *
9423 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9424 */
9425 @Override
9426 @ThermalMitigationResult
9427 public int sendThermalMitigationRequest(
9428 int subId,
9429 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9430 enforceModifyPermission();
9431
9432 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9433 final long identity = Binder.clearCallingIdentity();
9434
9435 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9436 try {
9437 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9438 switch (thermalMitigationAction) {
9439 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9440 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009441 handleDataThrottlingRequest(subId,
9442 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009443 break;
9444 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9445 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9446 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9447 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9448 }
9449
9450 // Ensure that radio is on. If not able to power on due to phone being
9451 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9452 if (!setRadioPowerForThermal(subId, true)) {
9453 thermalMitigationResult =
9454 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9455 break;
9456 }
9457
9458 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9459 false);
9460 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9461 break;
9462 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9463 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9464 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9465 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9466 }
9467
9468 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9469 if (registry != null) {
9470 TelephonyConnectionService service =
9471 registry.getTelephonyConnectionService();
9472 Phone phone = getPhone(subId);
9473 if (phone == null) {
9474 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009475 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009476 break;
9477 }
9478
9479 if (PhoneConstantConversions.convertCallState(phone.getState())
Daniel Bright74f1ca82020-11-13 11:49:37 -08009480 != TelephonyManager.CALL_STATE_IDLE
9481 || phone.isInEmergencySmsMode() || phone.isInEcm()
9482 || (service != null && service.isEmergencyCallPending())) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009483 String errorMessage = "Phone state is not valid. call state = "
9484 + PhoneConstantConversions.convertCallState(phone.getState())
9485 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9486 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9487 errorMessage += service == null
9488 ? " TelephonyConnectionService is null"
9489 : " isEmergencyCallPending = "
9490 + service.isEmergencyCallPending();
9491 Log.e(LOG_TAG, errorMessage);
9492 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009493 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009494 break;
9495 }
9496 } else {
9497 thermalMitigationResult =
9498 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9499 break;
9500 }
9501
9502 // Turn radio off. If not able to power off due to phone being unavailable,
9503 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9504 if (!setRadioPowerForThermal(subId, false)) {
9505 thermalMitigationResult =
9506 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9507 break;
9508 }
9509 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009510 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009511 break;
9512 default:
9513 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9514 + "not exist. Requested action: " + thermalMitigationAction);
9515 }
9516 } catch (IllegalArgumentException e) {
9517 throw e;
9518 } catch (Exception e) {
9519 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9520 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9521 } finally {
9522 Binder.restoreCallingIdentity(identity);
9523 }
9524
9525 if (DBG) {
9526 log("thermalMitigationRequest returning with thermalMitigationResult: "
9527 + thermalMitigationResult);
9528 }
9529
9530 return thermalMitigationResult;
9531 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009532
9533 /**
9534 * Set the GbaService Package Name that Telephony will bind to.
9535 *
9536 * @param subId The sim that the GbaService is associated with.
9537 * @param packageName The name of the package to be replaced with.
9538 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9539 */
9540 @Override
9541 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9542 enforceModifyPermission();
9543
9544 final long identity = Binder.clearCallingIdentity();
9545 try {
9546 return getGbaManager(subId).overrideServicePackage(packageName);
9547 } finally {
9548 Binder.restoreCallingIdentity(identity);
9549 }
9550 }
9551
9552 /**
9553 * Return the package name of the currently bound GbaService.
9554 *
9555 * @param subId The sim that the GbaService is associated with.
9556 * @return the package name of the GbaService configuration, null if GBA is not supported.
9557 */
9558 @Override
9559 public String getBoundGbaService(int subId) {
9560 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9561
9562 final long identity = Binder.clearCallingIdentity();
9563 try {
9564 return getGbaManager(subId).getServicePackage();
9565 } finally {
9566 Binder.restoreCallingIdentity(identity);
9567 }
9568 }
9569
9570 /**
9571 * Set the release time for telephony to unbind GbaService.
9572 *
9573 * @param subId The sim that the GbaService is associated with.
9574 * @param interval The release time to unbind GbaService by millisecond.
9575 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9576 */
9577 @Override
9578 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9579 enforceModifyPermission();
9580
9581 final long identity = Binder.clearCallingIdentity();
9582 try {
9583 return getGbaManager(subId).overrideReleaseTime(interval);
9584 } finally {
9585 Binder.restoreCallingIdentity(identity);
9586 }
9587 }
9588
9589 /**
9590 * Return the release time for telephony to unbind GbaService.
9591 *
9592 * @param subId The sim that the GbaService is associated with.
9593 * @return The release time to unbind GbaService by millisecond.
9594 */
9595 @Override
9596 public int getGbaReleaseTime(int subId) {
9597 enforceReadPrivilegedPermission("getGbaReleaseTime");
9598
9599 final long identity = Binder.clearCallingIdentity();
9600 try {
9601 return getGbaManager(subId).getReleaseTime();
9602 } finally {
9603 Binder.restoreCallingIdentity(identity);
9604 }
9605 }
9606
9607 private GbaManager getGbaManager(int subId) {
9608 GbaManager instance = GbaManager.getInstance(subId);
9609 if (instance == null) {
9610 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9611 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9612 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9613 }
9614 return instance;
9615 }
Hui Wang068ab862020-10-31 05:12:53 +00009616
9617 /**
9618 * indicate whether the device and the carrier can support
9619 * RCS VoLTE single registration.
9620 */
9621 @Override
9622 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9623 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9624
9625 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9626 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9627 }
9628
9629 final long identity = Binder.clearCallingIdentity();
9630 try {
9631 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9632 if (rpm != null) {
9633 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9634 }
9635 return false;
9636 } finally {
9637 Binder.restoreCallingIdentity(identity);
9638 }
9639 }
9640
9641 /**
9642 * Register RCS provisioning callback.
9643 */
9644 @Override
9645 public void registerRcsProvisioningChangedCallback(int subId,
9646 IRcsConfigCallback callback) {
9647 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9648
9649 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9650 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9651 }
9652 if (!isImsAvailableOnDevice()) {
9653 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9654 "IMS not available on device.");
9655 }
9656
9657 final long identity = Binder.clearCallingIdentity();
9658 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009659 if (!RcsProvisioningMonitor.getInstance()
9660 .registerRcsProvisioningChangedCallback(subId, callback)) {
9661 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9662 "Service not available for the subscription.");
9663 }
Hui Wang068ab862020-10-31 05:12:53 +00009664 } finally {
9665 Binder.restoreCallingIdentity(identity);
9666 }
9667 }
9668
9669 /**
9670 * Unregister RCS provisioning callback.
9671 */
9672 @Override
9673 public void unregisterRcsProvisioningChangedCallback(int subId,
9674 IRcsConfigCallback callback) {
9675 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9676
9677 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9678 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9679 }
9680 if (!isImsAvailableOnDevice()) {
9681 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9682 "IMS not available on device.");
9683 }
9684
9685 final long identity = Binder.clearCallingIdentity();
9686 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009687 RcsProvisioningMonitor.getInstance()
9688 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009689 } finally {
9690 Binder.restoreCallingIdentity(identity);
9691 }
9692 }
9693
9694 /**
9695 * trigger RCS reconfiguration.
9696 */
9697 public void triggerRcsReconfiguration(int subId) {
9698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9699 mApp, subId, "triggerRcsReconfiguration");
9700
9701 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9702 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9703 }
9704 if (!isImsAvailableOnDevice()) {
9705 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9706 "IMS not available on device.");
9707 }
9708
9709 final long identity = Binder.clearCallingIdentity();
9710 try {
9711 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9712 } finally {
9713 Binder.restoreCallingIdentity(identity);
9714 }
9715 }
9716
9717 /**
9718 * Provide the client configuration parameters of the RCS application.
9719 */
9720 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9721 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9722 mApp, subId, "setRcsClientConfiguration");
9723
9724 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9725 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9726 }
9727 if (!isImsAvailableOnDevice()) {
9728 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9729 "IMS not available on device.");
9730 }
9731
9732 final long identity = Binder.clearCallingIdentity();
9733
9734 try {
9735 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9736 if (configBinder == null) {
9737 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9738 } else {
9739 configBinder.setRcsClientConfiguration(rcc);
9740 }
9741 } catch (RemoteException e) {
9742 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9743 } finally {
9744 Binder.restoreCallingIdentity(identity);
9745 }
9746 }
9747
9748 /**
9749 * Overrides the config of RCS VoLTE single registration enabled for the device.
9750 */
9751 @Override
9752 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9753 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9754 "setDeviceSingleRegistrationEnabledOverride");
9755 enforceModifyPermission();
9756
9757 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9758 : Boolean.parseBoolean(enabledStr);
9759 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
9760 }
9761
9762 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009763 * Sends a device to device communication message. Only usable via shell.
9764 * @param message message to send.
9765 * @param value message value.
9766 */
9767 @Override
9768 public void sendDeviceToDeviceMessage(int message, int value) {
9769 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9770 "setCarrierSingleRegistrationEnabledOverride");
9771 enforceModifyPermission();
9772
9773 final long identity = Binder.clearCallingIdentity();
9774 try {
9775 TelephonyConnectionService service =
9776 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9777 if (service == null) {
9778 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9779 return;
9780 }
9781 service.sendTestDeviceToDeviceMessage(message, value);
9782 } finally {
9783 Binder.restoreCallingIdentity(identity);
9784 }
9785 }
9786
9787
9788 /**
Hui Wang068ab862020-10-31 05:12:53 +00009789 * Gets the config of RCS VoLTE single registration enabled for the device.
9790 */
9791 @Override
9792 public boolean getDeviceSingleRegistrationEnabled() {
9793 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9794 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9795 }
9796
9797 /**
9798 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9799 */
9800 @Override
9801 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9802 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9803 "setCarrierSingleRegistrationEnabledOverride");
9804 enforceModifyPermission();
9805
9806 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9807 : Boolean.parseBoolean(enabledStr);
9808 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9809 subId, enabled);
9810 }
9811
9812 /**
9813 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9814 */
9815 @Override
9816 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9817 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9818 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9819 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009820
9821 /**
9822 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9823 * their mobile plan.
9824 */
9825 @Override
9826 public String getMobileProvisioningUrl() {
9827 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9828 final long identity = Binder.clearCallingIdentity();
9829 try {
9830 return getDefaultPhone().getMobileProvisioningUrl();
9831 } finally {
9832 Binder.restoreCallingIdentity(identity);
9833 }
9834 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009835
James.cf Linbcdf8b32021-01-14 16:44:13 +08009836 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009837 * Get the EAB contact from the EAB database.
9838 */
9839 @Override
9840 public String getContactFromEab(String contact) {
9841 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9842 enforceModifyPermission();
9843 final long identity = Binder.clearCallingIdentity();
9844 try {
9845 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9846 } finally {
9847 Binder.restoreCallingIdentity(identity);
9848 }
9849 }
9850
9851 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009852 * Remove the EAB contacts from the EAB database.
9853 */
9854 @Override
9855 public int removeContactFromEab(int subId, String contacts) {
9856 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9857 enforceModifyPermission();
9858 final long identity = Binder.clearCallingIdentity();
9859 try {
9860 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9861 } finally {
9862 Binder.restoreCallingIdentity(identity);
9863 }
9864 }
9865
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009866 @Override
9867 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9868 String callingPackage) {
9869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9870 mApp, subId, "setSignalStrengthUpdateRequest");
9871
9872 final int callingUid = Binder.getCallingUid();
9873 // Verify that tha callingPackage belongs to the calling UID
9874 mApp.getSystemService(AppOpsManager.class)
9875 .checkPackage(callingUid, callingPackage);
9876
9877 validateSignalStrengthUpdateRequest(request, callingUid);
9878
9879 final long identity = Binder.clearCallingIdentity();
9880 try {
9881 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
9882 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9883
9884 if (result instanceof IllegalStateException) {
9885 throw (IllegalStateException) result;
9886 }
9887 } finally {
9888 Binder.restoreCallingIdentity(identity);
9889 }
9890 }
9891
9892 @Override
9893 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9894 String callingPackage) {
9895 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9896 mApp, subId, "clearSignalStrengthUpdateRequest");
9897
9898 final int callingUid = Binder.getCallingUid();
9899 // Verify that tha callingPackage belongs to the calling UID
9900 mApp.getSystemService(AppOpsManager.class)
9901 .checkPackage(callingUid, callingPackage);
9902
9903 final long identity = Binder.clearCallingIdentity();
9904 try {
9905 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
9906 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9907
9908 if (result instanceof IllegalStateException) {
9909 throw (IllegalStateException) result;
9910 }
9911 } finally {
9912 Binder.restoreCallingIdentity(identity);
9913 }
9914 }
9915
9916 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
9917 int callingUid) {
9918 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
9919 // phone/system process do not have further restriction on request
9920 return;
9921 }
9922
9923 // Applications has restrictions on how to use the request:
9924 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
9925 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
9926 // This is not system caller which has been checked above
9927 throw new IllegalArgumentException(
9928 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
9929 }
9930
9931 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
9932 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
9933 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
9934 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
9935 || info.isEnabled()) {
9936 throw new IllegalArgumentException(
9937 "Only system can set hide fields in SignalThresholdInfo");
9938 }
9939
9940 // Thresholds length for each RAN need in range. This has been validated in
9941 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
9942 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
9943 final int[] thresholds = info.getThresholds();
9944 Objects.requireNonNull(thresholds);
9945 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
9946 || thresholds.length
9947 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
9948 throw new IllegalArgumentException(
9949 "thresholds length is out of range: " + thresholds.length);
9950 }
9951 }
9952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009953}