blob: 933a764100b49c06a978f49377f44495e6dc68a5 [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;
Michele Berionned9fbae52020-11-13 02:36:59 +0000324 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700325
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800326 // Parameters of select command.
327 private static final int SELECT_COMMAND = 0xA4;
328 private static final int SELECT_P1 = 0x04;
329 private static final int SELECT_P2 = 0;
330 private static final int SELECT_P3 = 0x10;
331
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332 /** The singleton instance. */
333 private static PhoneInterfaceManager sInstance;
334
Wink Saville3ab207e2014-11-20 13:07:20 -0800335 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800336 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800337 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700338 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800339 private AppOpsManager mAppOps;
340 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800341 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800342 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700343 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344
Peter Wangdafb9ac2020-01-15 14:13:38 -0800345 /** User Activity */
346 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800347 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
348
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700349 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
350
Derek Tan97ebb422014-09-05 16:55:38 -0700351 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
352 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800353 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800354 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700355
Michelecea4cf22018-12-21 15:00:11 -0800356 // String to store multi SIM allowed
357 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
358
Derek Tan740e1672017-06-27 14:56:27 -0700359 // The AID of ISD-R.
360 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
361
yinxub1bed742017-04-17 11:45:04 -0700362 private NetworkScanRequestTracker mNetworkScanRequestTracker;
363
David Kelly5e06a7f2018-03-12 14:10:59 +0000364 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
365 private static final int MANUFACTURER_CODE_LENGTH = 8;
366
Jack Nudelman24d51a52020-11-24 12:08:04 -0800367 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
368
Derek Tan89e89d42014-07-08 17:00:10 -0700369 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700370 * Experiment flag to enable erase modem config on reset network, default value is false
371 */
372 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
373 "reset_network_erase_modem_config_enabled";
374
375 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700376 * A request object to use for transmitting data to an ICC.
377 */
378 private static final class IccAPDUArgument {
379 public int channel, cla, command, p1, p2, p3;
380 public String data;
381
382 public IccAPDUArgument(int channel, int cla, int command,
383 int p1, int p2, int p3, String data) {
384 this.channel = channel;
385 this.cla = cla;
386 this.command = command;
387 this.p1 = p1;
388 this.p2 = p2;
389 this.p3 = p3;
390 this.data = data;
391 }
392 }
393
394 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700395 * A request object to use for transmitting data to an ICC.
396 */
397 private static final class ManualNetworkSelectionArgument {
398 public OperatorInfo operatorInfo;
399 public boolean persistSelection;
400
401 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
402 this.operatorInfo = operatorInfo;
403 this.persistSelection = persistSelection;
404 }
405 }
406
407 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
409 * request after sending. The main thread will notify the request when it is complete.
410 */
411 private static final class MainThreadRequest {
412 /** The argument to use for the request */
413 public Object argument;
414 /** The result of the request that is run on the main thread */
415 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800416 // The subscriber id that this request applies to. Defaults to
417 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
418 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700419
Nathan Harold92bed182018-10-12 18:16:49 -0700420 // In cases where subId is unavailable, the caller needs to specify the phone.
421 public Phone phone;
422
vagdeviaf9a5b92018-08-15 16:01:53 -0700423 public WorkSource workSource;
424
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425 public MainThreadRequest(Object argument) {
426 this.argument = argument;
427 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800428
Nathan Harold92bed182018-10-12 18:16:49 -0700429 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
430 this.argument = argument;
431 if (phone != null) {
432 this.phone = phone;
433 }
434 this.workSource = workSource;
435 }
436
vagdeviaf9a5b92018-08-15 16:01:53 -0700437 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800438 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800439 if (subId != null) {
440 this.subId = subId;
441 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700442 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800443 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444 }
445
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800446 private static final class IncomingThirdPartyCallArgs {
447 public final ComponentName component;
448 public final String callId;
449 public final String callerDisplayName;
450
451 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
452 String callerDisplayName) {
453 this.component = component;
454 this.callId = callId;
455 this.callerDisplayName = callerDisplayName;
456 }
457 }
458
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459 /**
460 * A handler that processes messages on the main thread in the phone process. Since many
461 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
462 * inbound binder threads to the main thread in the phone process. The Binder thread
463 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
464 * on, which will be notified when the operation completes and will contain the result of the
465 * request.
466 *
467 * <p>If a MainThreadRequest object is provided in the msg.obj field,
468 * note that request.result must be set to something non-null for the calling thread to
469 * unblock.
470 */
471 private final class MainThreadHandler extends Handler {
472 @Override
473 public void handleMessage(Message msg) {
474 MainThreadRequest request;
475 Message onCompleted;
476 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800477 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700478 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800479 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700480
481 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700482 case CMD_HANDLE_USSD_REQUEST: {
483 request = (MainThreadRequest) msg.obj;
484 final Phone phone = getPhoneFromRequest(request);
485 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
486 String ussdRequest = ussdObject.first;
487 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700488
Pengquan Menga1bb6272018-09-06 09:59:22 -0700489 if (!isUssdApiAllowed(request.subId)) {
490 // Carrier does not support use of this API, return failure.
491 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
492 UssdResponse response = new UssdResponse(ussdRequest, null);
493 Bundle returnData = new Bundle();
494 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
495 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700496
Pengquan Menga1bb6272018-09-06 09:59:22 -0700497 request.result = true;
498 notifyRequester(request);
499 return;
500 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700501
Pengquan Menga1bb6272018-09-06 09:59:22 -0700502 try {
503 request.result = phone != null
504 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
505 } catch (CallStateException cse) {
506 request.result = false;
507 }
508 // Wake up the requesting thread
509 notifyRequester(request);
510 break;
pkanwar32d516d2016-10-14 19:37:38 -0700511 }
512
Yorke Lee716f67e2015-06-17 15:39:16 -0700513 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700514 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700515 final Phone phone = getPhoneFromRequest(request);
516 request.result = phone != null ?
517 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
518 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700520 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700522 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700523
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700525 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800527 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700528 if (uiccCard == null) {
529 loge("iccTransmitApduLogicalChannel: No UICC");
530 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700532 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700533 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
534 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700535 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700536 iccArgument.channel, iccArgument.cla, iccArgument.command,
537 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700538 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700539 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700540 break;
541
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700542 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700543 ar = (AsyncResult) msg.obj;
544 request = (MainThreadRequest) ar.userObj;
545 if (ar.exception == null && ar.result != null) {
546 request.result = ar.result;
547 } else {
548 request.result = new IccIoResult(0x6F, 0, (byte[])null);
549 if (ar.result == null) {
550 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800551 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700552 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800553 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 } else {
555 loge("iccTransmitApduLogicalChannel: Unknown exception");
556 }
557 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700559 break;
560
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
562 request = (MainThreadRequest) msg.obj;
563 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800564 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700565 if (uiccCard == null) {
566 loge("iccTransmitApduBasicChannel: No UICC");
567 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700569 } else {
570 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
571 request);
572 uiccCard.iccTransmitApduBasicChannel(
573 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
574 iccArgument.p3, iccArgument.data, onCompleted);
575 }
576 break;
577
578 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
579 ar = (AsyncResult) msg.obj;
580 request = (MainThreadRequest) ar.userObj;
581 if (ar.exception == null && ar.result != null) {
582 request.result = ar.result;
583 } else {
584 request.result = new IccIoResult(0x6F, 0, (byte[])null);
585 if (ar.result == null) {
586 loge("iccTransmitApduBasicChannel: Empty response");
587 } else if (ar.exception instanceof CommandException) {
588 loge("iccTransmitApduBasicChannel: CommandException: " +
589 ar.exception);
590 } else {
591 loge("iccTransmitApduBasicChannel: Unknown exception");
592 }
593 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 break;
596
597 case CMD_EXCHANGE_SIM_IO:
598 request = (MainThreadRequest) msg.obj;
599 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800600 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700601 if (uiccCard == null) {
602 loge("iccExchangeSimIO: No UICC");
603 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700604 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700605 } else {
606 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
607 request);
608 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
609 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
610 iccArgument.data, onCompleted);
611 }
612 break;
613
614 case EVENT_EXCHANGE_SIM_IO_DONE:
615 ar = (AsyncResult) msg.obj;
616 request = (MainThreadRequest) ar.userObj;
617 if (ar.exception == null && ar.result != null) {
618 request.result = ar.result;
619 } else {
620 request.result = new IccIoResult(0x6f, 0, (byte[])null);
621 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700622 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 break;
624
Derek Tan4d5e5c12014-02-04 11:54:58 -0800625 case CMD_SEND_ENVELOPE:
626 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800627 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700628 if (uiccCard == null) {
629 loge("sendEnvelopeWithStatus: No UICC");
630 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700631 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700632 } else {
633 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
634 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
635 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800636 break;
637
638 case EVENT_SEND_ENVELOPE_DONE:
639 ar = (AsyncResult) msg.obj;
640 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700641 if (ar.exception == null && ar.result != null) {
642 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800643 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700644 request.result = new IccIoResult(0x6F, 0, (byte[])null);
645 if (ar.result == null) {
646 loge("sendEnvelopeWithStatus: Empty response");
647 } else if (ar.exception instanceof CommandException) {
648 loge("sendEnvelopeWithStatus: CommandException: " +
649 ar.exception);
650 } else {
651 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
652 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800653 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800655 break;
656
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 case CMD_OPEN_CHANNEL:
658 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800659 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800660 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700661 if (uiccCard == null) {
662 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800663 request.result = new IccOpenLogicalChannelResponse(-1,
664 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700665 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700666 } else {
667 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800668 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
669 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700670 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 break;
672
673 case EVENT_OPEN_CHANNEL_DONE:
674 ar = (AsyncResult) msg.obj;
675 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700676 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700678 int[] result = (int[]) ar.result;
679 int channelId = result[0];
680 byte[] selectResponse = null;
681 if (result.length > 1) {
682 selectResponse = new byte[result.length - 1];
683 for (int i = 1; i < result.length; ++i) {
684 selectResponse[i - 1] = (byte) result[i];
685 }
686 }
687 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700688 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 if (ar.result == null) {
691 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700693 if (ar.exception != null) {
694 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
695 }
696
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700697 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700698 if (ar.exception instanceof CommandException) {
699 CommandException.Error error =
700 ((CommandException) (ar.exception)).getCommandError();
701 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700702 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700703 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700704 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700705 }
706 }
707 openChannelResp = new IccOpenLogicalChannelResponse(
708 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700709 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700710 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700711 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700712 break;
713
714 case CMD_CLOSE_CHANNEL:
715 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800716 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700717 if (uiccCard == null) {
718 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900719 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700720 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700721 } else {
722 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
723 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
724 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700725 break;
726
727 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800728 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
729 break;
730
731 case CMD_NV_READ_ITEM:
732 request = (MainThreadRequest) msg.obj;
733 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800734 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
735 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800736 break;
737
738 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700739 ar = (AsyncResult) msg.obj;
740 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800741 if (ar.exception == null && ar.result != null) {
742 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700743 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800744 request.result = "";
745 if (ar.result == null) {
746 loge("nvReadItem: Empty response");
747 } else if (ar.exception instanceof CommandException) {
748 loge("nvReadItem: CommandException: " +
749 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700750 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800751 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700752 }
753 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700754 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700755 break;
756
Jake Hambye994d462014-02-03 13:10:13 -0800757 case CMD_NV_WRITE_ITEM:
758 request = (MainThreadRequest) msg.obj;
759 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
760 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800761 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700762 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800763 break;
764
765 case EVENT_NV_WRITE_ITEM_DONE:
766 handleNullReturnEvent(msg, "nvWriteItem");
767 break;
768
769 case CMD_NV_WRITE_CDMA_PRL:
770 request = (MainThreadRequest) msg.obj;
771 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800772 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800773 break;
774
775 case EVENT_NV_WRITE_CDMA_PRL_DONE:
776 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
777 break;
778
chen xu6dac5ab2018-10-26 17:39:23 -0700779 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800780 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700781 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800782 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800783 break;
784
chen xu6dac5ab2018-10-26 17:39:23 -0700785 case EVENT_RESET_MODEM_CONFIG_DONE:
786 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800787 break;
788
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700789 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
790 request = (MainThreadRequest) msg.obj;
791 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
792 request);
793 Phone phone = getPhoneFromRequest(request);
794 if (phone != null) {
795 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
796 } else {
797 loge("isNRDualConnectivityEnabled: No phone object");
798 request.result = false;
799 notifyRequester(request);
800 }
801 break;
802 }
803
804 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
805 ar = (AsyncResult) msg.obj;
806 request = (MainThreadRequest) ar.userObj;
807 if (ar.exception == null && ar.result != null) {
808 request.result = ar.result;
809 } else {
810 // request.result must be set to something non-null
811 // for the calling thread to unblock
812 if (request.result != null) {
813 request.result = ar.result;
814 } else {
815 request.result = false;
816 }
817 if (ar.result == null) {
818 loge("isNRDualConnectivityEnabled: Empty response");
819 } else if (ar.exception instanceof CommandException) {
820 loge("isNRDualConnectivityEnabled: CommandException: "
821 + ar.exception);
822 } else {
823 loge("isNRDualConnectivityEnabled: Unknown exception");
824 }
825 }
826 notifyRequester(request);
827 break;
828
829 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
830 request = (MainThreadRequest) msg.obj;
831 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
832 Phone phone = getPhoneFromRequest(request);
833 if (phone != null) {
834 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
835 request.workSource);
836 } else {
837 loge("enableNrDualConnectivity: No phone object");
838 request.result =
839 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
840 notifyRequester(request);
841 }
842 break;
843 }
844
845 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
846 ar = (AsyncResult) msg.obj;
847 request = (MainThreadRequest) ar.userObj;
848 if (ar.exception == null) {
849 request.result =
850 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
851 } else {
852 request.result =
853 TelephonyManager
854 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
855 if (ar.exception instanceof CommandException) {
856 CommandException.Error error =
857 ((CommandException) (ar.exception)).getCommandError();
858 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
859 request.result =
860 TelephonyManager
861 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
862 }
863 loge("enableNrDualConnectivity" + ": CommandException: "
864 + ar.exception);
865 } else {
866 loge("enableNrDualConnectivity" + ": Unknown exception");
867 }
868 }
869 notifyRequester(request);
870 break;
871 }
872
Jake Hamby7c27be32014-03-03 13:25:59 -0800873 case CMD_GET_PREFERRED_NETWORK_TYPE:
874 request = (MainThreadRequest) msg.obj;
875 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700876 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800877 break;
878
879 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
880 ar = (AsyncResult) msg.obj;
881 request = (MainThreadRequest) ar.userObj;
882 if (ar.exception == null && ar.result != null) {
883 request.result = ar.result; // Integer
884 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530885 // request.result must be set to something non-null
886 // for the calling thread to unblock
887 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800888 if (ar.result == null) {
889 loge("getPreferredNetworkType: Empty response");
890 } else if (ar.exception instanceof CommandException) {
891 loge("getPreferredNetworkType: CommandException: " +
892 ar.exception);
893 } else {
894 loge("getPreferredNetworkType: Unknown exception");
895 }
896 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700897 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800898 break;
899
900 case CMD_SET_PREFERRED_NETWORK_TYPE:
901 request = (MainThreadRequest) msg.obj;
902 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
903 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700904 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800905 break;
906
907 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
908 handleNullReturnEvent(msg, "setPreferredNetworkType");
909 break;
910
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000911 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
912 request = (MainThreadRequest)msg.obj;
913 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800914 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000915 break;
916
917 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
918 ar = (AsyncResult)msg.obj;
919 request = (MainThreadRequest)ar.userObj;
920 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700921 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000922 break;
923
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800924 case CMD_SET_VOICEMAIL_NUMBER:
925 request = (MainThreadRequest) msg.obj;
926 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
927 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800928 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
929 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800930 break;
931
932 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
933 handleNullReturnEvent(msg, "setVoicemailNumber");
934 break;
935
Stuart Scott54788802015-03-30 13:18:01 -0700936 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
937 request = (MainThreadRequest) msg.obj;
938 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
939 request);
940 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
941 break;
942
943 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
944 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
945 break;
946
Shishir Agrawal302c8692015-06-19 13:49:39 -0700947 case CMD_PERFORM_NETWORK_SCAN:
948 request = (MainThreadRequest) msg.obj;
949 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
950 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
951 break;
952
Hall Liua1acea22020-09-18 19:04:59 -0700953 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800954 request = (MainThreadRequest) msg.obj;
955 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700956 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
957 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
958 request.argument;
959 int callForwardingReason = args.first;
960 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800961 break;
Hall Liua1acea22020-09-18 19:04:59 -0700962 }
963 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800964 ar = (AsyncResult) msg.obj;
965 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700966 TelephonyManager.CallForwardingInfoCallback callback =
967 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
968 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800969 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700970 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800971 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
972 for (CallForwardInfo callForwardInfo : callForwardInfos) {
973 // Service Class is a bit mask per 3gpp 27.007. Search for
974 // any service for voice call.
975 if ((callForwardInfo.serviceClass
976 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700977 callForwardingInfo = new CallForwardingInfo(true,
978 callForwardInfo.reason,
979 callForwardInfo.number,
980 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800981 break;
982 }
983 }
984 // Didn't find a call forward info for voice call.
985 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700986 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
987 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800988 }
Hall Liua1acea22020-09-18 19:04:59 -0700989 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -0800990 } else {
991 if (ar.result == null) {
992 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
993 }
994 if (ar.exception != null) {
995 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
996 }
Hall Liuae527aa2020-09-29 17:10:18 -0700997 int errorCode = TelephonyManager
998 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -0800999 if (ar.exception instanceof CommandException) {
1000 CommandException.Error error =
1001 ((CommandException) (ar.exception)).getCommandError();
1002 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001003 errorCode = TelephonyManager
1004 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001005 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001006 errorCode = TelephonyManager
1007 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001008 }
1009 }
Hall Liua1acea22020-09-18 19:04:59 -07001010 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001011 }
sqian80370722020-01-29 15:02:51 -08001012 break;
Hall Liua1acea22020-09-18 19:04:59 -07001013 }
sqian80370722020-01-29 15:02:51 -08001014
Hall Liua1acea22020-09-18 19:04:59 -07001015 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001016 request = (MainThreadRequest) msg.obj;
1017 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001018 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001019 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001020 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1021 request.argument).first;
1022 request.phone.setCallForwardingOption(
1023 callForwardingInfoToSet.isEnabled()
1024 ? CommandsInterface.CF_ACTION_ENABLE
1025 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001026 callForwardingInfoToSet.getReason(),
1027 callForwardingInfoToSet.getNumber(),
1028 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1029 break;
Hall Liua1acea22020-09-18 19:04:59 -07001030 }
sqian80370722020-01-29 15:02:51 -08001031
Hall Liua1acea22020-09-18 19:04:59 -07001032 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001033 ar = (AsyncResult) msg.obj;
1034 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001035 Consumer<Integer> callback =
1036 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1037 request.argument).second;
1038 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001039 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001040 int errorCode = TelephonyManager.CallForwardingInfoCallback
1041 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001042 if (ar.exception instanceof CommandException) {
1043 CommandException.Error error =
1044 ((CommandException) (ar.exception)).getCommandError();
1045 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001046 errorCode = TelephonyManager.CallForwardingInfoCallback
1047 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001048 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001049 errorCode = TelephonyManager.CallForwardingInfoCallback
1050 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001051 }
1052 }
1053 callback.accept(errorCode);
1054 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001055 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001056 }
sqian80370722020-01-29 15:02:51 -08001057 break;
Hall Liua1acea22020-09-18 19:04:59 -07001058 }
sqian80370722020-01-29 15:02:51 -08001059
Hall Liua1acea22020-09-18 19:04:59 -07001060 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001061 request = (MainThreadRequest) msg.obj;
1062 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1063 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1064 break;
Hall Liua1acea22020-09-18 19:04:59 -07001065 }
sqian80370722020-01-29 15:02:51 -08001066
Hall Liua1acea22020-09-18 19:04:59 -07001067 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001068 ar = (AsyncResult) msg.obj;
1069 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001070 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001071 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1072 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001073 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001074 // Service Class is a bit mask per 3gpp 27.007.
1075 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001076 if (callForwardResults.length > 1
1077 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001078 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001079 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001080 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1081 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001082 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001083 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001084 }
1085 } else {
1086 if (ar.result == null) {
1087 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1088 }
1089 if (ar.exception != null) {
1090 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1091 }
1092 if (ar.exception instanceof CommandException) {
1093 CommandException.Error error =
1094 ((CommandException) (ar.exception)).getCommandError();
1095 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1096 callForwardingStatus =
1097 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1098 }
1099 }
1100 }
Hall Liua1acea22020-09-18 19:04:59 -07001101 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001102 break;
Hall Liua1acea22020-09-18 19:04:59 -07001103 }
sqian80370722020-01-29 15:02:51 -08001104
Hall Liua1acea22020-09-18 19:04:59 -07001105 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001106 request = (MainThreadRequest) msg.obj;
1107 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001108 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1109 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001110 break;
Hall Liua1acea22020-09-18 19:04:59 -07001111 }
sqian80370722020-01-29 15:02:51 -08001112
Hall Liua1acea22020-09-18 19:04:59 -07001113 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001114 ar = (AsyncResult) msg.obj;
1115 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001116 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1117 Consumer<Integer> callback =
1118 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1119 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001120 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001121 if (ar.exception instanceof CommandException) {
1122 CommandException.Error error =
1123 ((CommandException) (ar.exception)).getCommandError();
1124 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1125 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1126 } else {
1127 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1128 }
1129 } else {
1130 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1131 }
1132 } else {
1133 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1134 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001135 }
sqian80370722020-01-29 15:02:51 -08001136 break;
Hall Liua1acea22020-09-18 19:04:59 -07001137 }
sqian80370722020-01-29 15:02:51 -08001138
Shishir Agrawal302c8692015-06-19 13:49:39 -07001139 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1140 ar = (AsyncResult) msg.obj;
1141 request = (MainThreadRequest) ar.userObj;
1142 CellNetworkScanResult cellScanResult;
1143 if (ar.exception == null && ar.result != null) {
1144 cellScanResult = new CellNetworkScanResult(
1145 CellNetworkScanResult.STATUS_SUCCESS,
1146 (List<OperatorInfo>) ar.result);
1147 } else {
1148 if (ar.result == null) {
1149 loge("getCellNetworkScanResults: Empty response");
1150 }
1151 if (ar.exception != null) {
1152 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1153 }
1154 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1155 if (ar.exception instanceof CommandException) {
1156 CommandException.Error error =
1157 ((CommandException) (ar.exception)).getCommandError();
1158 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1159 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1160 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1161 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1162 }
1163 }
1164 cellScanResult = new CellNetworkScanResult(errorCode, null);
1165 }
1166 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001167 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001168 break;
1169
1170 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1171 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001172 ManualNetworkSelectionArgument selArg =
1173 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001174 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1175 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001176 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1177 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001178 break;
1179
1180 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001181 ar = (AsyncResult) msg.obj;
1182 request = (MainThreadRequest) ar.userObj;
1183 if (ar.exception == null) {
1184 request.result = true;
1185 } else {
1186 request.result = false;
1187 loge("setNetworkSelectionModeManual " + ar.exception);
1188 }
1189 notifyRequester(request);
1190 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001191 break;
1192
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001193 case CMD_GET_MODEM_ACTIVITY_INFO:
1194 request = (MainThreadRequest) msg.obj;
1195 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001196 if (defaultPhone != null) {
1197 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001198 } else {
1199 ResultReceiver result = (ResultReceiver) request.argument;
1200 Bundle bundle = new Bundle();
1201 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1202 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1203 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001204 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001205 break;
1206
1207 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1208 ar = (AsyncResult) msg.obj;
1209 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001210 ResultReceiver result = (ResultReceiver) request.argument;
1211
1212 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001213 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001214 // Update the last modem activity info and the result of the request.
1215 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1216 if (isModemActivityInfoValid(info)) {
1217 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1218 int[] txTimeMs = info.getTransmitTimeMillis();
1219 int[] lastModemTxTimeMs = mLastModemActivityInfo
1220 .getTransmitTimeMillis();
1221 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1222 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1223 }
1224 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1225 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1226 + mLastModemActivityInfo.getSleepTimeMillis());
1227 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1228 + mLastModemActivityInfo.getIdleTimeMillis());
1229 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1230 mLastModemActivityInfo.setReceiveTimeMillis(
1231 info.getReceiveTimeMillis()
1232 + mLastModemActivityInfo.getReceiveTimeMillis());
1233 }
1234 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1235 mLastModemActivityInfo.getSleepTimeMillis(),
1236 mLastModemActivityInfo.getIdleTimeMillis(),
1237 mLastModemActivityInfo.getTransmitTimeMillis(),
1238 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001239 } else {
1240 if (ar.result == null) {
1241 loge("queryModemActivityInfo: Empty response");
1242 } else if (ar.exception instanceof CommandException) {
1243 loge("queryModemActivityInfo: CommandException: " +
1244 ar.exception);
1245 } else {
1246 loge("queryModemActivityInfo: Unknown exception");
1247 }
1248 }
sqian1a1be542020-03-05 11:37:28 -08001249 Bundle bundle = new Bundle();
1250 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1251 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001252 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001253 break;
1254
Meng Wang1a7c35a2016-05-05 20:56:15 -07001255 case CMD_SET_ALLOWED_CARRIERS:
1256 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001257 CarrierRestrictionRules argument =
1258 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001259 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001260 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001261 break;
1262
1263 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1264 ar = (AsyncResult) msg.obj;
1265 request = (MainThreadRequest) ar.userObj;
1266 if (ar.exception == null && ar.result != null) {
1267 request.result = ar.result;
1268 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001269 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1270 if (ar.exception instanceof CommandException) {
1271 loge("setAllowedCarriers: CommandException: " + ar.exception);
1272 CommandException.Error error =
1273 ((CommandException) (ar.exception)).getCommandError();
1274 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1275 request.result =
1276 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1277 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001278 } else {
1279 loge("setAllowedCarriers: Unknown exception");
1280 }
1281 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001282 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001283 break;
1284
1285 case CMD_GET_ALLOWED_CARRIERS:
1286 request = (MainThreadRequest) msg.obj;
1287 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001288 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001289 break;
1290
1291 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1292 ar = (AsyncResult) msg.obj;
1293 request = (MainThreadRequest) ar.userObj;
1294 if (ar.exception == null && ar.result != null) {
1295 request.result = ar.result;
1296 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001297 request.result = new IllegalStateException(
1298 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001299 if (ar.result == null) {
1300 loge("getAllowedCarriers: Empty response");
1301 } else if (ar.exception instanceof CommandException) {
1302 loge("getAllowedCarriers: CommandException: " +
1303 ar.exception);
1304 } else {
1305 loge("getAllowedCarriers: Unknown exception");
1306 }
1307 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001308 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001309 break;
1310
Nathan Haroldb3014052017-01-25 15:57:32 -08001311 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1312 ar = (AsyncResult) msg.obj;
1313 request = (MainThreadRequest) ar.userObj;
1314 if (ar.exception == null && ar.result != null) {
1315 request.result = ar.result;
1316 } else {
1317 request.result = new IllegalArgumentException(
1318 "Failed to retrieve Forbidden Plmns");
1319 if (ar.result == null) {
1320 loge("getForbiddenPlmns: Empty response");
1321 } else {
1322 loge("getForbiddenPlmns: Unknown exception");
1323 }
1324 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001325 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001326 break;
1327
1328 case CMD_GET_FORBIDDEN_PLMNS:
1329 request = (MainThreadRequest) msg.obj;
1330 uiccCard = getUiccCardFromRequest(request);
1331 if (uiccCard == null) {
1332 loge("getForbiddenPlmns() UiccCard is null");
1333 request.result = new IllegalArgumentException(
1334 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001335 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001336 break;
1337 }
1338 Integer appType = (Integer) request.argument;
1339 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1340 if (uiccApp == null) {
1341 loge("getForbiddenPlmns() no app with specified type -- "
1342 + appType);
1343 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001344 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001345 break;
1346 } else {
1347 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1348 + " specified type -- " + appType);
1349 }
1350 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1351 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1352 onCompleted);
1353 break;
1354
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001355 case CMD_SWITCH_SLOTS:
1356 request = (MainThreadRequest) msg.obj;
1357 int[] physicalSlots = (int[]) request.argument;
1358 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1359 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1360 break;
1361
1362 case EVENT_SWITCH_SLOTS_DONE:
1363 ar = (AsyncResult) msg.obj;
1364 request = (MainThreadRequest) ar.userObj;
1365 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001366 notifyRequester(request);
1367 break;
1368 case CMD_GET_NETWORK_SELECTION_MODE:
1369 request = (MainThreadRequest) msg.obj;
1370 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1371 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1372 break;
1373
1374 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1375 ar = (AsyncResult) msg.obj;
1376 request = (MainThreadRequest) ar.userObj;
1377 if (ar.exception != null) {
1378 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1379 } else {
1380 int mode = ((int[]) ar.result)[0];
1381 if (mode == 0) {
1382 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1383 } else {
1384 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1385 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001386 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001387 notifyRequester(request);
1388 break;
1389 case CMD_GET_CDMA_ROAMING_MODE:
1390 request = (MainThreadRequest) msg.obj;
1391 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1392 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1393 break;
1394 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1395 ar = (AsyncResult) msg.obj;
1396 request = (MainThreadRequest) ar.userObj;
1397 if (ar.exception != null) {
1398 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1399 } else {
1400 request.result = ((int[]) ar.result)[0];
1401 }
1402 notifyRequester(request);
1403 break;
1404 case CMD_SET_CDMA_ROAMING_MODE:
1405 request = (MainThreadRequest) msg.obj;
1406 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1407 int mode = (int) request.argument;
1408 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1409 break;
1410 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1411 ar = (AsyncResult) msg.obj;
1412 request = (MainThreadRequest) ar.userObj;
1413 request.result = ar.exception == null;
1414 notifyRequester(request);
1415 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001416 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1417 request = (MainThreadRequest) msg.obj;
1418 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1419 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1420 break;
1421 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1422 ar = (AsyncResult) msg.obj;
1423 request = (MainThreadRequest) ar.userObj;
1424 if (ar.exception != null) {
1425 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1426 } else {
1427 request.result = ((int[]) ar.result)[0];
1428 }
1429 notifyRequester(request);
1430 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001431 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1432 request = (MainThreadRequest) msg.obj;
1433 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1434 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001435 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1436 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001437 break;
1438 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1439 ar = (AsyncResult) msg.obj;
1440 request = (MainThreadRequest) ar.userObj;
1441 request.result = ar.exception == null;
1442 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001443 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001444 case CMD_GET_ALL_CELL_INFO:
1445 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001446 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001447 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001448 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001449 case EVENT_GET_ALL_CELL_INFO_DONE:
1450 ar = (AsyncResult) msg.obj;
1451 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001452 // If a timeout occurs, the response will be null
1453 request.result = (ar.exception == null && ar.result != null)
1454 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001455 synchronized (request) {
1456 request.notifyAll();
1457 }
1458 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001459 case CMD_REQUEST_CELL_INFO_UPDATE:
1460 request = (MainThreadRequest) msg.obj;
1461 request.phone.requestCellInfoUpdate(request.workSource,
1462 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1463 break;
1464 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1465 ar = (AsyncResult) msg.obj;
1466 request = (MainThreadRequest) ar.userObj;
1467 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1468 try {
1469 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001470 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001471 cb.onError(
1472 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1473 ar.exception.getClass().getName(),
1474 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001475 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001476 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001477 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001478 } else {
1479 // use the result as returned
1480 cb.onCellInfo((List<CellInfo>) ar.result);
1481 }
1482 } catch (RemoteException re) {
1483 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1484 }
1485 break;
Sarah Chincc055732020-11-18 13:39:35 -08001486 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001487 request = (MainThreadRequest) msg.obj;
1488 WorkSource ws = (WorkSource) request.argument;
1489 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001490 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001491 break;
Sarah Chincc055732020-11-18 13:39:35 -08001492 }
1493 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001494 ar = (AsyncResult) msg.obj;
1495 request = (MainThreadRequest) ar.userObj;
1496 if (ar.exception == null) {
1497 request.result = ar.result;
1498 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001499 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001500 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001501 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001502 }
1503
1504 synchronized (request) {
1505 request.notifyAll();
1506 }
1507 break;
Sarah Chincc055732020-11-18 13:39:35 -08001508 }
chen xu6dac5ab2018-10-26 17:39:23 -07001509 case CMD_MODEM_REBOOT:
1510 request = (MainThreadRequest) msg.obj;
1511 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001512 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001513 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001514 case EVENT_CMD_MODEM_REBOOT_DONE:
1515 handleNullReturnEvent(msg, "rebootModem");
1516 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001517 case CMD_REQUEST_ENABLE_MODEM:
1518 request = (MainThreadRequest) msg.obj;
1519 boolean enable = (boolean) request.argument;
1520 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001521 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001522 PhoneConfigurationManager.getInstance()
1523 .enablePhone(request.phone, enable, onCompleted);
1524 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001525 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001526 ar = (AsyncResult) msg.obj;
1527 request = (MainThreadRequest) ar.userObj;
1528 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001529 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001530 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001531 if ((boolean) request.result) {
1532 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1533 updateModemStateMetrics();
1534 } else {
1535 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1536 + ar.exception);
1537 }
1538 notifyRequester(request);
1539 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001540 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001541 case CMD_GET_MODEM_STATUS:
1542 request = (MainThreadRequest) msg.obj;
1543 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1544 PhoneConfigurationManager.getInstance()
1545 .getPhoneStatusFromModem(request.phone, onCompleted);
1546 break;
1547 case EVENT_GET_MODEM_STATUS_DONE:
1548 ar = (AsyncResult) msg.obj;
1549 request = (MainThreadRequest) ar.userObj;
1550 int id = request.phone.getPhoneId();
1551 if (ar.exception == null && ar.result != null) {
1552 request.result = ar.result;
1553 //update the cache as modem status has changed
1554 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1555 (boolean) request.result);
1556 } else {
1557 // Return true if modem status cannot be retrieved. For most cases,
1558 // modem status is on. And for older version modems, GET_MODEM_STATUS
1559 // and disable modem are not supported. Modem is always on.
1560 // TODO: this should be fixed in R to support a third
1561 // status UNKNOWN b/131631629
1562 request.result = true;
1563 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1564 + ar.exception);
1565 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001566 notifyRequester(request);
1567 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001568 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1569 request = (MainThreadRequest) msg.obj;
1570 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1571 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1572 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1573 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1574 break;
1575 }
1576 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1577 ar = (AsyncResult) msg.obj;
1578 request = (MainThreadRequest) ar.userObj;
1579 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1580 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1581 args.second.accept(ar.exception == null);
1582 notifyRequester(request);
1583 break;
1584 }
Sarah Chincc055732020-11-18 13:39:35 -08001585 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1586 request = (MainThreadRequest) msg.obj;
1587 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1588 Phone phone = getPhoneFromRequest(request);
1589 if (phone != null) {
1590 phone.getSystemSelectionChannels(onCompleted);
1591 } else {
1592 loge("getSystemSelectionChannels: No phone object");
1593 request.result = new ArrayList<RadioAccessSpecifier>();
1594 notifyRequester(request);
1595 }
1596 break;
1597 }
1598 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1599 ar = (AsyncResult) msg.obj;
1600 request = (MainThreadRequest) ar.userObj;
1601 if (ar.exception == null && ar.result != null) {
1602 request.result = ar.result;
1603 } else {
1604 request.result = new IllegalArgumentException(
1605 "Failed to retrieve system selection channels");
1606 if (ar.result == null) {
1607 loge("getSystemSelectionChannels: Empty response");
1608 } else {
1609 loge("getSystemSelectionChannels: Unknown exception");
1610 }
1611 }
1612 notifyRequester(request);
1613 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001614 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1615 ar = (AsyncResult) msg.obj;
1616 request = (MainThreadRequest) ar.userObj;
1617 if (ar.exception == null && ar.result != null) {
1618 request.result = ar.result;
1619 } else {
1620 request.result = -1;
1621 loge("Failed to set Forbidden Plmns");
1622 if (ar.result == null) {
1623 loge("setForbidenPlmns: Empty response");
1624 } else if (ar.exception != null) {
1625 loge("setForbiddenPlmns: Exception: " + ar.exception);
1626 request.result = -1;
1627 } else {
1628 loge("setForbiddenPlmns: Unknown exception");
1629 }
1630 }
1631 notifyRequester(request);
1632 break;
1633 case CMD_SET_FORBIDDEN_PLMNS:
1634 request = (MainThreadRequest) msg.obj;
1635 uiccCard = getUiccCardFromRequest(request);
1636 if (uiccCard == null) {
1637 loge("setForbiddenPlmns: UiccCard is null");
1638 request.result = -1;
1639 notifyRequester(request);
1640 break;
1641 }
1642 Pair<Integer, List<String>> setFplmnsArgs =
1643 (Pair<Integer, List<String>>) request.argument;
1644 appType = setFplmnsArgs.first;
1645 List<String> fplmns = setFplmnsArgs.second;
1646 uiccApp = uiccCard.getApplicationByType(appType);
1647 if (uiccApp == null) {
1648 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1649 request.result = -1;
1650 loge("Failed to get UICC App");
1651 notifyRequester(request);
1652 } else {
1653 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1654 ((SIMRecords) uiccApp.getIccRecords())
1655 .setForbiddenPlmns(onCompleted, fplmns);
1656 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001657 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001658 case CMD_ERASE_MODEM_CONFIG:
1659 request = (MainThreadRequest) msg.obj;
1660 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1661 defaultPhone.eraseModemConfig(onCompleted);
1662 break;
1663 case EVENT_ERASE_MODEM_CONFIG_DONE:
1664 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001665 break;
zoey chenf95ca592019-12-30 16:11:23 +08001666
1667 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1668 request = (MainThreadRequest) msg.obj;
1669 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1670 Pair<String, String> changed = (Pair<String, String>) request.argument;
1671 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1672 changed.first, changed.second, onCompleted);
1673 break;
1674 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1675 ar = (AsyncResult) msg.obj;
1676 request = (MainThreadRequest) ar.userObj;
1677 if (ar.exception == null) {
1678 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001679 // If the operation is successful, update the PIN storage
1680 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1681 int phoneId = getPhoneFromRequest(request).getPhoneId();
1682 UiccController.getInstance().getPinStorage()
1683 .storePin(passwords.second, phoneId);
zoey chenf95ca592019-12-30 16:11:23 +08001684 } else {
1685 request.result = msg.arg1;
1686 }
1687 notifyRequester(request);
1688 break;
1689
Michele Berionned9fbae52020-11-13 02:36:59 +00001690 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001691 request = (MainThreadRequest) msg.obj;
1692 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1693 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1694 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1695 enabled.first, enabled.second, onCompleted);
1696 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001697 }
zoey chenf95ca592019-12-30 16:11:23 +08001698 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1699 ar = (AsyncResult) msg.obj;
1700 request = (MainThreadRequest) ar.userObj;
1701 if (ar.exception == null) {
1702 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001703 // If the operation is successful, update the PIN storage
1704 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1705 int phoneId = getPhoneFromRequest(request).getPhoneId();
1706 if (enabled.first) {
1707 UiccController.getInstance().getPinStorage()
1708 .storePin(enabled.second, phoneId);
1709 } else {
1710 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1711 }
zoey chenf95ca592019-12-30 16:11:23 +08001712 } else {
1713 request.result = msg.arg1;
1714 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001715
1716
zoey chenf95ca592019-12-30 16:11:23 +08001717 notifyRequester(request);
1718 break;
1719
Peter Wangdafb9ac2020-01-15 14:13:38 -08001720 case MSG_NOTIFY_USER_ACTIVITY:
1721 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001722 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001723 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1724 getDefaultPhone().getContext().sendBroadcastAsUser(
1725 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1726 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001727
1728 case CMD_SET_DATA_THROTTLING: {
1729 request = (MainThreadRequest) msg.obj;
1730 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1731 DataThrottlingRequest dataThrottlingRequest =
1732 (DataThrottlingRequest) request.argument;
1733 Phone phone = getPhoneFromRequest(request);
1734 if (phone != null) {
1735 phone.setDataThrottling(onCompleted,
1736 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1737 dataThrottlingRequest.getCompletionDurationMillis());
1738 } else {
1739 loge("setDataThrottling: No phone object");
1740 request.result =
1741 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1742 notifyRequester(request);
1743 }
1744
1745 break;
1746 }
1747 case EVENT_SET_DATA_THROTTLING_DONE:
1748 ar = (AsyncResult) msg.obj;
1749 request = (MainThreadRequest) ar.userObj;
1750
1751 if (ar.exception == null) {
1752 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1753 } else if (ar.exception instanceof CommandException) {
1754 loge("setDataThrottling: CommandException: " + ar.exception);
1755 CommandException.Error error =
1756 ((CommandException) (ar.exception)).getCommandError();
1757
1758 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1759 request.result = TelephonyManager
1760 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1761 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1762 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1763 } else {
1764 request.result =
1765 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1766 }
1767 } else {
1768 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1769 }
1770 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1771 notifyRequester(request);
1772 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001773
1774 case CMD_SET_SIM_POWER: {
1775 request = (MainThreadRequest) msg.obj;
1776 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1777 request = (MainThreadRequest) msg.obj;
1778 int stateToSet =
1779 ((Pair<Integer, IIntegerConsumer>)
1780 request.argument).first;
1781 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1782 break;
1783 }
1784 case EVENT_SET_SIM_POWER_DONE: {
1785 ar = (AsyncResult) msg.obj;
1786 request = (MainThreadRequest) ar.userObj;
1787 IIntegerConsumer callback =
1788 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1789 if (ar.exception != null) {
1790 loge("setSimPower exception: " + ar.exception);
1791 int errorCode = TelephonyManager.CallForwardingInfoCallback
1792 .RESULT_ERROR_UNKNOWN;
1793 if (ar.exception instanceof CommandException) {
1794 CommandException.Error error =
1795 ((CommandException) (ar.exception)).getCommandError();
1796 if (error == CommandException.Error.SIM_ERR) {
1797 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1798 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1799 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1800 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1801 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1802 } else {
1803 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1804 }
1805 }
1806 try {
1807 callback.accept(errorCode);
1808 } catch (RemoteException e) {
1809 // Ignore if the remote process is no longer available to call back.
1810 Log.w(LOG_TAG, "setSimPower: callback not available.");
1811 }
1812 } else {
1813 try {
1814 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1815 } catch (RemoteException e) {
1816 // Ignore if the remote process is no longer available to call back.
1817 Log.w(LOG_TAG, "setSimPower: callback not available.");
1818 }
1819 }
1820 break;
1821 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001822 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1823 request = (MainThreadRequest) msg.obj;
1824
1825 final Phone phone = getPhoneFromRequest(request);
1826 if (phone == null || phone.getServiceStateTracker() == null) {
1827 request.result = new IllegalStateException("Phone or SST is null");
1828 notifyRequester(request);
1829 break;
1830 }
1831
1832 Pair<Integer, SignalStrengthUpdateRequest> pair =
1833 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1834 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1835 request);
1836 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1837 request.subId, pair.first /*callingUid*/,
1838 pair.second /*request*/, onCompleted);
1839 break;
1840 }
1841 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1842 ar = (AsyncResult) msg.obj;
1843 request = (MainThreadRequest) ar.userObj;
1844 // request.result will be the exception of ar if present, true otherwise.
1845 // Be cautious not to leave result null which will wait() forever
1846 request.result = ar.exception != null ? ar.exception : true;
1847 notifyRequester(request);
1848 break;
1849 }
1850 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1851 request = (MainThreadRequest) msg.obj;
1852
1853 Phone phone = getPhoneFromRequest(request);
1854 if (phone == null || phone.getServiceStateTracker() == null) {
1855 request.result = new IllegalStateException("Phone or SST is null");
1856 notifyRequester(request);
1857 break;
1858 }
1859
1860 Pair<Integer, SignalStrengthUpdateRequest> pair =
1861 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1862 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1863 request);
1864 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1865 request.subId, pair.first /*callingUid*/,
1866 pair.second /*request*/, onCompleted);
1867 break;
1868 }
1869 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1870 ar = (AsyncResult) msg.obj;
1871 request = (MainThreadRequest) ar.userObj;
1872 request.result = ar.exception != null ? ar.exception : true;
1873 notifyRequester(request);
1874 break;
1875 }
Jordan Liud5366d92020-11-24 14:50:34 -08001876
Michele Berionned9fbae52020-11-13 02:36:59 +00001877 case CMD_PREPARE_UNATTENDED_REBOOT:
1878 request = (MainThreadRequest) msg.obj;
1879 request.result =
1880 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1881 notifyRequester(request);
1882 break;
1883
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 default:
1885 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1886 break;
1887 }
1888 }
Jake Hambye994d462014-02-03 13:10:13 -08001889
Pengquan Menga1bb6272018-09-06 09:59:22 -07001890 private void notifyRequester(MainThreadRequest request) {
1891 synchronized (request) {
1892 request.notifyAll();
1893 }
1894 }
1895
Jake Hambye994d462014-02-03 13:10:13 -08001896 private void handleNullReturnEvent(Message msg, String command) {
1897 AsyncResult ar = (AsyncResult) msg.obj;
1898 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1899 if (ar.exception == null) {
1900 request.result = true;
1901 } else {
1902 request.result = false;
1903 if (ar.exception instanceof CommandException) {
1904 loge(command + ": CommandException: " + ar.exception);
1905 } else {
1906 loge(command + ": Unknown exception");
1907 }
1908 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001909 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001910 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001911 }
1912
1913 /**
1914 * Posts the specified command to be executed on the main thread,
1915 * waits for the request to complete, and returns the result.
1916 * @see #sendRequestAsync
1917 */
1918 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001919 return sendRequest(
1920 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001921 }
1922
1923 /**
1924 * Posts the specified command to be executed on the main thread,
1925 * waits for the request to complete, and returns the result.
1926 * @see #sendRequestAsync
1927 */
1928 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1929 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001930 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001931 }
1932
1933 /**
1934 * Posts the specified command to be executed on the main thread,
1935 * waits for the request to complete, and returns the result.
1936 * @see #sendRequestAsync
1937 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001938 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001939 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001940 }
1941
1942 /**
1943 * Posts the specified command to be executed on the main thread,
1944 * waits for the request to complete, and returns the result.
1945 * @see #sendRequestAsync
1946 */
Nathan Harold92bed182018-10-12 18:16:49 -07001947 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1948 return sendRequest(command, argument, subId, null, workSource);
1949 }
1950
1951 /**
1952 * Posts the specified command to be executed on the main thread,
1953 * waits for the request to complete, and returns the result.
1954 * @see #sendRequestAsync
1955 */
1956 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1957 return sendRequest(
1958 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1959 }
1960
1961 /**
1962 * Posts the specified command to be executed on the main thread,
1963 * waits for the request to complete, and returns the result.
1964 * @see #sendRequestAsync
1965 */
1966 private Object sendRequest(
1967 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1969 throw new RuntimeException("This method will deadlock if called from the main thread.");
1970 }
1971
Nathan Harold92bed182018-10-12 18:16:49 -07001972 MainThreadRequest request = null;
1973 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1974 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1975 } else if (phone != null) {
1976 request = new MainThreadRequest(argument, phone, workSource);
1977 } else {
1978 request = new MainThreadRequest(argument, subId, workSource);
1979 }
1980
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001981 Message msg = mMainThreadHandler.obtainMessage(command, request);
1982 msg.sendToTarget();
1983
1984 // Wait for the request to complete
1985 synchronized (request) {
1986 while (request.result == null) {
1987 try {
1988 request.wait();
1989 } catch (InterruptedException e) {
1990 // Do nothing, go back and wait until the request is complete
1991 }
1992 }
1993 }
1994 return request.result;
1995 }
1996
1997 /**
1998 * Asynchronous ("fire and forget") version of sendRequest():
1999 * Posts the specified command to be executed on the main thread, and
2000 * returns immediately.
2001 * @see #sendRequest
2002 */
2003 private void sendRequestAsync(int command) {
2004 mMainThreadHandler.sendEmptyMessage(command);
2005 }
2006
2007 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002008 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002009 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002010 */
2011 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002012 sendRequestAsync(command, argument, null, null);
2013 }
2014
2015 /**
2016 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2017 * @see {@link #sendRequest(int,Object)}
2018 */
2019 private void sendRequestAsync(
2020 int command, Object argument, Phone phone, WorkSource workSource) {
2021 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002022 Message msg = mMainThreadHandler.obtainMessage(command, request);
2023 msg.sendToTarget();
2024 }
2025
2026 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002027 * Initialize the singleton PhoneInterfaceManager instance.
2028 * This is only done once, at startup, from PhoneApp.onCreate().
2029 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002030 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 synchronized (PhoneInterfaceManager.class) {
2032 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002033 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002034 } else {
2035 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2036 }
2037 return sInstance;
2038 }
2039 }
2040
2041 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002042 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002043 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002044 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08002045 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002046 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2048 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002049 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002050 mTelephonySharedPreferences =
2051 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002052 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002053 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002054 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002055
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002056 publish();
2057 }
2058
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002059 private Phone getDefaultPhone() {
2060 Phone thePhone = getPhone(getDefaultSubscription());
2061 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2062 }
2063
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002064 private void publish() {
2065 if (DBG) log("publish: " + this);
2066
Peter Wangc035ce42020-01-08 21:00:22 -08002067 TelephonyFrameworkInitializer
2068 .getTelephonyServiceManager()
2069 .getTelephonyServiceRegisterer()
2070 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002071 }
2072
Stuart Scott584921c2015-01-15 17:10:34 -08002073 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002074 if (request.phone != null) {
2075 return request.phone;
2076 } else {
2077 return getPhoneFromSubId(request.subId);
2078 }
2079 }
2080
2081 private Phone getPhoneFromSubId(int subId) {
2082 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2083 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002084 }
2085
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002086 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2087 Phone phone = getPhoneFromRequest(request);
2088 return phone == null ? null :
2089 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2090 }
2091
Wink Saville36469e72014-06-11 15:17:00 -07002092 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002093 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002094 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002095 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002096
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002097 private void sendEraseModemConfig(Phone phone) {
2098 if (phone != null) {
2099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2100 mApp, phone.getSubId(), "eraseModemConfig");
2101 final long identity = Binder.clearCallingIdentity();
2102 try {
2103 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2104 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2105 } finally {
2106 Binder.restoreCallingIdentity(identity);
2107 }
2108 }
2109 }
2110
Peter Wang050bb052020-01-13 23:33:09 -08002111 private boolean isImsAvailableOnDevice() {
2112 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2113 if (pm == null) {
2114 // For some reason package manger is not available.. This will fail internally anyway,
2115 // so do not throw error and allow.
2116 return true;
2117 }
2118 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2119 }
2120
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002121 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002122 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002123 }
2124
Wink Savilleb564aae2014-10-23 10:18:09 -07002125 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002126 if (DBG) log("dial: " + number);
2127 // No permission check needed here: This is just a wrapper around the
2128 // ACTION_DIAL intent, which is available to any app since it puts up
2129 // the UI before it does anything.
2130
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002131 final long identity = Binder.clearCallingIdentity();
2132 try {
2133 String url = createTelUrl(number);
2134 if (url == null) {
2135 return;
2136 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002137
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002138 // PENDING: should we just silently fail if phone is offhook or ringing?
2139 PhoneConstants.State state = mCM.getState(subId);
2140 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2141 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2142 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2143 mApp.startActivity(intent);
2144 }
2145 } finally {
2146 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 }
2148 }
2149
2150 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002151 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002152 }
2153
Wink Savilleb564aae2014-10-23 10:18:09 -07002154 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155 if (DBG) log("call: " + number);
2156
2157 // This is just a wrapper around the ACTION_CALL intent, but we still
2158 // need to do a permission check since we're calling startActivity()
2159 // from the context of the phone app.
2160 enforceCallPermission();
2161
Jordan Liu1617b712019-07-10 15:06:26 -07002162 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002163 != AppOpsManager.MODE_ALLOWED) {
2164 return;
2165 }
2166
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002167 final long identity = Binder.clearCallingIdentity();
2168 try {
2169 String url = createTelUrl(number);
2170 if (url == null) {
2171 return;
2172 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002174 boolean isValid = false;
2175 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2176 if (slist != null) {
2177 for (SubscriptionInfo subInfoRecord : slist) {
2178 if (subInfoRecord.getSubscriptionId() == subId) {
2179 isValid = true;
2180 break;
2181 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002182 }
Wink Saville08874612014-08-31 19:19:58 -07002183 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002184 if (!isValid) {
2185 return;
2186 }
Wink Saville08874612014-08-31 19:19:58 -07002187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002188 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2189 intent.putExtra(SUBSCRIPTION_KEY, subId);
2190 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2191 mApp.startActivity(intent);
2192 } finally {
2193 Binder.restoreCallingIdentity(identity);
2194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 }
2196
Wink Savilleb564aae2014-10-23 10:18:09 -07002197 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002198 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002199 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2200 }
2201
Wink Savilleb564aae2014-10-23 10:18:09 -07002202 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002203 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002204 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2205 }
2206
Wink Savilleb564aae2014-10-23 10:18:09 -07002207 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002208 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002209
2210 final long identity = Binder.clearCallingIdentity();
2211 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002212 Phone phone = getPhone(subId);
2213 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002214 checkSimPin.start();
2215 return checkSimPin.unlockSim(null, pin);
2216 } finally {
2217 Binder.restoreCallingIdentity(identity);
2218 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 }
2220
Wink Savilleb564aae2014-10-23 10:18:09 -07002221 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002222 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002223
2224 final long identity = Binder.clearCallingIdentity();
2225 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002226 Phone phone = getPhone(subId);
2227 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002228 checkSimPuk.start();
2229 return checkSimPuk.unlockSim(puk, pin);
2230 } finally {
2231 Binder.restoreCallingIdentity(identity);
2232 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002233 }
2234
2235 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002236 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 * a synchronous one.
2238 */
2239 private static class UnlockSim extends Thread {
2240
2241 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002242 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002243
2244 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002245 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2246 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247
2248 // For replies from SimCard interface
2249 private Handler mHandler;
2250
2251 // For async handler to identify request type
2252 private static final int SUPPLY_PIN_COMPLETE = 100;
2253
Michele Berionned9fbae52020-11-13 02:36:59 +00002254 UnlockSim(int phoneId, IccCard simCard) {
2255 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 mSimCard = simCard;
2257 }
2258
2259 @Override
2260 public void run() {
2261 Looper.prepare();
2262 synchronized (UnlockSim.this) {
2263 mHandler = new Handler() {
2264 @Override
2265 public void handleMessage(Message msg) {
2266 AsyncResult ar = (AsyncResult) msg.obj;
2267 switch (msg.what) {
2268 case SUPPLY_PIN_COMPLETE:
2269 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2270 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002271 mRetryCount = msg.arg1;
2272 if (ar.exception != null) {
2273 if (ar.exception instanceof CommandException &&
2274 ((CommandException)(ar.exception)).getCommandError()
2275 == CommandException.Error.PASSWORD_INCORRECT) {
2276 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002277 } //When UiccCardApp dispose,handle message and return exception
2278 else if (ar.exception instanceof CommandException &&
2279 ((CommandException) (ar.exception)).getCommandError()
2280 == CommandException.Error.ABORTED) {
2281 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002282 } else {
2283 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2284 }
2285 } else {
2286 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 mDone = true;
2289 UnlockSim.this.notifyAll();
2290 }
2291 break;
2292 }
2293 }
2294 };
2295 UnlockSim.this.notifyAll();
2296 }
2297 Looper.loop();
2298 }
2299
2300 /*
2301 * Use PIN or PUK to unlock SIM card
2302 *
2303 * If PUK is null, unlock SIM card with PIN
2304 *
2305 * If PUK is not null, unlock SIM card with PUK and set PIN code
2306 */
Wink Saville9de0f752013-10-22 19:04:03 -07002307 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308
2309 while (mHandler == null) {
2310 try {
2311 wait();
2312 } catch (InterruptedException e) {
2313 Thread.currentThread().interrupt();
2314 }
2315 }
2316 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2317
2318 if (puk == null) {
2319 mSimCard.supplyPin(pin, callback);
2320 } else {
2321 mSimCard.supplyPuk(puk, pin, callback);
2322 }
2323
2324 while (!mDone) {
2325 try {
2326 Log.d(LOG_TAG, "wait for done");
2327 wait();
2328 } catch (InterruptedException e) {
2329 // Restore the interrupted status
2330 Thread.currentThread().interrupt();
2331 }
2332 }
2333 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002334 int[] resultArray = new int[2];
2335 resultArray[0] = mResult;
2336 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002337
2338 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2339 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2340 }
2341
Wink Saville9de0f752013-10-22 19:04:03 -07002342 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 }
2344 }
2345
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002346 /**
2347 * This method has been removed due to privacy and stability concerns.
2348 */
2349 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002351 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2352 return;
Wink Saville36469e72014-06-11 15:17:00 -07002353 }
2354
Nathan Harold1f889d82020-06-04 17:05:26 -07002355 @Override
2356 public void updateServiceLocationWithPackageName(String callingPackage) {
2357 mApp.getSystemService(AppOpsManager.class)
2358 .checkPackage(Binder.getCallingUid(), callingPackage);
2359
Nathan Haroldf096d982020-11-18 17:18:06 -08002360 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002361 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2362 // Callers targeting S have no business invoking this method.
2363 return;
2364 }
2365
2366 LocationAccessPolicy.LocationPermissionResult locationResult =
2367 LocationAccessPolicy.checkLocationPermission(mApp,
2368 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2369 .setCallingPackage(callingPackage)
2370 .setCallingFeatureId(null)
2371 .setCallingPid(Binder.getCallingPid())
2372 .setCallingUid(Binder.getCallingUid())
2373 .setMethod("updateServiceLocation")
2374 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2375 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2376 .build());
2377 // Apps that lack location permission have no business calling this method;
2378 // however, because no permission was declared in the public API, denials must
2379 // all be "soft".
2380 switch (locationResult) {
2381 case DENIED_HARD: /* fall through */
2382 case DENIED_SOFT:
2383 return;
2384 }
2385
2386 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002387 final long identity = Binder.clearCallingIdentity();
2388 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002389 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002390 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002391 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002392 }
2393 } finally {
2394 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002395 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 }
2397
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002398 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002399 @Override
2400 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002401 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002402 }
2403
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002404
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002405 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002406 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2407 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2408 callingFeatureId);
2409 }
2410
2411 @Deprecated
2412 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002413 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002414 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2415 }
2416
2417 @Override
2418 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2419 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002420 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002421 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002422 return false;
2423 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002424
2425 final long identity = Binder.clearCallingIdentity();
2426 try {
2427 return isRadioOnForSubscriber(subId);
2428 } finally {
2429 Binder.restoreCallingIdentity(identity);
2430 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002431 }
2432
2433 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002434 final long identity = Binder.clearCallingIdentity();
2435 try {
2436 final Phone phone = getPhone(subId);
2437 if (phone != null) {
2438 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2439 } else {
2440 return false;
2441 }
2442 } finally {
2443 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 }
2446
2447 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002448 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 }
Wink Saville36469e72014-06-11 15:17:00 -07002450
Wink Savilleb564aae2014-10-23 10:18:09 -07002451 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002453
2454 final long identity = Binder.clearCallingIdentity();
2455 try {
2456 final Phone phone = getPhone(subId);
2457 if (phone != null) {
2458 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2459 }
2460 } finally {
2461 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002462 }
Wink Saville36469e72014-06-11 15:17:00 -07002463 }
2464
2465 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002466 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002467 }
2468
Wink Savilleb564aae2014-10-23 10:18:09 -07002469 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002470 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002471
2472 final long identity = Binder.clearCallingIdentity();
2473 try {
2474 final Phone phone = getPhone(subId);
2475 if (phone == null) {
2476 return false;
2477 }
2478 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2479 toggleRadioOnOffForSubscriber(subId);
2480 }
2481 return true;
2482 } finally {
2483 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
Wink Saville36469e72014-06-11 15:17:00 -07002486
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002487 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002488 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002489 /*
2490 * If any of the Radios are available, it will need to be
2491 * shutdown. So return true if any Radio is available.
2492 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002493 final long identity = Binder.clearCallingIdentity();
2494 try {
2495 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2496 Phone phone = PhoneFactory.getPhone(i);
2497 if (phone != null && phone.isRadioAvailable()) return true;
2498 }
2499 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2500 return false;
2501 } finally {
2502 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002503 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002504 }
2505
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002507 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508 enforceModifyPermission();
2509
2510 final long identity = Binder.clearCallingIdentity();
2511 try {
2512 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2513 logv("Shutting down Phone " + i);
2514 shutdownRadioUsingPhoneId(i);
2515 }
2516 } finally {
2517 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002518 }
2519 }
2520
2521 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002522 Phone phone = PhoneFactory.getPhone(phoneId);
2523 if (phone != null && phone.isRadioAvailable()) {
2524 phone.shutdownRadio();
2525 }
2526 }
2527
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002529 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002530
2531 final long identity = Binder.clearCallingIdentity();
2532 try {
2533 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2534 if (defaultPhone != null) {
2535 defaultPhone.setRadioPower(turnOn);
2536 return true;
2537 } else {
2538 loge("There's no default phone.");
2539 return false;
2540 }
2541 } finally {
2542 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002543 }
Wink Saville36469e72014-06-11 15:17:00 -07002544 }
2545
Wink Savilleb564aae2014-10-23 10:18:09 -07002546 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002547 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002548
2549 final long identity = Binder.clearCallingIdentity();
2550 try {
2551 final Phone phone = getPhone(subId);
2552 if (phone != null) {
2553 phone.setRadioPower(turnOn);
2554 return true;
2555 } else {
2556 return false;
2557 }
2558 } finally {
2559 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002560 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002561 }
2562
Wink Saville36469e72014-06-11 15:17:00 -07002563 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002564 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002565 public boolean enableDataConnectivity() {
2566 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002567
2568 final long identity = Binder.clearCallingIdentity();
2569 try {
2570 int subId = mSubscriptionController.getDefaultDataSubId();
2571 final Phone phone = getPhone(subId);
2572 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002573 phone.getDataEnabledSettings().setDataEnabled(
2574 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002575 return true;
2576 } else {
2577 return false;
2578 }
2579 } finally {
2580 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 }
2583
Wink Saville36469e72014-06-11 15:17:00 -07002584 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002585 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586 public boolean disableDataConnectivity() {
2587 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002588
2589 final long identity = Binder.clearCallingIdentity();
2590 try {
2591 int subId = mSubscriptionController.getDefaultDataSubId();
2592 final Phone phone = getPhone(subId);
2593 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002594 phone.getDataEnabledSettings().setDataEnabled(
2595 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002596 return true;
2597 } else {
2598 return false;
2599 }
2600 } finally {
2601 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603 }
2604
Sanket Padawe356d7632015-06-22 14:03:32 -07002605 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002606 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607 final long identity = Binder.clearCallingIdentity();
2608 try {
2609 final Phone phone = getPhone(subId);
2610 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002611 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 } else {
2613 return false;
2614 }
2615 } finally {
2616 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002617 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618 }
2619
2620 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002621 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002622 }
2623
pkanwarae03a6b2016-11-06 20:37:09 -08002624 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625 enforceCallPermission();
2626
2627 final long identity = Binder.clearCallingIdentity();
2628 try {
2629 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2630 return;
2631 }
2632 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2633 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2634 } finally {
2635 Binder.restoreCallingIdentity(identity);
2636 }
pkanwar32d516d2016-10-14 19:37:38 -07002637 };
2638
Wink Savilleb564aae2014-10-23 10:18:09 -07002639 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002640 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641
2642 final long identity = Binder.clearCallingIdentity();
2643 try {
2644 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2645 return false;
2646 }
2647 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2648 } finally {
2649 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002650 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002651 }
2652
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002654 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002655 }
2656
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002657 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002658 final long identity = Binder.clearCallingIdentity();
2659 try {
2660 Phone phone = PhoneFactory.getPhone(slotIndex);
2661 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2662 PhoneConstantConversions.convertCallState(phone.getState());
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
2665 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 }
2667
Sanket Padawe356d7632015-06-22 14:03:32 -07002668 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002669 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002670 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2671 }
2672
2673 @Override
2674 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002675 final long identity = Binder.clearCallingIdentity();
2676 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002677 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002678 if (phone != null) {
2679 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2680 } else {
2681 return PhoneConstantConversions.convertDataState(
2682 PhoneConstants.DataState.DISCONNECTED);
2683 }
2684 } finally {
2685 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002686 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002687 }
2688
Sanket Padawe356d7632015-06-22 14:03:32 -07002689 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002690 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002691 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2692 }
2693
2694 @Override
2695 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696 final long identity = Binder.clearCallingIdentity();
2697 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002698 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002699 if (phone != null) {
2700 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2701 } else {
2702 return TelephonyManager.DATA_ACTIVITY_NONE;
2703 }
2704 } finally {
2705 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 }
2708
2709 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002710 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002711 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002712 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002713
2714 LocationAccessPolicy.LocationPermissionResult locationResult =
2715 LocationAccessPolicy.checkLocationPermission(mApp,
2716 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2717 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002718 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002719 .setCallingPid(Binder.getCallingPid())
2720 .setCallingUid(Binder.getCallingUid())
2721 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002722 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002723 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2724 .build());
2725 switch (locationResult) {
2726 case DENIED_HARD:
2727 throw new SecurityException("Not allowed to access cell location");
2728 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002729 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2730 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002731 }
2732
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002733 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734 final long identity = Binder.clearCallingIdentity();
2735 try {
2736 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002737 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002738 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 } finally {
2740 Binder.restoreCallingIdentity(identity);
2741 }
Svetoslav64fad262015-04-14 14:35:21 -07002742 }
2743
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002744 @Override
Jack Yu01425032020-02-22 19:38:58 -08002745 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002746 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2747 // registered cell info, so return a NULL country instead.
2748 final long identity = Binder.clearCallingIdentity();
2749 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002750 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2751 // Get default phone in this case.
2752 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2753 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002754 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002755 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002756 if (phone == null) return "";
2757 ServiceStateTracker sst = phone.getServiceStateTracker();
2758 if (sst == null) return "";
2759 LocaleTracker lt = sst.getLocaleTracker();
2760 if (lt == null) return "";
2761 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2762 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2763 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002764 } finally {
2765 Binder.restoreCallingIdentity(identity);
2766 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002767 }
2768
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002769 /**
2770 * This method was removed due to potential issues caused by performing partial
2771 * updates of service state, and lack of a credible use case.
2772 *
2773 * This has the ability to break the telephony implementation by disabling notification of
2774 * changes in device connectivity. DO NOT USE THIS!
2775 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002776 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 public void enableLocationUpdates() {
2778 mApp.enforceCallingOrSelfPermission(
2779 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 }
2781
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002782 /**
2783 * This method was removed due to potential issues caused by performing partial
2784 * updates of service state, and lack of a credible use case.
2785 *
2786 * This has the ability to break the telephony implementation by disabling notification of
2787 * changes in device connectivity. DO NOT USE THIS!
2788 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002789 @Override
2790 public void disableLocationUpdates() {
2791 mApp.enforceCallingOrSelfPermission(
2792 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002793 }
2794
2795 @Override
2796 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002797 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2798 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002799 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002800 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2801 throw new SecurityException(
2802 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2803 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002804
Jordan Liu1617b712019-07-10 15:06:26 -07002805 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002806 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2807 return null;
2808 }
Svetoslav64fad262015-04-14 14:35:21 -07002809
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002810 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002811
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002812 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002813 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002814
Nathan Haroldf180aac2018-06-01 18:43:55 -07002815 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2816 for (CellInfo ci : info) {
2817 if (ci instanceof CellInfoGsm) {
2818 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2819 } else if (ci instanceof CellInfoWcdma) {
2820 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2821 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002822 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002823 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002824 }
2825
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002826 private List<CellInfo> getCachedCellInfo() {
2827 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2828 for (Phone phone : PhoneFactory.getPhones()) {
2829 List<CellInfo> info = phone.getAllCellInfo();
2830 if (info != null) cellInfos.addAll(info);
2831 }
2832 return cellInfos;
2833 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002834
2835 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002836 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002837 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002838 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002839
2840 LocationAccessPolicy.LocationPermissionResult locationResult =
2841 LocationAccessPolicy.checkLocationPermission(mApp,
2842 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2843 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002844 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002845 .setCallingPid(Binder.getCallingPid())
2846 .setCallingUid(Binder.getCallingUid())
2847 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002848 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002849 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2850 .build());
2851 switch (locationResult) {
2852 case DENIED_HARD:
2853 throw new SecurityException("Not allowed to access cell info");
2854 case DENIED_SOFT:
2855 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002856 }
2857
Nathan Haroldf096d982020-11-18 17:18:06 -08002858 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002859 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2860 return getCachedCellInfo();
2861 }
2862
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002863 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002864 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865 final long identity = Binder.clearCallingIdentity();
2866 try {
2867 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2868 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002869 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002870 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002871 if (info != null) cellInfos.addAll(info);
2872 }
2873 return cellInfos;
2874 } finally {
2875 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002876 }
2877 }
2878
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002879 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002880 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2881 String callingFeatureId) {
2882 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2883 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002884 }
2885
2886 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002887 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2888 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002889 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002890 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002891 }
2892
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002893 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2894 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002895 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002896 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002897
2898 LocationAccessPolicy.LocationPermissionResult locationResult =
2899 LocationAccessPolicy.checkLocationPermission(mApp,
2900 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2901 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002902 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002903 .setCallingPid(Binder.getCallingPid())
2904 .setCallingUid(Binder.getCallingUid())
2905 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002906 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2907 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002908 .build());
2909 switch (locationResult) {
2910 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002911 if (TelephonyPermissions
2912 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002913 // Safetynet logging for b/154934934
2914 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2915 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002916 throw new SecurityException("Not allowed to access cell info");
2917 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002918 if (TelephonyPermissions
2919 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002920 // Safetynet logging for b/154934934
2921 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2922 }
Nathan Harold5320c422019-05-09 10:26:08 -07002923 try {
2924 cb.onCellInfo(new ArrayList<CellInfo>());
2925 } catch (RemoteException re) {
2926 // Drop without consequences
2927 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002928 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002929 }
2930
Nathan Harolda939a962019-05-09 10:13:47 -07002931
2932 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002933 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2934
2935 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2936 }
2937
2938 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002939 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002940 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002941 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002942
2943 final long identity = Binder.clearCallingIdentity();
2944 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002945 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002946 } finally {
2947 Binder.restoreCallingIdentity(identity);
2948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002949 }
2950
Shishir Agrawala9f32182016-04-12 12:00:16 -07002951 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002952 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002953 Phone phone = PhoneFactory.getPhone(slotIndex);
2954 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002955 return null;
2956 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002957 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002958 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002959 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002960 return null;
2961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002962
2963 final long identity = Binder.clearCallingIdentity();
2964 try {
2965 return phone.getImei();
2966 } finally {
2967 Binder.restoreCallingIdentity(identity);
2968 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002969 }
2970
2971 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002972 public String getTypeAllocationCodeForSlot(int slotIndex) {
2973 Phone phone = PhoneFactory.getPhone(slotIndex);
2974 String tac = null;
2975 if (phone != null) {
2976 String imei = phone.getImei();
2977 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2978 }
2979 return tac;
2980 }
2981
2982 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002983 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002984 Phone phone = PhoneFactory.getPhone(slotIndex);
2985 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002986 return null;
2987 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002988
Jeff Davidson913390f2018-02-23 17:11:49 -08002989 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002990 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002991 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002992 return null;
2993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002994
2995 final long identity = Binder.clearCallingIdentity();
2996 try {
2997 return phone.getMeid();
2998 } finally {
2999 Binder.restoreCallingIdentity(identity);
3000 }
Jack Yu2af8d712017-03-15 17:14:14 -07003001 }
3002
3003 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003004 public String getManufacturerCodeForSlot(int slotIndex) {
3005 Phone phone = PhoneFactory.getPhone(slotIndex);
3006 String manufacturerCode = null;
3007 if (phone != null) {
3008 String meid = phone.getMeid();
3009 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3010 }
3011 return manufacturerCode;
3012 }
3013
3014 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003015 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3016 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003017 Phone phone = PhoneFactory.getPhone(slotIndex);
3018 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003019 return null;
3020 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003021 int subId = phone.getSubId();
3022 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003023 mApp, subId, callingPackage, callingFeatureId,
3024 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003025 return null;
3026 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003027
3028 final long identity = Binder.clearCallingIdentity();
3029 try {
3030 return phone.getDeviceSvn();
3031 } finally {
3032 Binder.restoreCallingIdentity(identity);
3033 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003034 }
3035
fionaxu43304da2017-11-27 22:51:16 -08003036 @Override
3037 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003038 final long identity = Binder.clearCallingIdentity();
3039 try {
3040 final Phone phone = getPhone(subId);
3041 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3042 } finally {
3043 Binder.restoreCallingIdentity(identity);
3044 }
fionaxu43304da2017-11-27 22:51:16 -08003045 }
3046
3047 @Override
3048 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 final Phone phone = getPhone(subId);
3052 return phone == null ? null : phone.getCarrierName();
3053 } finally {
3054 Binder.restoreCallingIdentity(identity);
3055 }
fionaxu43304da2017-11-27 22:51:16 -08003056 }
3057
calvinpanffe225e2018-11-01 19:43:06 +08003058 @Override
chen xu0026ca62019-03-06 15:28:50 -08003059 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 final Phone phone = getPhone(subId);
3063 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003064 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
3068 }
3069
3070 @Override
chen xu0026ca62019-03-06 15:28:50 -08003071 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003072 final long identity = Binder.clearCallingIdentity();
3073 try {
3074 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003075 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003076 } finally {
3077 Binder.restoreCallingIdentity(identity);
3078 }
3079 }
3080
chen xu651eec72018-11-11 19:03:44 -08003081 @Override
chen xu864e11c2018-12-06 22:10:03 -08003082 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3083 if (!isSubscriptionMccMnc) {
3084 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3085 }
chen xu651eec72018-11-11 19:03:44 -08003086 final Phone phone = PhoneFactory.getPhone(slotIndex);
3087 if (phone == null) {
3088 return TelephonyManager.UNKNOWN_CARRIER_ID;
3089 }
3090 final long identity = Binder.clearCallingIdentity();
3091 try {
3092 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3093 } finally {
3094 Binder.restoreCallingIdentity(identity);
3095 }
3096 }
3097
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003098 //
3099 // Internal helper methods.
3100 //
3101
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003102 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003103 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3104 *
3105 * @throws SecurityException if the caller does not have the required permission
3106 */
3107 private void enforceModifyPermission() {
3108 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3109 }
3110
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003111 /**
3112 * Make sure the caller is system.
3113 *
3114 * @throws SecurityException if the caller is not system.
3115 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003116 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003117 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3118 throw new SecurityException("Caller must be system");
3119 }
3120 }
3121
Shuo Qianf2b2df42019-11-13 17:43:31 -08003122 private void enforceActiveEmergencySessionPermission() {
3123 mApp.enforceCallingOrSelfPermission(
3124 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3125 }
3126
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003127 /**
3128 * Make sure the caller has the CALL_PHONE permission.
3129 *
3130 * @throws SecurityException if the caller does not have the required permission
3131 */
3132 private void enforceCallPermission() {
3133 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3134 }
3135
paulhu423b5f22019-08-23 19:17:33 +08003136 private void enforceSettingsPermission() {
3137 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003138 }
3139
Michele Berionned9fbae52020-11-13 02:36:59 +00003140 private void enforceRebootPermission() {
3141 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3142 }
3143
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003144 private String createTelUrl(String number) {
3145 if (TextUtils.isEmpty(number)) {
3146 return null;
3147 }
3148
Jake Hambye994d462014-02-03 13:10:13 -08003149 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003150 }
3151
Ihab Awadf9e92732013-12-05 18:02:52 -08003152 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003153 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3154 }
3155
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003156 private static void logv(String msg) {
3157 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3158 }
3159
Ihab Awadf9e92732013-12-05 18:02:52 -08003160 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003161 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3162 }
3163
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003164 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003165 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003166 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003167 }
3168
Sanket Padawe356d7632015-06-22 14:03:32 -07003169 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003170 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003171 final long identity = Binder.clearCallingIdentity();
3172 try {
3173 final Phone phone = PhoneFactory.getPhone(slotIndex);
3174 if (phone == null) {
3175 return PhoneConstants.PHONE_TYPE_NONE;
3176 } else {
3177 return phone.getPhoneType();
3178 }
3179 } finally {
3180 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003182 }
3183
3184 /**
3185 * Returns the CDMA ERI icon index to display
3186 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003187 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003188 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3189 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3190 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003191 }
3192
Sanket Padawe356d7632015-06-22 14:03:32 -07003193 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003194 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3195 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003196 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003197 mApp, subId, callingPackage, callingFeatureId,
3198 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003199 return -1;
3200 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201
3202 final long identity = Binder.clearCallingIdentity();
3203 try {
3204 final Phone phone = getPhone(subId);
3205 if (phone != null) {
3206 return phone.getCdmaEriIconIndex();
3207 } else {
3208 return -1;
3209 }
3210 } finally {
3211 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003212 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003213 }
3214
3215 /**
3216 * Returns the CDMA ERI icon mode,
3217 * 0 - ON
3218 * 1 - FLASHING
3219 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003220 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003221 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3222 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3223 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003224 }
3225
Sanket Padawe356d7632015-06-22 14:03:32 -07003226 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003227 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3228 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003229 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003230 mApp, subId, callingPackage, callingFeatureId,
3231 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003232 return -1;
3233 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003234
3235 final long identity = Binder.clearCallingIdentity();
3236 try {
3237 final Phone phone = getPhone(subId);
3238 if (phone != null) {
3239 return phone.getCdmaEriIconMode();
3240 } else {
3241 return -1;
3242 }
3243 } finally {
3244 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003245 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003246 }
3247
3248 /**
3249 * Returns the CDMA ERI text,
3250 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003251 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003252 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3253 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3254 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003255 }
3256
Sanket Padawe356d7632015-06-22 14:03:32 -07003257 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003258 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3259 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003260 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003261 mApp, subId, callingPackage, callingFeatureId,
3262 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003263 return null;
3264 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003265
3266 final long identity = Binder.clearCallingIdentity();
3267 try {
3268 final Phone phone = getPhone(subId);
3269 if (phone != null) {
3270 return phone.getCdmaEriText();
3271 } else {
3272 return null;
3273 }
3274 } finally {
3275 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003276 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003277 }
3278
3279 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003280 * Returns the CDMA MDN.
3281 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003282 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003283 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003284 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3285 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003286
3287 final long identity = Binder.clearCallingIdentity();
3288 try {
3289 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003290 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003291 return phone.getLine1Number();
3292 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003293 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003294 return null;
3295 }
3296 } finally {
3297 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003298 }
3299 }
3300
3301 /**
3302 * Returns the CDMA MIN.
3303 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003304 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003305 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3307 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003308
3309 final long identity = Binder.clearCallingIdentity();
3310 try {
3311 final Phone phone = getPhone(subId);
3312 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3313 return phone.getCdmaMin();
3314 } else {
3315 return null;
3316 }
3317 } finally {
3318 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003319 }
3320 }
3321
Hall Liud892bec2018-11-30 14:51:45 -08003322 @Override
3323 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3324 INumberVerificationCallback callback, String callingPackage) {
3325 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3326 != PERMISSION_GRANTED) {
3327 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3328 }
3329 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3330
3331 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3332 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003333 throw new SecurityException("Calling package must be configured in the device config: "
3334 + "calling package: " + callingPackage
3335 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003336 }
3337
3338 if (range == null) {
3339 throw new NullPointerException("Range must be non-null");
3340 }
3341
3342 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003343 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003344
3345 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3346 }
3347
Junda Liuca05d5d2014-08-14 22:36:34 -07003348 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003349 * Returns true if CDMA provisioning needs to run.
3350 */
3351 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003352 final long identity = Binder.clearCallingIdentity();
3353 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003354 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003355 } finally {
3356 Binder.restoreCallingIdentity(identity);
3357 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003358 }
3359
3360 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003361 * Sets the voice mail number of a given subId.
3362 */
3363 @Override
3364 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003365 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3366 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367
3368 final long identity = Binder.clearCallingIdentity();
3369 try {
3370 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3371 new Pair<String, String>(alphaTag, number), new Integer(subId));
3372 return success;
3373 } finally {
3374 Binder.restoreCallingIdentity(identity);
3375 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003376 }
3377
Ta-wei Yen87c49842016-05-13 21:19:52 -07003378 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003379 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3380 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003381 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3382 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003383 if (!TextUtils.equals(callingPackage, systemDialer)) {
3384 throw new SecurityException("caller must be system dialer");
3385 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003386
3387 final long identity = Binder.clearCallingIdentity();
3388 try {
3389 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3390 if (phoneAccountHandle == null) {
3391 return null;
3392 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003393 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003394 } finally {
3395 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003396 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003397 }
3398
3399 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003400 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3401 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003402 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003403 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003404 mApp, subId, callingPackage, callingFeatureId,
3405 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003406 return null;
3407 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003408
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003409 final long identity = Binder.clearCallingIdentity();
3410 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003411 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003412 } finally {
3413 Binder.restoreCallingIdentity(identity);
3414 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003415 }
3416
3417 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003418 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3419 VisualVoicemailSmsFilterSettings settings) {
3420 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003421
3422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003425 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003426 } finally {
3427 Binder.restoreCallingIdentity(identity);
3428 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003429 }
3430
3431 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003432 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3433 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003434
3435 final long identity = Binder.clearCallingIdentity();
3436 try {
3437 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003438 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003439 } finally {
3440 Binder.restoreCallingIdentity(identity);
3441 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003442 }
3443
3444 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003445 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3446 String callingPackage, int subId) {
3447 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003448
3449 final long identity = Binder.clearCallingIdentity();
3450 try {
3451 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003452 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003453 } finally {
3454 Binder.restoreCallingIdentity(identity);
3455 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003456 }
3457
3458 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003459 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003460 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003461
3462 final long identity = Binder.clearCallingIdentity();
3463 try {
3464 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003465 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003466 } finally {
3467 Binder.restoreCallingIdentity(identity);
3468 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003469 }
3470
3471 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003472 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3473 String callingAttributionTag, int subId, String number, int port, String text,
3474 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003475 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003476 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003477 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003478 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003479 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3480 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003481 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003482
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003483 /**
fionaxu0152e512016-11-14 13:36:14 -08003484 * Sets the voice activation state of a given subId.
3485 */
3486 @Override
3487 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3489 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003490
3491 final long identity = Binder.clearCallingIdentity();
3492 try {
3493 final Phone phone = getPhone(subId);
3494 if (phone != null) {
3495 phone.setVoiceActivationState(activationState);
3496 } else {
3497 loge("setVoiceActivationState fails with invalid subId: " + subId);
3498 }
3499 } finally {
3500 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003501 }
3502 }
3503
3504 /**
3505 * Sets the data activation state of a given subId.
3506 */
3507 @Override
3508 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003509 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3510 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003511
3512 final long identity = Binder.clearCallingIdentity();
3513 try {
3514 final Phone phone = getPhone(subId);
3515 if (phone != null) {
3516 phone.setDataActivationState(activationState);
3517 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003518 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003519 }
3520 } finally {
3521 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003522 }
3523 }
3524
3525 /**
3526 * Returns the voice activation state of a given subId.
3527 */
3528 @Override
3529 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003530 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003531
fionaxu0152e512016-11-14 13:36:14 -08003532 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003533 final long identity = Binder.clearCallingIdentity();
3534 try {
3535 if (phone != null) {
3536 return phone.getVoiceActivationState();
3537 } else {
3538 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3539 }
3540 } finally {
3541 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003542 }
3543 }
3544
3545 /**
3546 * Returns the data activation state of a given subId.
3547 */
3548 @Override
3549 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003550 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003551
fionaxu0152e512016-11-14 13:36:14 -08003552 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003553 final long identity = Binder.clearCallingIdentity();
3554 try {
3555 if (phone != null) {
3556 return phone.getDataActivationState();
3557 } else {
3558 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3559 }
3560 } finally {
3561 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003562 }
3563 }
3564
3565 /**
Wink Saville36469e72014-06-11 15:17:00 -07003566 * Returns the unread count of voicemails for a subId
3567 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003568 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003569 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3570 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003571 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003572 mApp, subId, callingPackage, callingFeatureId,
3573 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003574 return 0;
3575 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003576 final long identity = Binder.clearCallingIdentity();
3577 try {
3578 final Phone phone = getPhone(subId);
3579 if (phone != null) {
3580 return phone.getVoiceMessageCount();
3581 } else {
3582 return 0;
3583 }
3584 } finally {
3585 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003586 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003587 }
3588
3589 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003590 * returns true, if the device is in a state where both voice and data
3591 * are supported simultaneously. This can change based on location or network condition.
3592 */
3593 @Override
3594 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003595 final long identity = Binder.clearCallingIdentity();
3596 try {
3597 final Phone phone = getPhone(subId);
3598 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3599 } finally {
3600 Binder.restoreCallingIdentity(identity);
3601 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003602 }
3603
3604 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003605 * Send the dialer code if called from the current default dialer or the caller has
3606 * carrier privilege.
3607 * @param inputCode The dialer code to send
3608 */
3609 @Override
3610 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003611 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003612 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003613 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3614 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003615 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003616 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003617 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003618 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003619
3620 final long identity = Binder.clearCallingIdentity();
3621 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003622 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003623 } finally {
3624 Binder.restoreCallingIdentity(identity);
3625 }
fionaxu235cc5e2017-03-06 22:25:57 -08003626 }
3627
Pengquan Menga1bb6272018-09-06 09:59:22 -07003628 @Override
3629 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003630 TelephonyPermissions
3631 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3632 mApp, subId, "getNetworkSelectionMode");
3633 final long identity = Binder.clearCallingIdentity();
3634 try {
3635 if (!isActiveSubscription(subId)) {
3636 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3637 }
3638 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3639 } finally {
3640 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003641 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003642 }
3643
Brad Ebinger35c841c2018-10-01 10:40:55 -07003644 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003645 public boolean isInEmergencySmsMode() {
3646 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3647 final long identity = Binder.clearCallingIdentity();
3648 try {
3649 for (Phone phone : PhoneFactory.getPhones()) {
3650 if (phone.isInEmergencySmsMode()) {
3651 return true;
3652 }
3653 }
3654 } finally {
3655 Binder.restoreCallingIdentity(identity);
3656 }
3657 return false;
3658 }
3659
shilu366312e2019-12-17 09:28:10 -08003660 /**
3661 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3662 * @param subId The subscription to use to check the configuration.
3663 * @param c The callback that will be used to send the result.
3664 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003665 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003666 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3667 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003668 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3669 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003670
Brad Ebinger77b832e2019-10-17 17:03:22 -07003671 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3672 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3673 "IMS not available on device.");
3674 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003675 final long token = Binder.clearCallingIdentity();
3676 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003677 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003678 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003679 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003680 } catch (ImsException e) {
3681 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003682 } finally {
3683 Binder.restoreCallingIdentity(token);
3684 }
3685 }
3686
shilu366312e2019-12-17 09:28:10 -08003687 /**
3688 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3689 * @param subId The subscription to use to check the configuration.
3690 * @param c The callback that will be used to send the result.
3691 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003692 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003693 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003694 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3695 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003696 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3697 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3698 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003699 final long token = Binder.clearCallingIdentity();
3700 try {
3701 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3702 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3703 .removeRegistrationCallbackForSubscription(c, subId);
3704 } catch (ImsException e) {
3705 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3706 + "is inactive, ignoring unregister.");
3707 // If the subscription is no longer active, just return, since the callback
3708 // will already have been removed internally.
3709 } finally {
3710 Binder.restoreCallingIdentity(token);
3711 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003712 }
3713
Brad Ebinger774ba362019-10-22 17:36:18 -07003714 /**
3715 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3716 */
3717 @Override
3718 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3719 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3720 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3721 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3722 "IMS not available on device.");
3723 }
3724 final long token = Binder.clearCallingIdentity();
3725 try {
3726 Phone phone = getPhone(subId);
3727 if (phone == null) {
3728 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3729 + subId + "'");
3730 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3731 }
3732 phone.getImsRegistrationState(regState -> {
3733 try {
3734 consumer.accept((regState == null)
3735 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3736 } catch (RemoteException e) {
3737 // Ignore if the remote process is no longer available to call back.
3738 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3739 }
3740 });
3741 } finally {
3742 Binder.restoreCallingIdentity(token);
3743 }
3744 }
3745
3746 /**
3747 * Get the transport type for the IMS service registration state.
3748 */
3749 @Override
3750 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003751 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3752 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003753 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3754 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3755 "IMS not available on device.");
3756 }
3757 final long token = Binder.clearCallingIdentity();
3758 try {
3759 Phone phone = getPhone(subId);
3760 if (phone == null) {
3761 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3762 + subId + "'");
3763 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3764 }
3765 phone.getImsRegistrationTech(regTech -> {
3766 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3767 int regTechConverted = (regTech == null)
3768 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3769 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3770 regTechConverted);
3771 try {
3772 consumer.accept(regTechConverted);
3773 } catch (RemoteException e) {
3774 // Ignore if the remote process is no longer available to call back.
3775 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3776 }
3777 });
3778 } finally {
3779 Binder.restoreCallingIdentity(token);
3780 }
3781 }
3782
shilu366312e2019-12-17 09:28:10 -08003783 /**
3784 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3785 * @param subId The subscription to use to check the configuration.
3786 * @param c The callback that will be used to send the result.
3787 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003788 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003789 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3790 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003791 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3792 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003793 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3794 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3795 "IMS not available on device.");
3796 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003797 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3798 final long token = Binder.clearCallingIdentity();
3799 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003800 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003801 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003802 } catch (ImsException e) {
3803 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003804 } finally {
3805 Binder.restoreCallingIdentity(token);
3806 }
3807 }
3808
shilu366312e2019-12-17 09:28:10 -08003809 /**
3810 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3811 * @param subId The subscription to use to check the configuration.
3812 * @param c The callback that will be used to send the result.
3813 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003814 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003815 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003816 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3817 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003818 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3819 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3820 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003821
3822 final long token = Binder.clearCallingIdentity();
3823 try {
3824 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3825 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003826 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003827 } catch (ImsException e) {
3828 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3829 + "is inactive, ignoring unregister.");
3830 // If the subscription is no longer active, just return, since the callback
3831 // will already have been removed internally.
3832 } finally {
3833 Binder.restoreCallingIdentity(token);
3834 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003835 }
3836
3837 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003838 public boolean isCapable(int subId, int capability, int regTech) {
3839 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003840 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3841 final long token = Binder.clearCallingIdentity();
3842 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003843 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003844 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003845 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003846 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3847 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003848 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003849 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3850 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003851 } finally {
3852 Binder.restoreCallingIdentity(token);
3853 }
3854 }
3855
3856 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003857 public boolean isAvailable(int subId, int capability, int regTech) {
3858 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003859 final long token = Binder.clearCallingIdentity();
3860 try {
3861 Phone phone = getPhone(subId);
3862 if (phone == null) return false;
3863 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003864 } catch (com.android.ims.ImsException e) {
3865 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3866 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003867 } finally {
3868 Binder.restoreCallingIdentity(token);
3869 }
3870 }
3871
Brad Ebinger77b832e2019-10-17 17:03:22 -07003872 /**
3873 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3874 * subscription.
3875 * @param subId The subscription to use to check the configuration.
3876 * @param callback The callback that will be used to send the result.
3877 * @param capability The MmTelFeature capability that will be used to send the result.
3878 * @param transportType The transport type of the MmTelFeature capability.
3879 */
3880 @Override
3881 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3882 int transportType) {
3883 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3884 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3885 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3886 "IMS not available on device.");
3887 }
3888 final long token = Binder.clearCallingIdentity();
3889 try {
3890 int slotId = getSlotIndex(subId);
3891 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3892 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3893 + subId + "'");
3894 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3895 }
3896 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3897 transportType, aBoolean -> {
3898 try {
3899 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3900 } catch (RemoteException e) {
3901 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3902 + "running. Ignore");
3903 }
3904 });
3905 } finally {
3906 Binder.restoreCallingIdentity(token);
3907 }
3908 }
3909
shilu366312e2019-12-17 09:28:10 -08003910 /**
3911 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3912 * @param subId The subscription to use to check the configuration.
3913 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003914 @Override
3915 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003916 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3917 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003918
Brad Ebinger35c841c2018-10-01 10:40:55 -07003919 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3920 final long token = Binder.clearCallingIdentity();
3921 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003922 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003923 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003924 } catch (ImsException e) {
3925 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003926 } finally {
3927 Binder.restoreCallingIdentity(token);
3928 }
3929 }
3930
3931 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003932 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003933 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003934 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003935 final long identity = Binder.clearCallingIdentity();
3936 try {
3937 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003938 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003939 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003940 } catch (ImsException e) {
3941 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003942 } finally {
3943 Binder.restoreCallingIdentity(identity);
3944 }
3945 }
3946
shilu366312e2019-12-17 09:28:10 -08003947 /**
3948 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3949 * @param subId The subscription to use to check the configuration.
3950 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003951 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003952 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003953 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3954 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003955 final long identity = Binder.clearCallingIdentity();
3956 try {
3957 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003958 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3959 } catch (ImsException e) {
3960 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003961 } finally {
3962 Binder.restoreCallingIdentity(identity);
3963 }
3964 }
3965
3966 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003967 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003969 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003970 final long identity = Binder.clearCallingIdentity();
3971 try {
3972 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003973 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003974 } catch (ImsException e) {
3975 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003976 } finally {
3977 Binder.restoreCallingIdentity(identity);
3978 }
3979 }
3980
shilu366312e2019-12-17 09:28:10 -08003981 /**
3982 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3983 * @param subId The subscription to use to check the configuration.
3984 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003985 @Override
3986 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003987 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3988 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003989 final long identity = Binder.clearCallingIdentity();
3990 try {
3991 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003992 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003993 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003994 } catch (ImsException e) {
3995 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003996 } finally {
3997 Binder.restoreCallingIdentity(identity);
3998 }
3999 }
4000
4001 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004002 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004004 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004005 final long identity = Binder.clearCallingIdentity();
4006 try {
4007 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004008 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004009 } catch (ImsException e) {
4010 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004011 } finally {
4012 Binder.restoreCallingIdentity(identity);
4013 }
4014 }
4015
shilu366312e2019-12-17 09:28:10 -08004016 /**
4017 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4018 * @param subId The subscription to use to check the configuration.
4019 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004020 @Override
4021 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004022 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4023 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004024 final long identity = Binder.clearCallingIdentity();
4025 try {
4026 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004027 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004028 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004029 } catch (ImsException e) {
4030 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004031 } finally {
4032 Binder.restoreCallingIdentity(identity);
4033 }
4034 }
4035
4036 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004037 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004039 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004040 final long identity = Binder.clearCallingIdentity();
4041 try {
4042 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004043 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004044 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004045 } catch (ImsException e) {
4046 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004047 } finally {
4048 Binder.restoreCallingIdentity(identity);
4049 }
4050 }
4051
4052 @Override
4053 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4055 "setVoWiFiNonPersistent");
4056 final long identity = Binder.clearCallingIdentity();
4057 try {
4058 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004059 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004060 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004061 } catch (ImsException e) {
4062 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004063 } finally {
4064 Binder.restoreCallingIdentity(identity);
4065 }
4066 }
4067
shilu366312e2019-12-17 09:28:10 -08004068 /**
4069 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4070 * @param subId The subscription to use to check the configuration.
4071 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004072 @Override
4073 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004074 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4075 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004076 final long identity = Binder.clearCallingIdentity();
4077 try {
4078 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004079 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004080 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004081 } catch (ImsException e) {
4082 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004083 } finally {
4084 Binder.restoreCallingIdentity(identity);
4085 }
4086 }
4087
4088 @Override
4089 public void setVoWiFiModeSetting(int subId, int mode) {
4090 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4091 "setVoWiFiModeSetting");
4092 final long identity = Binder.clearCallingIdentity();
4093 try {
4094 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004095 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004096 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004097 } catch (ImsException e) {
4098 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004099 } finally {
4100 Binder.restoreCallingIdentity(identity);
4101 }
4102 }
4103
4104 @Override
4105 public int getVoWiFiRoamingModeSetting(int subId) {
4106 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4107 final long identity = Binder.clearCallingIdentity();
4108 try {
4109 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004110 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004111 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004112 } catch (ImsException e) {
4113 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004114 } finally {
4115 Binder.restoreCallingIdentity(identity);
4116 }
4117 }
4118
4119 @Override
4120 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4122 "setVoWiFiRoamingModeSetting");
4123 final long identity = Binder.clearCallingIdentity();
4124 try {
4125 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004126 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004127 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004128 } catch (ImsException e) {
4129 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004130 } finally {
4131 Binder.restoreCallingIdentity(identity);
4132 }
4133 }
4134
4135 @Override
4136 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4137 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4138 "setRttCapabilityEnabled");
4139 final long identity = Binder.clearCallingIdentity();
4140 try {
4141 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004142 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4143 } catch (ImsException e) {
4144 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004145 } finally {
4146 Binder.restoreCallingIdentity(identity);
4147 }
4148 }
4149
shilu366312e2019-12-17 09:28:10 -08004150 /**
4151 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4152 * @param subId The subscription to use to check the configuration.
4153 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004154 @Override
4155 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004156 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4157 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004158 final long identity = Binder.clearCallingIdentity();
4159 try {
4160 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004161 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004162 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004163 } catch (ImsException e) {
4164 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004165 } finally {
4166 Binder.restoreCallingIdentity(identity);
4167 }
4168 }
4169
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004170 @Override
4171 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4172 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4173 final long identity = Binder.clearCallingIdentity();
4174 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004175 if (!isImsAvailableOnDevice()) {
4176 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4177 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004178 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004179 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004180 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004181 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004182 } catch (ImsException e) {
4183 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004184 } finally {
4185 Binder.restoreCallingIdentity(identity);
4186 }
4187 }
4188
4189 @Override
4190 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4191 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4192 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004193 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4194 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4195 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004196 try {
4197 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004198 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004199 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004200 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004201 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4202 + "is inactive, ignoring unregister.");
4203 // If the subscription is no longer active, just return, since the callback will already
4204 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004205 } finally {
4206 Binder.restoreCallingIdentity(identity);
4207 }
4208 }
4209
allenwtsu99c623b2020-01-03 18:24:23 +08004210
4211 private void checkModifyPhoneStatePermission(int subId, String message) {
4212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4213 message);
4214 }
4215
4216 private boolean isImsProvisioningRequired(int subId, int capability,
4217 boolean isMmtelCapability) {
4218 Phone phone = getPhone(subId);
4219 if (phone == null) {
4220 loge("phone instance null for subid " + subId);
4221 return false;
4222 }
4223 if (isMmtelCapability) {
4224 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4225 return false;
4226 }
4227 } else {
4228 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4229 return false;
4230 }
4231 }
4232 return true;
4233 }
4234
4235 @Override
4236 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4237 boolean isProvisioned) {
4238 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4239
4240 final long identity = Binder.clearCallingIdentity();
4241 try {
4242 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4243 if (!isImsProvisioningRequired(subId, capability, false)) {
4244 return;
4245 }
4246
4247 // this capability requires provisioning, route to the correct API.
4248 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4249 switch (capability) {
4250 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4251 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4252 ims.setEabProvisioned(isProvisioned);
4253 break;
4254 default: {
4255 throw new IllegalArgumentException("Tried to set provisioning for "
4256 + "rcs capability '" + capability + "', which does not require "
4257 + "provisioning.");
4258 }
4259 }
4260 } finally {
4261 Binder.restoreCallingIdentity(identity);
4262 }
4263
4264 }
4265
4266
4267 @Override
4268 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4269 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4270 final long identity = Binder.clearCallingIdentity();
4271 try {
4272 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4273 if (!isImsProvisioningRequired(subId, capability, false)) {
4274 return true;
4275 }
4276
4277 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4278 switch (capability) {
4279 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4280 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4281 return ims.isEabProvisionedOnDevice();
4282
4283 default: {
4284 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4285 + "capability '" + capability + "', which does not require "
4286 + "provisioning.");
4287 }
4288 }
4289
4290 } finally {
4291 Binder.restoreCallingIdentity(identity);
4292 }
4293 }
4294
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004295 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004296 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4297 boolean isProvisioned) {
4298 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4299 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4300 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4301 }
allenwtsu99c623b2020-01-03 18:24:23 +08004302 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004303 final long identity = Binder.clearCallingIdentity();
4304 try {
4305 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004306 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004307 return;
4308 }
4309
4310 // this capability requires provisioning, route to the correct API.
4311 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4312 switch (capability) {
4313 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4314 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4315 ims.setVolteProvisioned(isProvisioned);
4316 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4317 ims.setWfcProvisioned(isProvisioned);
4318 }
4319 break;
4320 }
4321 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4322 // There is currently no difference in VT provisioning type.
4323 ims.setVtProvisioned(isProvisioned);
4324 break;
4325 }
4326 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4327 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4328 // change the capability of the feature instead if needed.
4329 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4330 == isProvisioned) {
4331 // No change in provisioning.
4332 return;
4333 }
4334 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4335 try {
4336 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004337 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004338 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4339 + ", Exception" + e.getMessage());
4340 }
4341 break;
4342 }
4343 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004344 throw new IllegalArgumentException("Tried to set provisioning for "
4345 + "MmTel capability '" + capability + "', which does not require "
4346 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004347 }
4348 }
4349
4350 } finally {
4351 Binder.restoreCallingIdentity(identity);
4352 }
4353 }
4354
4355 @Override
4356 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4357 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4358 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4359 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4360 }
4361 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4362 final long identity = Binder.clearCallingIdentity();
4363 try {
4364 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004365 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004366 return true;
4367 }
4368
4369 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4370 switch (capability) {
4371 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4372 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4373 return ims.isVolteProvisionedOnDevice();
4374 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4375 return ims.isWfcProvisionedOnDevice();
4376 }
4377 // This should never happen, since we are checking tech above to make sure it
4378 // is either LTE or IWLAN.
4379 throw new IllegalArgumentException("Invalid radio technology for voice "
4380 + "capability.");
4381 }
4382 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4383 // There is currently no difference in VT provisioning type.
4384 return ims.isVtProvisionedOnDevice();
4385 }
4386 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4387 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4388 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4389 }
4390 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004391 throw new IllegalArgumentException(
4392 "Tried to get provisioning for MmTel capability '" + capability
4393 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004394 }
4395 }
4396
4397 } finally {
4398 Binder.restoreCallingIdentity(identity);
4399 }
4400 }
4401
4402 @Override
4403 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4404 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4405 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4406 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4407 }
4408 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4409 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4410 return (provisionedBits & capability) > 0;
4411 }
4412
4413 @Override
4414 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4415 boolean isProvisioned) {
4416 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4417 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4418 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4419 }
4420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4421 "setProvisioningStatusForCapability");
4422 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4423 // If the current provisioning status for capability already matches isProvisioned,
4424 // do nothing.
4425 if (((provisionedBits & capability) > 0) == isProvisioned) {
4426 return;
4427 }
4428 if (isProvisioned) {
4429 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4430 } else {
4431 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4432 }
4433 }
4434
4435 /**
4436 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4437 * technology. The bitfield should mirror the bitfield defined by
4438 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4439 */
4440 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4441 String key = getMmTelProvisioningKey(subId, tech);
4442 // Default is no capabilities are provisioned.
4443 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4444 }
4445
4446 /**
4447 * Sets the MmTel capability provisioning bitfield (defined by
4448 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4449 * technology specified.
4450 *
4451 * Note: This is a synchronous command and should not be called on UI thread.
4452 */
4453 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4454 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4455 String key = getMmTelProvisioningKey(subId, tech);
4456 editor.putInt(key, newField);
4457 editor.commit();
4458 }
4459
4460 private static String getMmTelProvisioningKey(int subId, int tech) {
4461 // resulting key is provision_ims_mmtel_{subId}_{tech}
4462 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4463 }
4464
4465 /**
4466 * Query CarrierConfig to see if the specified capability requires provisioning for the
4467 * carrier associated with the subscription id.
4468 */
4469 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4470 int capability) {
4471 CarrierConfigManager configManager = new CarrierConfigManager(context);
4472 PersistableBundle c = configManager.getConfigForSubId(subId);
4473 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004474 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004475 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4476 false);
4477 boolean requireVoiceVtProvisioning = c.getBoolean(
4478 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4479
4480 // First check to make sure that the capability requires provisioning.
4481 switch (capability) {
4482 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4483 // intentional fallthrough
4484 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4485 if (requireVoiceVtProvisioning) {
4486 // Voice and Video requires provisioning
4487 return true;
4488 }
4489 break;
4490 }
4491 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4492 if (requireUtProvisioning) {
4493 // UT requires provisioning
4494 return true;
4495 }
4496 break;
4497 }
4498 }
4499 return false;
4500 }
4501
allenwtsu99c623b2020-01-03 18:24:23 +08004502 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4503 int capability) {
4504 CarrierConfigManager configManager = new CarrierConfigManager(context);
4505 PersistableBundle c = configManager.getConfigForSubId(subId);
4506
4507 boolean requireRcsProvisioning = c.getBoolean(
4508 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4509
4510 // First check to make sure that the capability requires provisioning.
4511 switch (capability) {
4512 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4513 // intentional fallthrough
4514 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4515 if (requireRcsProvisioning) {
4516 // OPTION or PRESENCE requires provisioning
4517 return true;
4518 }
4519 break;
4520 }
4521 }
4522 return false;
4523 }
4524
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004525 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004526 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004527 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4528 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4529 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004530 enforceReadPrivilegedPermission("getImsProvisioningInt");
4531 final long identity = Binder.clearCallingIdentity();
4532 try {
4533 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004534 int slotId = getSlotIndex(subId);
4535 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4536 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4537 + subId + "' for key:" + key);
4538 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4539 }
4540 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004541 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004542 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4543 + subId + "' for key:" + key);
4544 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004545 } finally {
4546 Binder.restoreCallingIdentity(identity);
4547 }
4548 }
4549
4550 @Override
4551 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004552 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4553 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4554 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004555 enforceReadPrivilegedPermission("getImsProvisioningString");
4556 final long identity = Binder.clearCallingIdentity();
4557 try {
4558 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004559 int slotId = getSlotIndex(subId);
4560 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4561 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4562 + subId + "' for key:" + key);
4563 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4564 }
4565 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004566 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004567 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4568 + subId + "' for key:" + key);
4569 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004570 } finally {
4571 Binder.restoreCallingIdentity(identity);
4572 }
4573 }
4574
4575 @Override
4576 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004577 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4578 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4579 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4581 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004582 final long identity = Binder.clearCallingIdentity();
4583 try {
4584 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004585 int slotId = getSlotIndex(subId);
4586 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4587 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4588 + subId + "' for key:" + key);
4589 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4590 }
4591 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004592 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004593 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4594 + "' for key:" + key);
4595 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004596 } finally {
4597 Binder.restoreCallingIdentity(identity);
4598 }
4599 }
4600
4601 @Override
4602 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004603 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4604 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4605 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4607 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004608 final long identity = Binder.clearCallingIdentity();
4609 try {
4610 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004611 int slotId = getSlotIndex(subId);
4612 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4613 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4614 + subId + "' for key:" + key);
4615 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4616 }
4617 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004618 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004619 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4620 + "' for key:" + key);
4621 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004622 } finally {
4623 Binder.restoreCallingIdentity(identity);
4624 }
4625 }
4626
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004627 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004628 int slotId = SubscriptionManager.getSlotIndex(subId);
4629 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004630 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4631 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004632 }
4633 return slotId;
4634 }
4635
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004636 private int getSlotIndex(int subId) {
4637 int slotId = SubscriptionManager.getSlotIndex(subId);
4638 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4639 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4640 }
4641 return slotId;
4642 }
4643
Wink Saville36469e72014-06-11 15:17:00 -07004644 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004645 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004646 */
4647 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004648 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4649 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004650 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004651 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004652 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004653 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004654 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004655 mApp, subId, callingPackage, callingFeatureId,
4656 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004657 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4658 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004659
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004660 final long identity = Binder.clearCallingIdentity();
4661 try {
4662 final Phone phone = getPhone(subId);
4663 if (phone != null) {
4664 return phone.getServiceState().getDataNetworkType();
4665 } else {
4666 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4667 }
4668 } finally {
4669 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004671 }
4672
4673 /**
4674 * Returns the data network type
4675 */
4676 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004677 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4678 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4679 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004680 }
4681
4682 /**
4683 * Returns the data network type for a subId
4684 */
4685 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004686 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4687 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004688 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004689 mApp, subId, callingPackage, callingFeatureId,
4690 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004691 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4692 }
4693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004694 final long identity = Binder.clearCallingIdentity();
4695 try {
4696 final Phone phone = getPhone(subId);
4697 if (phone != null) {
4698 return phone.getServiceState().getDataNetworkType();
4699 } else {
4700 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4701 }
4702 } finally {
4703 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004705 }
4706
4707 /**
Wink Saville36469e72014-06-11 15:17:00 -07004708 * Returns the Voice network type for a subId
4709 */
4710 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004711 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4712 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004714 mApp, subId, callingPackage, callingFeatureId,
4715 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004716 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4717 }
4718
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004719 final long identity = Binder.clearCallingIdentity();
4720 try {
4721 final Phone phone = getPhone(subId);
4722 if (phone != null) {
4723 return phone.getServiceState().getVoiceNetworkType();
4724 } else {
4725 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4726 }
4727 } finally {
4728 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004730 }
4731
4732 /**
4733 * @return true if a ICC card is present
4734 */
4735 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004736 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004737 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4738 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004739 }
4740
4741 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004742 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004743 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004744 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004745 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004746 final long identity = Binder.clearCallingIdentity();
4747 try {
4748 final Phone phone = PhoneFactory.getPhone(slotIndex);
4749 if (phone != null) {
4750 return phone.getIccCard().hasIccCard();
4751 } else {
4752 return false;
4753 }
4754 } finally {
4755 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004756 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004757 }
4758
4759 /**
4760 * Return if the current radio is LTE on CDMA. This
4761 * is a tri-state return value as for a period of time
4762 * the mode may be unknown.
4763 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004764 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004765 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004766 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004767 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004768 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004769 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4770 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4771 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004772 }
4773
Sanket Padawe356d7632015-06-22 14:03:32 -07004774 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004775 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4776 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004777 try {
4778 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4779 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004780 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4781 }
4782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004783 final long identity = Binder.clearCallingIdentity();
4784 try {
4785 final Phone phone = getPhone(subId);
4786 if (phone == null) {
4787 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4788 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004789 return TelephonyProperties.lte_on_cdma_device()
4790 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004791 }
4792 } finally {
4793 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004794 }
Wink Saville36469e72014-06-11 15:17:00 -07004795 }
4796
Wink Saville36469e72014-06-11 15:17:00 -07004797 /**
4798 * {@hide}
4799 * Returns Default subId, 0 in the case of single standby.
4800 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004801 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004802 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004803 }
4804
Shishir Agrawala9f32182016-04-12 12:00:16 -07004805 private int getSlotForDefaultSubscription() {
4806 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4807 }
4808
Wink Savilleb564aae2014-10-23 10:18:09 -07004809 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004810 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004811 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004812
Pengquan Menge92a50d2018-09-21 15:54:48 -07004813 private boolean isActiveSubscription(int subId) {
4814 return mSubscriptionController.isActiveSubId(subId);
4815 }
4816
Ihab Awadf2177b72013-11-25 13:33:23 -08004817 /**
4818 * @see android.telephony.TelephonyManager.WifiCallingChoices
4819 */
4820 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004821 final long identity = Binder.clearCallingIdentity();
4822 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004823 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004824 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4825 getWhenToMakeWifiCallsDefaultPreference());
4826 } finally {
4827 Binder.restoreCallingIdentity(identity);
4828 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004829 }
4830
4831 /**
4832 * @see android.telephony.TelephonyManager.WifiCallingChoices
4833 */
4834 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004835 final long identity = Binder.clearCallingIdentity();
4836 try {
4837 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004838 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004839 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4840 } finally {
4841 Binder.restoreCallingIdentity(identity);
4842 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004843 }
4844
Sailesh Nepald1e68152013-12-12 19:08:02 -08004845 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004846 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004847 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004848 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004849
Jordan Liu4c733742019-02-28 12:03:40 -08004850 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4851 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4852 if (phoneId == -1) {
4853 throw new IllegalArgumentException("Given slot index: " + slotIndex
4854 + " does not correspond to an active phone");
4855 }
4856 return PhoneFactory.getPhone(phoneId);
4857 }
4858
Shishir Agrawal566b7612013-10-28 14:41:00 -07004859 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004860 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4861 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4863 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004864 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004865 if (DBG) {
4866 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4867 }
4868 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4869 p2);
4870 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004871
Jordan Liu4c733742019-02-28 12:03:40 -08004872
4873 @Override
4874 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4875 int slotIndex, String callingPackage, String aid, int p2) {
4876 enforceModifyPermission();
4877 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4878 if (DBG) {
4879 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4880 }
4881 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4882 callingPackage, aid, p2);
4883 }
4884
4885 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4886 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004887 final long identity = Binder.clearCallingIdentity();
4888 try {
4889 if (TextUtils.equals(ISDR_AID, aid)) {
4890 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004891 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4892 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004893 if (bestComponent == null
4894 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4895 loge("The calling package is not allowed to access ISD-R.");
4896 throw new SecurityException(
4897 "The calling package is not allowed to access ISD-R.");
4898 }
Derek Tan740e1672017-06-27 14:56:27 -07004899 }
Derek Tan740e1672017-06-27 14:56:27 -07004900
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004901 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004902 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4903 null /* workSource */);
4904 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004905 return response;
4906 } finally {
4907 Binder.restoreCallingIdentity(identity);
4908 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004909 }
4910
4911 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004912 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4914 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004915 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4916 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4917 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004918
Jordan Liu4c733742019-02-28 12:03:40 -08004919 @Override
4920 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4921 enforceModifyPermission();
4922 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4923 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4924 channel);
4925 }
4926
4927 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004928 final long identity = Binder.clearCallingIdentity();
4929 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004930 if (channel < 0) {
4931 return false;
4932 }
Jordan Liu4c733742019-02-28 12:03:40 -08004933 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4934 null /* workSource */);
4935 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004936 return success;
4937 } finally {
4938 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004939 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004940 }
4941
4942 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004943 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004944 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4946 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004947 if (DBG) {
4948 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4949 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4950 + p3 + " data=" + data);
4951 }
4952 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4953 command, p1, p2, p3, data);
4954 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004955
Jordan Liu4c733742019-02-28 12:03:40 -08004956 @Override
4957 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4958 int command, int p1, int p2, int p3, String data) {
4959 enforceModifyPermission();
4960 if (DBG) {
4961 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4962 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4963 + p3 + " data=" + data);
4964 }
4965 return iccTransmitApduLogicalChannelWithPermission(
4966 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4967 data);
4968 }
4969
4970 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4971 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004972 final long identity = Binder.clearCallingIdentity();
4973 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004974 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004975 return "";
4976 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004978 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004979 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4980 null /* workSource */);
4981 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004982
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004983 // Append the returned status code to the end of the response payload.
4984 String s = Integer.toHexString(
4985 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4986 if (response.payload != null) {
4987 s = IccUtils.bytesToHexString(response.payload) + s;
4988 }
4989 return s;
4990 } finally {
4991 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004992 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004993 }
Jake Hambye994d462014-02-03 13:10:13 -08004994
Evan Charltonc66da362014-05-16 14:06:40 -07004995 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004996 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4997 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4999 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005000 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005001 if (DBG) {
5002 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5003 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5004 }
5005 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5006 cla, command, p1, p2, p3, data);
5007 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005008
Jordan Liu4c733742019-02-28 12:03:40 -08005009 @Override
5010 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5011 int command, int p1, int p2, int p3, String data) {
5012 enforceModifyPermission();
5013 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5014 if (DBG) {
5015 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5016 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5017 + " data=" + data);
5018 }
5019
5020 return iccTransmitApduBasicChannelWithPermission(
5021 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5022 p2, p3, data);
5023 }
5024
5025 // open APDU basic channel assuming the caller has sufficient permissions
5026 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5027 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028 final long identity = Binder.clearCallingIdentity();
5029 try {
5030 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5031 && TextUtils.equals(ISDR_AID, data)) {
5032 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005033 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5034 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005035 if (bestComponent == null
5036 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5037 loge("The calling package is not allowed to select ISD-R.");
5038 throw new SecurityException(
5039 "The calling package is not allowed to select ISD-R.");
5040 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005041 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005042
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005043 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005044 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5045 null /* workSource */);
5046 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005048 // Append the returned status code to the end of the response payload.
5049 String s = Integer.toHexString(
5050 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5051 if (response.payload != null) {
5052 s = IccUtils.bytesToHexString(response.payload) + s;
5053 }
5054 return s;
5055 } finally {
5056 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005057 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005058 }
5059
5060 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005061 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005062 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005063 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5064 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005065
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066 final long identity = Binder.clearCallingIdentity();
5067 try {
5068 if (DBG) {
5069 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5070 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5071 }
5072
5073 IccIoResult response =
5074 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5075 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5076 subId);
5077
5078 if (DBG) {
5079 log("Exchange SIM_IO [R]" + response);
5080 }
5081
5082 byte[] result = null;
5083 int length = 2;
5084 if (response.payload != null) {
5085 length = 2 + response.payload.length;
5086 result = new byte[length];
5087 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5088 } else {
5089 result = new byte[length];
5090 }
5091
5092 result[length - 1] = (byte) response.sw2;
5093 result[length - 2] = (byte) response.sw1;
5094 return result;
5095 } finally {
5096 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005097 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005098 }
5099
Nathan Haroldb3014052017-01-25 15:57:32 -08005100 /**
5101 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5102 * on a particular subscription
5103 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005104 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5105 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005106 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005107 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005108 return null;
5109 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005110
5111 final long identity = Binder.clearCallingIdentity();
5112 try {
5113 if (appType != TelephonyManager.APPTYPE_USIM
5114 && appType != TelephonyManager.APPTYPE_SIM) {
5115 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5116 return null;
5117 }
5118 Object response = sendRequest(
5119 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5120 if (response instanceof String[]) {
5121 return (String[]) response;
5122 }
yincheng zhaod698b842019-09-06 17:06:54 -07005123 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005124 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005125 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005126 } finally {
5127 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005128 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005129 }
5130
yincheng zhaod698b842019-09-06 17:06:54 -07005131 /**
5132 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5133 * subscription.
5134 *
5135 * @param subId the id of the subscription.
5136 * @param appType the uicc app type, must be USIM or SIM.
5137 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5138 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005139 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005140 * @return number of fplmns that is successfully written to the SIM.
5141 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005142 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5143 String callingFeatureId) {
5144 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5145 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005146 if (DBG) logv("no permissions for setForbiddenplmns");
5147 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5148 }
5149 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5150 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5151 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5152 }
5153 if (fplmns == null) {
5154 throw new IllegalArgumentException("Fplmn List provided is null");
5155 }
5156 for (String fplmn : fplmns) {
5157 if (!CellIdentity.isValidPlmn(fplmn)) {
5158 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5159 }
5160 }
5161 final long identity = Binder.clearCallingIdentity();
5162 try {
5163 Object response = sendRequest(
5164 CMD_SET_FORBIDDEN_PLMNS,
5165 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5166 subId);
5167 return (int) response;
5168 } finally {
5169 Binder.restoreCallingIdentity(identity);
5170 }
5171 }
5172
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005173 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005174 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5176 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005177
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005178 final long identity = Binder.clearCallingIdentity();
5179 try {
5180 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5181 if (response.payload == null) {
5182 return "";
5183 }
Evan Charltonc66da362014-05-16 14:06:40 -07005184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005185 // Append the returned status code to the end of the response payload.
5186 String s = Integer.toHexString(
5187 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5188 s = IccUtils.bytesToHexString(response.payload) + s;
5189 return s;
5190 } finally {
5191 Binder.restoreCallingIdentity(identity);
5192 }
Evan Charltonc66da362014-05-16 14:06:40 -07005193 }
5194
Jake Hambye994d462014-02-03 13:10:13 -08005195 /**
5196 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5197 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5198 *
5199 * @param itemID the ID of the item to read
5200 * @return the NV item as a String, or null on error.
5201 */
5202 @Override
5203 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005204 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5206 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207
5208 final long identity = Binder.clearCallingIdentity();
5209 try {
5210 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005211 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005212 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5213 return value;
5214 } finally {
5215 Binder.restoreCallingIdentity(identity);
5216 }
Jake Hambye994d462014-02-03 13:10:13 -08005217 }
5218
5219 /**
5220 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5221 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5222 *
5223 * @param itemID the ID of the item to read
5224 * @param itemValue the value to write, as a String
5225 * @return true on success; false on any failure
5226 */
5227 @Override
5228 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005229 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5231 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005232
5233 final long identity = Binder.clearCallingIdentity();
5234 try {
5235 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5236 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005237 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5239 return success;
5240 } finally {
5241 Binder.restoreCallingIdentity(identity);
5242 }
Jake Hambye994d462014-02-03 13:10:13 -08005243 }
5244
5245 /**
5246 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5247 * Used for device configuration by some CDMA operators.
5248 *
5249 * @param preferredRoamingList byte array containing the new PRL
5250 * @return true on success; false on any failure
5251 */
5252 @Override
5253 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5255 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005256
5257 final long identity = Binder.clearCallingIdentity();
5258 try {
5259 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5260 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5261 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5262 return success;
5263 } finally {
5264 Binder.restoreCallingIdentity(identity);
5265 }
Jake Hambye994d462014-02-03 13:10:13 -08005266 }
5267
5268 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005269 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005270 * Used for device configuration by some CDMA operators.
5271 *
chen xu6dac5ab2018-10-26 17:39:23 -07005272 * @param slotIndex - device slot.
5273 *
Jake Hambye994d462014-02-03 13:10:13 -08005274 * @return true on success; false on any failure
5275 */
5276 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005277 public boolean resetModemConfig(int slotIndex) {
5278 Phone phone = PhoneFactory.getPhone(slotIndex);
5279 if (phone != null) {
5280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5281 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282
chen xu6dac5ab2018-10-26 17:39:23 -07005283 final long identity = Binder.clearCallingIdentity();
5284 try {
5285 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5286 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5287 return success;
5288 } finally {
5289 Binder.restoreCallingIdentity(identity);
5290 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005291 }
chen xu6dac5ab2018-10-26 17:39:23 -07005292 return false;
5293 }
5294
5295 /**
5296 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5297 *
5298 * @param slotIndex - device slot.
5299 *
5300 * @return true on success; false on any failure
5301 */
5302 @Override
5303 public boolean rebootModem(int slotIndex) {
5304 Phone phone = PhoneFactory.getPhone(slotIndex);
5305 if (phone != null) {
5306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5307 mApp, phone.getSubId(), "rebootModem");
5308
5309 final long identity = Binder.clearCallingIdentity();
5310 try {
5311 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5312 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5313 return success;
5314 } finally {
5315 Binder.restoreCallingIdentity(identity);
5316 }
5317 }
5318 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005319 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005320
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005321 public String[] getPcscfAddress(String apnType, String callingPackage,
5322 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005323 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005324 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5325 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005326 return new String[0];
5327 }
5328
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005329 final long identity = Binder.clearCallingIdentity();
5330 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005331 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332 } finally {
5333 Binder.restoreCallingIdentity(identity);
5334 }
Wink Saville36469e72014-06-11 15:17:00 -07005335 }
5336
Brad Ebinger51f743a2017-01-23 13:50:20 -08005337 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005338 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5339 * {@link #disableIms(int)}.
5340 * @param slotIndex device slot.
5341 */
5342 public void resetIms(int slotIndex) {
5343 enforceModifyPermission();
5344
5345 final long identity = Binder.clearCallingIdentity();
5346 try {
5347 if (mImsResolver == null) {
5348 // may happen if the does not support IMS.
5349 return;
5350 }
5351 mImsResolver.disableIms(slotIndex);
5352 mImsResolver.enableIms(slotIndex);
5353 } finally {
5354 Binder.restoreCallingIdentity(identity);
5355 }
5356 }
5357
5358 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005359 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5360 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005361 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005362 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -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 Ebinger9c0eb502019-01-23 15:06:19 -08005368 // may happen if the device does not support IMS.
5369 return;
5370 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005371 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372 } finally {
5373 Binder.restoreCallingIdentity(identity);
5374 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005375 }
5376
5377 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005378 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5379 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005380 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005381 public void disableIms(int slotId) {
5382 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005383
5384 final long identity = Binder.clearCallingIdentity();
5385 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005386 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005387 // may happen if the device does not support IMS.
5388 return;
5389 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005390 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005391 } finally {
5392 Binder.restoreCallingIdentity(identity);
5393 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005394 }
5395
5396 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005397 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5398 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005399 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005400 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005401 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005402 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403
5404 final long identity = Binder.clearCallingIdentity();
5405 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005406 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005407 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5408 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005409 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005410 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005411 } finally {
5412 Binder.restoreCallingIdentity(identity);
5413 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005414 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005415 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005416 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5417 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005418 @Override
5419 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005420 enforceModifyPermission();
5421
5422 final long identity = Binder.clearCallingIdentity();
5423 try {
5424 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005425 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005426 } finally {
5427 Binder.restoreCallingIdentity(identity);
5428 }
5429 }
5430
5431 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005432 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005433 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005434 */
5435 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5436 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005437
5438 final long identity = Binder.clearCallingIdentity();
5439 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005440 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005441 // may happen if the device does not support IMS.
5442 return null;
5443 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005444 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 } finally {
5446 Binder.restoreCallingIdentity(identity);
5447 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005448 }
5449
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005450 /**
5451 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005452 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005453 */
5454 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5455 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005456
5457 final long identity = Binder.clearCallingIdentity();
5458 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005459 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005460 // may happen if the device does not support IMS.
5461 return null;
5462 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005463 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005464 } finally {
5465 Binder.restoreCallingIdentity(identity);
5466 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005467 }
5468
Brad Ebinger884c07b2018-02-15 16:17:40 -08005469 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005470 * Sets the ImsService Package Name that Telephony will bind to.
5471 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005472 * @param slotIndex the slot ID that the ImsService should bind for.
5473 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005474 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005475 * @param featureTypes An integer array of feature types associated with a packageName.
5476 * @param packageName The name of the package that the current configuration will be replaced
5477 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005478 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005479 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005480 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5481 int[] featureTypes, String packageName) {
5482 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5483 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5485 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005486 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005487
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005488 final long identity = Binder.clearCallingIdentity();
5489 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005490 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005491 // may happen if the device does not support IMS.
5492 return false;
5493 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005494 Map<Integer, String> featureConfig = new HashMap<>();
5495 for (int featureType : featureTypes) {
5496 featureConfig.put(featureType, packageName);
5497 }
5498 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5499 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500 } finally {
5501 Binder.restoreCallingIdentity(identity);
5502 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005503 }
5504
5505 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005506 * Clears any carrier ImsService overrides for the slot index specified that were previously
5507 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5508 *
5509 * This should only be used for testing.
5510 *
5511 * @param slotIndex the slot ID that the ImsService should bind for.
5512 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5513 */
5514 @Override
5515 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5516 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5517 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5518 "clearCarrierImsServiceOverride");
5519 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5520 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5521 "clearCarrierImsServiceOverride");
5522
5523 final long identity = Binder.clearCallingIdentity();
5524 try {
5525 if (mImsResolver == null) {
5526 // may happen if the device does not support IMS.
5527 return false;
5528 }
5529 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5530 } finally {
5531 Binder.restoreCallingIdentity(identity);
5532 }
5533 }
5534
5535 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005536 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005537 *
5538 * @param slotId The slot that the ImsService is associated with.
5539 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5540 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005541 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005542 * @return the package name of the ImsService configuration.
5543 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005544 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5545 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005546 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005547 TelephonyPermissions
5548 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5549 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5550 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005551
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005552 final long identity = Binder.clearCallingIdentity();
5553 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005554 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005555 // may happen if the device does not support IMS.
5556 return "";
5557 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005558 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005559 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5560 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561 } finally {
5562 Binder.restoreCallingIdentity(identity);
5563 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005564 }
5565
Brad Ebinger77b832e2019-10-17 17:03:22 -07005566 /**
5567 * Get the MmTelFeature state associated with the requested subscription id.
5568 * @param subId The subscription that the MmTelFeature is associated with.
5569 * @param callback A callback with an integer containing the
5570 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5571 */
5572 @Override
5573 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5574 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5575 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5576 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5577 "IMS not available on device.");
5578 }
5579 final long token = Binder.clearCallingIdentity();
5580 try {
5581 int slotId = getSlotIndex(subId);
5582 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5583 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5584 + subId + "'");
5585 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5586 }
5587 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5588 try {
5589 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5590 } catch (RemoteException e) {
5591 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5592 + "Ignore");
5593 }
5594 });
5595 } finally {
5596 Binder.restoreCallingIdentity(token);
5597 }
5598 }
5599
Daniel Brightbb5840b2021-01-12 15:48:18 -08005600 /**
5601 * Sets the ims registration state on all valid {@link Phone}s.
5602 */
5603 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005604 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005605
5606 final long identity = Binder.clearCallingIdentity();
5607 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005608 // NOTE: Before S, this method only set the default phone.
5609 for (final Phone phone : PhoneFactory.getPhones()) {
5610 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5611 phone.setImsRegistrationState(registered);
5612 }
5613 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614 } finally {
5615 Binder.restoreCallingIdentity(identity);
5616 }
Wink Saville36469e72014-06-11 15:17:00 -07005617 }
5618
5619 /**
Stuart Scott54788802015-03-30 13:18:01 -07005620 * Set the network selection mode to automatic.
5621 *
5622 */
5623 @Override
5624 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5626 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005627
5628 final long identity = Binder.clearCallingIdentity();
5629 try {
shilufc958392020-01-20 11:36:01 -08005630 if (!isActiveSubscription(subId)) {
5631 return;
5632 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5634 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5635 } finally {
5636 Binder.restoreCallingIdentity(identity);
5637 }
Stuart Scott54788802015-03-30 13:18:01 -07005638 }
5639
Jack Yud10cdd42020-09-28 20:28:01 -07005640 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005641 * Ask the radio to connect to the input network and change selection mode to manual.
5642 *
5643 * @param subId the id of the subscription.
5644 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5645 * the operator to attach to.
5646 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5647 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5648 * normal network selection next time.
5649 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005650 */
5651 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005652 public boolean setNetworkSelectionModeManual(
5653 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005654 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5655 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005656
5657 if (!isActiveSubscription(subId)) {
5658 return false;
5659 }
5660
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005661 final long identity = Binder.clearCallingIdentity();
5662 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005663 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005664 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005665 if (DBG) {
5666 log("setNetworkSelectionModeManual: subId: " + subId
5667 + " operator: " + operatorInfo);
5668 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005669 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5670 } finally {
5671 Binder.restoreCallingIdentity(identity);
5672 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005673 }
shilu84f6e8b2019-12-19 13:58:01 -08005674 /**
5675 * Get the manual network selection
5676 *
5677 * @param subId the id of the subscription.
5678 *
5679 * @return the previously saved user selected PLMN
5680 */
5681 @Override
5682 public String getManualNetworkSelectionPlmn(int subId) {
5683 TelephonyPermissions
5684 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5685 mApp, subId, "getManualNetworkSelectionPlmn");
5686
5687 final long identity = Binder.clearCallingIdentity();
5688 try {
5689 if (!isActiveSubscription(subId)) {
5690 return "";
5691 }
5692
5693 final Phone phone = getPhone(subId);
5694 if (phone == null) {
5695 return "";
5696 }
5697 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5698 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5699 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5700 } finally {
5701 Binder.restoreCallingIdentity(identity);
5702 }
5703 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005704
5705 /**
5706 * Scans for available networks.
5707 */
5708 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005709 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5710 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5712 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005713 LocationAccessPolicy.LocationPermissionResult locationResult =
5714 LocationAccessPolicy.checkLocationPermission(mApp,
5715 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5716 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005717 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005718 .setCallingPid(Binder.getCallingPid())
5719 .setCallingUid(Binder.getCallingUid())
5720 .setMethod("getCellNetworkScanResults")
5721 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5722 .build());
5723 switch (locationResult) {
5724 case DENIED_HARD:
5725 throw new SecurityException("Not allowed to access scan results -- location");
5726 case DENIED_SOFT:
5727 return null;
5728 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005729
Pengquan Menga1bb6272018-09-06 09:59:22 -07005730 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005731 try {
5732 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005733 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735 } finally {
5736 Binder.restoreCallingIdentity(identity);
5737 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005738 }
5739
5740 /**
sqian80370722020-01-29 15:02:51 -08005741 * Get the call forwarding info, given the call forwarding reason.
5742 */
5743 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005744 public void getCallForwarding(int subId, int callForwardingReason,
5745 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005746 enforceReadPrivilegedPermission("getCallForwarding");
5747 long identity = Binder.clearCallingIdentity();
5748 try {
5749 if (DBG) {
5750 log("getCallForwarding: subId " + subId
5751 + " callForwardingReason" + callForwardingReason);
5752 }
Hall Liua1acea22020-09-18 19:04:59 -07005753
5754 Phone phone = getPhone(subId);
5755 if (phone == null) {
5756 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005757 callback.onError(
5758 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005759 } catch (RemoteException e) {
5760 // ignore
5761 }
5762 return;
5763 }
5764
5765 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5766 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5767 @Override
5768 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5769 try {
5770 callback.onCallForwardingInfoAvailable(info);
5771 } catch (RemoteException e) {
5772 // ignore
5773 }
5774 }
5775
5776 @Override
5777 public void onError(int error) {
5778 try {
5779 callback.onError(error);
5780 } catch (RemoteException e) {
5781 // ignore
5782 }
5783 }
5784 });
5785 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005786 } finally {
5787 Binder.restoreCallingIdentity(identity);
5788 }
5789 }
5790
5791 /**
5792 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5793 * reason, the number to forward, and the timeout before the forwarding is attempted.
5794 */
5795 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005796 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5797 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005798 enforceModifyPermission();
5799 long identity = Binder.clearCallingIdentity();
5800 try {
5801 if (DBG) {
5802 log("setCallForwarding: subId " + subId
5803 + " callForwardingInfo" + callForwardingInfo);
5804 }
Hall Liua1acea22020-09-18 19:04:59 -07005805
5806 Phone phone = getPhone(subId);
5807 if (phone == null) {
5808 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005809 callback.accept(
5810 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005811 } catch (RemoteException e) {
5812 // ignore
5813 }
5814 return;
5815 }
5816
5817 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5818 FunctionalUtils.ignoreRemoteException(callback::accept));
5819
5820 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005821 } finally {
5822 Binder.restoreCallingIdentity(identity);
5823 }
5824 }
5825
5826 /**
Hall Liua1acea22020-09-18 19:04:59 -07005827 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005828 */
5829 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005830 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005831 enforceReadPrivilegedPermission("getCallForwarding");
5832 long identity = Binder.clearCallingIdentity();
5833 try {
Hall Liua1acea22020-09-18 19:04:59 -07005834
5835 Phone phone = getPhone(subId);
5836 if (phone == null) {
5837 try {
5838 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5839 } catch (RemoteException e) {
5840 // ignore
5841 }
5842 return;
5843 }
5844
5845 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5846
sqian80370722020-01-29 15:02:51 -08005847 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005848 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005849 } finally {
5850 Binder.restoreCallingIdentity(identity);
5851 }
5852 }
5853
5854 /**
Hall Liua1acea22020-09-18 19:04:59 -07005855 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005856 */
5857 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005858 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005859 enforceModifyPermission();
5860 long identity = Binder.clearCallingIdentity();
5861 try {
Hall Liua1acea22020-09-18 19:04:59 -07005862 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5863
5864 Phone phone = getPhone(subId);
5865 if (phone == null) {
5866 try {
5867 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5868 } catch (RemoteException e) {
5869 // ignore
5870 }
5871 return;
5872 }
5873
5874 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5875 FunctionalUtils.ignoreRemoteException(callback::accept));
5876
5877 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005878 } finally {
5879 Binder.restoreCallingIdentity(identity);
5880 }
5881 }
5882
5883 /**
yinxub1bed742017-04-17 11:45:04 -07005884 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005885 *
yinxub1bed742017-04-17 11:45:04 -07005886 * @param subId id of the subscription
5887 * @param request contains the radio access networks with bands/channels to scan
5888 * @param messenger callback messenger for scan results or errors
5889 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005890 * @return the id of the requested scan which can be used to stop the scan.
5891 */
5892 @Override
5893 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005894 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005895 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5896 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005897 LocationAccessPolicy.LocationPermissionResult locationResult =
5898 LocationAccessPolicy.checkLocationPermission(mApp,
5899 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5900 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005901 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005902 .setCallingPid(Binder.getCallingPid())
5903 .setCallingUid(Binder.getCallingUid())
5904 .setMethod("requestNetworkScan")
5905 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5906 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005907 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005908 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5909 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005910 if (e != null) {
5911 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5912 throw e;
5913 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005914 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005915 return TelephonyScanManager.INVALID_SCAN_ID;
5916 }
5917 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005918 }
Hall Liu912dfd32019-04-25 14:02:26 -07005919 int callingUid = Binder.getCallingUid();
5920 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005921 final long identity = Binder.clearCallingIdentity();
5922 try {
5923 return mNetworkScanRequestTracker.startNetworkScan(
5924 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005925 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005926 } finally {
5927 Binder.restoreCallingIdentity(identity);
5928 }
yinxu504e1392017-04-12 16:03:22 -07005929 }
5930
Hall Liub2ac8ef2019-02-28 15:56:23 -08005931 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005932 NetworkScanRequest request, int subId, String callingPackage) {
5933 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005934 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5935 boolean hasNetworkScanPermission =
5936 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5937 == PERMISSION_GRANTED;
5938
5939 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5940 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5941 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005942 }
5943
5944 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5945 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005946 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5947 return new SecurityException("Specific channels must not be"
5948 + " scanned without location access.");
5949 }
5950 }
5951 }
5952
Hall Liub2ac8ef2019-02-28 15:56:23 -08005953 return null;
5954 }
5955
yinxu504e1392017-04-12 16:03:22 -07005956 /**
5957 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005958 *
5959 * @param subId id of the subscription
5960 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005961 */
5962 @Override
5963 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005964 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5965 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005966
Hall Liu912dfd32019-04-25 14:02:26 -07005967 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968 final long identity = Binder.clearCallingIdentity();
5969 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005970 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971 } finally {
5972 Binder.restoreCallingIdentity(identity);
5973 }
yinxu504e1392017-04-12 16:03:22 -07005974 }
5975
5976 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005977 * Get the calculated preferred network type.
5978 * Used for debugging incorrect network type.
5979 *
5980 * @return the preferred network type, defined in RILConstants.java.
5981 */
5982 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005983 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005984 final Phone defaultPhone = getDefaultPhone();
5985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005986 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005987 return RILConstants.PREFERRED_NETWORK_MODE;
5988 }
5989
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990 final long identity = Binder.clearCallingIdentity();
5991 try {
5992 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005993 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 } finally {
5995 Binder.restoreCallingIdentity(identity);
5996 }
Junda Liu84d15a22014-07-02 11:21:04 -07005997 }
5998
5999 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08006000 * Get the preferred network type.
6001 * Used for device configuration by some CDMA operators.
6002 *
6003 * @return the preferred network type, defined in RILConstants.java.
6004 */
6005 @Override
Stuart Scott54788802015-03-30 13:18:01 -07006006 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006007 TelephonyPermissions
6008 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6009 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010
6011 final long identity = Binder.clearCallingIdentity();
6012 try {
6013 if (DBG) log("getPreferredNetworkType");
6014 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
6015 int networkType = (result != null ? result[0] : -1);
6016 if (DBG) log("getPreferredNetworkType: " + networkType);
6017 return networkType;
6018 } finally {
6019 Binder.restoreCallingIdentity(identity);
6020 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006021 }
6022
6023 /**
6024 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08006025 *
6026 * @param networkType the preferred network type, defined in RILConstants.java.
6027 * @return true on success; false on any failure.
6028 */
6029 @Override
Stuart Scott54788802015-03-30 13:18:01 -07006030 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6032 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033
6034 final long identity = Binder.clearCallingIdentity();
6035 try {
calvinpan089c2a62020-03-12 14:17:55 +08006036 Boolean success = (Boolean) sendRequest(
6037 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08006038
6039 if (success) {
6040 Settings.Global.putInt(mApp.getContentResolver(),
6041 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
6042 }
calvinpan089c2a62020-03-12 14:17:55 +08006043 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
6044 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045 } finally {
6046 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07006047 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006048 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006049
6050 /**
calvinpan677fc2b2020-01-14 20:42:55 +08006051 * Get the allowed network types that store in the telephony provider.
6052 *
6053 * @param subId the id of the subscription.
6054 * @return allowedNetworkTypes the allowed network types.
6055 */
6056 @Override
6057 public long getAllowedNetworkTypes(int subId) {
6058 TelephonyPermissions
6059 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6060 mApp, subId, "getAllowedNetworkTypes");
6061
6062 final long identity = Binder.clearCallingIdentity();
6063 try {
6064 return SubscriptionManager.getLongSubscriptionProperty(
6065 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
6066 } finally {
6067 Binder.restoreCallingIdentity(identity);
6068 }
6069 }
6070
6071 /**
6072 * Set the allowed network types.
6073 *
6074 * @param subId the id of the subscription.
6075 * @param allowedNetworkTypes the allowed network types.
6076 * @return true on success; false on any failure.
6077 */
6078 @Override
6079 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
6080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6081 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08006082
calvinpan089c2a62020-03-12 14:17:55 +08006083 SubscriptionManager.setSubscriptionProperty(subId,
6084 SubscriptionManager.ALLOWED_NETWORK_TYPES,
6085 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08006086
calvinpan089c2a62020-03-12 14:17:55 +08006087 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6088 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6089 RILConstants.PREFERRED_NETWORK_MODE);
6090 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08006091 }
6092
6093 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006094 * Get the allowed network types for certain reason.
6095 *
6096 * @param subId the id of the subscription.
6097 * @param reason the reason the allowed network type change is taking place
6098 * @return the allowed network types.
6099 */
6100 @Override
6101 public long getAllowedNetworkTypesForReason(int subId,
6102 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6103 TelephonyPermissions
6104 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6105 mApp, subId, "getAllowedNetworkTypesForReason");
6106 final long identity = Binder.clearCallingIdentity();
6107 try {
6108 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6109 } finally {
6110 Binder.restoreCallingIdentity(identity);
6111 }
6112 }
6113
6114 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006115 * Enable/Disable E-UTRA-NR Dual Connectivity
6116 * @param subId subscription id of the sim card
6117 * @param nrDualConnectivityState expected NR dual connectivity state
6118 * This can be passed following states
6119 * <ol>
6120 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6121 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6122 * <li>Disable NR dual connectivity and force secondary cell to be released
6123 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6124 * </ol>
6125 * @return operation result.
6126 */
6127 @Override
6128 public int setNrDualConnectivityState(int subId,
6129 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6130 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6131 mApp, subId, "enableNRDualConnectivity");
6132 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6133 final long identity = Binder.clearCallingIdentity();
6134 try {
6135 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6136 nrDualConnectivityState, subId,
6137 workSource);
6138 if (DBG) log("enableNRDualConnectivity result: " + result);
6139 return result;
6140 } finally {
6141 Binder.restoreCallingIdentity(identity);
6142 }
6143 }
6144
6145 /**
6146 * Is E-UTRA-NR Dual Connectivity enabled
6147 * @return true if dual connectivity is enabled else false
6148 */
6149 @Override
6150 public boolean isNrDualConnectivityEnabled(int subId) {
6151 TelephonyPermissions
6152 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6153 mApp, subId, "isNRDualConnectivityEnabled");
6154 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6155 final long identity = Binder.clearCallingIdentity();
6156 try {
6157 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6158 null, subId, workSource);
6159 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6160 return isEnabled;
6161 } finally {
6162 Binder.restoreCallingIdentity(identity);
6163 }
6164 }
6165
6166 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006167 * get carrier bandwidth per primary and secondary carrier
6168 * @param subId subscription id of the sim card
6169 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6170 */
6171 @Override
6172 public CarrierBandwidth getCarrierBandwidth(int subId) {
6173 TelephonyPermissions
6174 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6175 mApp, subId, "isNRDualConnectivityEnabled");
6176 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6177 final long identity = Binder.clearCallingIdentity();
6178 try {
6179 CarrierBandwidth carrierBandwidth =
6180 getPhoneFromSubId(subId).getCarrierBandwidth();
6181 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6182 return carrierBandwidth;
6183 } finally {
6184 Binder.restoreCallingIdentity(identity);
6185 }
6186 }
6187
6188 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006189 * Get the effective allowed network types on the device.
6190 * This API will return an intersection of allowed network types for all reasons,
6191 * including the configuration done through setAllowedNetworkTypes
6192 *
6193 * @param subId the id of the subscription.
6194 * @return the allowed network types
6195 */
6196 @Override
6197 public long getEffectiveAllowedNetworkTypes(int subId) {
6198 TelephonyPermissions
6199 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6200 mApp, subId, "getEffectiveAllowedNetworkTypes");
6201 final long identity = Binder.clearCallingIdentity();
6202 try {
6203 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6204 } finally {
6205 Binder.restoreCallingIdentity(identity);
6206 }
6207 }
6208
6209 /**
6210 * Set the allowed network types of the device and
6211 * provide the reason triggering the allowed network change.
6212 *
6213 * @param subId the id of the subscription.
6214 * @param reason the reason the allowed network type change is taking place
6215 * @param allowedNetworkTypes the allowed network types.
6216 * @return true on success; false on any failure.
6217 */
6218 @Override
6219 public boolean setAllowedNetworkTypesForReason(int subId,
6220 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6222 mApp, subId, "setAllowedNetworkTypesForReason");
6223 final long identity = Binder.clearCallingIdentity();
6224 try {
6225 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6226 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6227 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6228 RILConstants.PREFERRED_NETWORK_MODE);
6229 return setPreferredNetworkType(subId, preferredNetworkMode);
6230 } finally {
6231 Binder.restoreCallingIdentity(identity);
6232 }
6233 }
6234
6235 /**
Miaoa84611c2019-03-15 09:21:10 +08006236 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006237 *
Miaoa84611c2019-03-15 09:21:10 +08006238 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006239 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006240 * @hide
6241 */
6242 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006243 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006244 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006245 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006246 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006247 try {
Miaoa84611c2019-03-15 09:21:10 +08006248 if (phone != null) {
6249 return phone.hasMatchedTetherApnSetting();
6250 } else {
6251 return false;
6252 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006253 } finally {
6254 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006255 }
Junda Liu475951f2014-11-07 16:45:03 -08006256 }
6257
6258 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006259 * Enable or disable always reporting signal strength changes from radio.
6260 *
6261 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6262 */
6263 @Override
6264 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6265 enforceModifyPermission();
6266 enforceSystemCaller();
6267
6268 final long identity = Binder.clearCallingIdentity();
6269 final Phone phone = getPhone(subId);
6270 try {
6271 if (phone != null) {
6272 if (DBG) {
6273 log("setAlwaysReportSignalStrength: subId=" + subId
6274 + " isEnable=" + isEnable);
6275 }
6276 phone.setAlwaysReportSignalStrength(isEnable);
6277 } else {
6278 loge("setAlwaysReportSignalStrength: no phone found for subId="
6279 + subId);
6280 }
6281 } finally {
6282 Binder.restoreCallingIdentity(identity);
6283 }
6284 }
6285
6286 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006287 * Get the user enabled state of Mobile Data.
6288 *
6289 * TODO: remove and use isUserDataEnabled.
6290 * This can't be removed now because some vendor codes
6291 * calls through ITelephony directly while they should
6292 * use TelephonyManager.
6293 *
6294 * @return true on enabled
6295 */
6296 @Override
6297 public boolean getDataEnabled(int subId) {
6298 return isUserDataEnabled(subId);
6299 }
6300
6301 /**
6302 * Get whether mobile data is enabled per user setting.
6303 *
6304 * There are other factors deciding whether mobile data is actually enabled, but they are
6305 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006306 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006307 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006308 *
6309 * @return {@code true} if data is enabled else {@code false}
6310 */
6311 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006312 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006313 try {
6314 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6315 null);
6316 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6318 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006319 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006320
6321 final long identity = Binder.clearCallingIdentity();
6322 try {
6323 int phoneId = mSubscriptionController.getPhoneId(subId);
6324 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6325 Phone phone = PhoneFactory.getPhone(phoneId);
6326 if (phone != null) {
6327 boolean retVal = phone.isUserDataEnabled();
6328 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6329 return retVal;
6330 } else {
6331 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6332 return false;
6333 }
6334 } finally {
6335 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006336 }
6337 }
6338
6339 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006340 * Checks if the device is capable of mobile data by considering whether whether the
6341 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6342 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006343 *
Shuo Qian985d1232020-01-08 14:30:06 -08006344 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006345 */
6346 @Override
6347 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006348 try {
6349 try {
6350 mApp.enforceCallingOrSelfPermission(
6351 android.Manifest.permission.ACCESS_NETWORK_STATE,
6352 null);
6353 } catch (Exception e) {
6354 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6355 "isDataEnabled");
6356 }
6357 } catch (Exception e) {
6358 enforceReadPrivilegedPermission("isDataEnabled");
6359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006360
6361 final long identity = Binder.clearCallingIdentity();
6362 try {
6363 int phoneId = mSubscriptionController.getPhoneId(subId);
6364 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6365 Phone phone = PhoneFactory.getPhone(phoneId);
6366 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006367 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6369 return retVal;
6370 } else {
6371 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6372 return false;
6373 }
6374 } finally {
6375 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006376 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006377 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006378
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006379 /**
6380 * Check if data is enabled for a specific reason
6381 * @param subId Subscription index
6382 * @param reason the reason the data enable change is taking place
6383 * @return {@code true} if the overall data is enabled; {@code false} if not.
6384 */
6385 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006386 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006387 @TelephonyManager.DataEnabledReason int reason) {
6388 try {
6389 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6390 null);
6391 } catch (Exception e) {
6392 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006393 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006394 }
6395
6396
6397 final long identity = Binder.clearCallingIdentity();
6398 try {
6399 int phoneId = mSubscriptionController.getPhoneId(subId);
6400 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006401 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006402 + " reason=" + reason);
6403 }
6404 Phone phone = PhoneFactory.getPhone(phoneId);
6405 if (phone != null) {
6406 boolean retVal;
6407 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6408 retVal = phone.isUserDataEnabled();
6409 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006410 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006411 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006412 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006413 return retVal;
6414 } else {
6415 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006416 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006417 + subId + " retVal=false");
6418 }
6419 return false;
6420 }
6421 } finally {
6422 Binder.restoreCallingIdentity(identity);
6423 }
6424 }
6425
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006426 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006427 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006428 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6429 // Skip the check if it's one of these special uids
6430 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6431 }
6432
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006433 //load access rules from carrier configs, and check those as well: b/139133814
6434 SubscriptionController subController = SubscriptionController.getInstance();
6435 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6436 || subController == null) return privilegeFromSim;
6437
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006438 PackageManager pkgMgr = phone.getContext().getPackageManager();
6439 String[] packages = pkgMgr.getPackagesForUid(uid);
6440
6441 final long identity = Binder.clearCallingIdentity();
6442 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006443 int subId = phone.getSubId();
6444 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6445 // A test override is in place for the privileges for this subId, so don't try to
6446 // read the subscription privileges.
6447 return privilegeFromSim;
6448 }
6449 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006450 SubscriptionManager subManager = (SubscriptionManager)
6451 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6452 for (String pkg : packages) {
6453 if (subManager.canManageSubscription(subInfo, pkg)) {
6454 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6455 }
6456 }
6457 return privilegeFromSim;
6458 } finally {
6459 Binder.restoreCallingIdentity(identity);
6460 }
6461 }
6462
6463 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6464 String pkgName) {
6465 //load access rules from carrier configs, and check those as well: b/139133814
6466 SubscriptionController subController = SubscriptionController.getInstance();
6467 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6468 || subController == null) return privilegeFromSim;
6469
6470 final long identity = Binder.clearCallingIdentity();
6471 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006472 int subId = phone.getSubId();
6473 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6474 // A test override is in place for the privileges for this subId, so don't try to
6475 // read the subscription privileges.
6476 return privilegeFromSim;
6477 }
6478 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006479 SubscriptionManager subManager = (SubscriptionManager)
6480 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6481 return subManager.canManageSubscription(subInfo, pkgName)
6482 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6483 } finally {
6484 Binder.restoreCallingIdentity(identity);
6485 }
6486 }
6487
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006488 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006489 public int getCarrierPrivilegeStatus(int subId) {
6490 final Phone phone = getPhone(subId);
6491 if (phone == null) {
6492 loge("getCarrierPrivilegeStatus: Invalid subId");
6493 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6494 }
6495 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006496 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006497 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006498 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6499 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006500
6501 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6502 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006503 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006504 }
Junda Liu29340342014-07-10 15:23:27 -07006505
6506 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006507 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006508 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006509 final Phone phone = getPhone(subId);
6510 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006511 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006512 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6513 }
6514 UiccProfile profile =
6515 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6516 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006517 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006518 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6519 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006520 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006521 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006522 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006523 }
6524
6525 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006526 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6527 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006528 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006529 }
6530
6531 int phoneId = SubscriptionManager.getPhoneId(subId);
6532 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006533 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006534 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006535 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6536 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006537 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6538 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6539 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006540 }
6541
6542 @Override
6543 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006544 if (TextUtils.isEmpty(pkgName))
6545 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006546 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6547 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6548 UiccCard card = UiccController.getInstance().getUiccCard(i);
6549 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006550 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006551 continue;
6552 }
6553
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006554 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6555 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6556 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006557 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6558 break;
6559 }
6560 }
6561
6562 return result;
Junda Liu29340342014-07-10 15:23:27 -07006563 }
Derek Tan89e89d42014-07-08 17:00:10 -07006564
6565 @Override
Junda Liue64de782015-04-16 17:19:16 -07006566 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6567 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6568 loge("phoneId " + phoneId + " is not valid.");
6569 return null;
6570 }
6571 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006572 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006573 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006574 return null ;
6575 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006576 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006577 }
6578
Amith Yamasani6e118872016-02-19 12:53:51 -08006579 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006580 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006581 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006582 List<String> privilegedPackages = new ArrayList<>();
6583 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006584 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6585 // has UICC in that slot.
6586 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006587 if (card.hasCarrierPrivilegeRules()) {
6588 if (packages == null) {
6589 // Only check packages in user 0 for now
6590 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006591 PackageManager.MATCH_DISABLED_COMPONENTS
6592 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006593 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006594 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006595 }
6596 for (int p = packages.size() - 1; p >= 0; p--) {
6597 PackageInfo pkgInfo = packages.get(p);
6598 if (pkgInfo != null && pkgInfo.packageName != null
6599 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006600 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006601 privilegedPackages.add(pkgInfo.packageName);
6602 }
6603 }
6604 }
6605 }
6606 return privilegedPackages;
6607 }
6608
chen xuf7e9fe82019-05-09 19:31:02 -07006609 @Override
6610 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006611 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6612
6613 final long identity = Binder.clearCallingIdentity();
6614
chen xuf7e9fe82019-05-09 19:31:02 -07006615 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006616 try {
6617 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6618 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6619 }
6620 } finally {
6621 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006622 }
6623 return privilegedPackages;
6624 }
6625
Wink Savilleb564aae2014-10-23 10:18:09 -07006626 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006627 final Phone phone = getPhone(subId);
6628 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006629 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006630 return null;
6631 }
6632 String iccId = card.getIccId();
6633 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006634 return null;
6635 }
6636 return iccId;
6637 }
6638
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006639 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006640 public void setCallComposerStatus(int subId, int status) {
6641 enforceModifyPermission();
6642
6643 final long identity = Binder.clearCallingIdentity();
6644 try {
6645 Phone phone = getPhone(subId);
6646 if (phone != null) {
6647 Phone defaultPhone = phone.getImsPhone();
6648 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6649 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6650 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006651 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6652 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006653 }
6654 }
Shuo Qiand8782462020-12-22 19:10:14 -08006655 } catch (ImsException e) {
6656 throw new ServiceSpecificException(e.getCode());
6657 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006658 Binder.restoreCallingIdentity(identity);
6659 }
6660 }
6661
6662 @Override
6663 public int getCallComposerStatus(int subId) {
6664 enforceReadPrivilegedPermission("getCallComposerStatus");
6665
6666 final long identity = Binder.clearCallingIdentity();
6667 try {
6668 Phone phone = getPhone(subId);
6669 if (phone != null) {
6670 Phone defaultPhone = phone.getImsPhone();
6671 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6672 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6673 return imsPhone.getCallComposerStatus();
6674 }
6675 }
6676 } finally {
6677 Binder.restoreCallingIdentity(identity);
6678 }
6679 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6680 }
6681
6682 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006683 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6684 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006685 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006686 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006687
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006688 final long identity = Binder.clearCallingIdentity();
6689 try {
6690 final String iccId = getIccId(subId);
6691 final Phone phone = getPhone(subId);
6692 if (phone == null) {
6693 return false;
6694 }
6695 final String subscriberId = phone.getSubscriberId();
6696
6697 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006698 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006699 + subscriberId + " to " + number);
6700 }
6701
6702 if (TextUtils.isEmpty(iccId)) {
6703 return false;
6704 }
6705
6706 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6707
6708 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6709 if (alphaTag == null) {
6710 editor.remove(alphaTagPrefKey);
6711 } else {
6712 editor.putString(alphaTagPrefKey, alphaTag);
6713 }
6714
6715 // Record both the line number and IMSI for this ICCID, since we need to
6716 // track all merged IMSIs based on line number
6717 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6718 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6719 if (number == null) {
6720 editor.remove(numberPrefKey);
6721 editor.remove(subscriberPrefKey);
6722 } else {
6723 editor.putString(numberPrefKey, number);
6724 editor.putString(subscriberPrefKey, subscriberId);
6725 }
6726
6727 editor.commit();
6728 return true;
6729 } finally {
6730 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006731 }
Derek Tan7226c842014-07-02 17:42:23 -07006732 }
6733
6734 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006735 public String getLine1NumberForDisplay(int subId, String callingPackage,
6736 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006737 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006738 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006739 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006740 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006741 return null;
6742 }
Derek Tan97ebb422014-09-05 16:55:38 -07006743
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006744 final long identity = Binder.clearCallingIdentity();
6745 try {
6746 String iccId = getIccId(subId);
6747 if (iccId != null) {
6748 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6749 if (DBG_MERGE) {
6750 log("getLine1NumberForDisplay returning "
6751 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6752 }
6753 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006754 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006755 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6756 return null;
6757 } finally {
6758 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006759 }
Derek Tan7226c842014-07-02 17:42:23 -07006760 }
6761
6762 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006763 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6764 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006765 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006766 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006767 return null;
6768 }
Derek Tan97ebb422014-09-05 16:55:38 -07006769
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006770 final long identity = Binder.clearCallingIdentity();
6771 try {
6772 String iccId = getIccId(subId);
6773 if (iccId != null) {
6774 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6775 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6776 }
6777 return null;
6778 } finally {
6779 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006780 }
Derek Tan7226c842014-07-02 17:42:23 -07006781 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006782
6783 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006784 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6785 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006786 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6787 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006788 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006789 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006790 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006791 return null;
6792 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006793
Jordan Liub49b04b2019-05-06 14:45:15 -07006794 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6795 // the process, where TelephonyManager was instantiated.
6796 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006797 final long identity = Binder.clearCallingIdentity();
6798 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006799 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006800 final TelephonyManager tele = TelephonyManager.from(context);
6801 final SubscriptionManager sub = SubscriptionManager.from(context);
6802
6803 // Figure out what subscribers are currently active
6804 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805
Jordan Liub49b04b2019-05-06 14:45:15 -07006806 // Only consider subs which match the current subId
6807 // This logic can be simplified. See b/131189269 for progress.
6808 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006809 activeSubscriberIds.add(tele.getSubscriberId(subId));
6810 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006811
6812 // First pass, find a number override for an active subscriber
6813 String mergeNumber = null;
6814 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6815 for (String key : prefs.keySet()) {
6816 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6817 final String subscriberId = (String) prefs.get(key);
6818 if (activeSubscriberIds.contains(subscriberId)) {
6819 final String iccId = key.substring(
6820 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6821 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6822 mergeNumber = (String) prefs.get(numberKey);
6823 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006824 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006825 + " for active subscriber " + subscriberId);
6826 }
6827 if (!TextUtils.isEmpty(mergeNumber)) {
6828 break;
6829 }
6830 }
6831 }
6832 }
6833
6834 // Shortcut when no active merged subscribers
6835 if (TextUtils.isEmpty(mergeNumber)) {
6836 return null;
6837 }
6838
6839 // Second pass, find all subscribers under that line override
6840 final ArraySet<String> result = new ArraySet<>();
6841 for (String key : prefs.keySet()) {
6842 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6843 final String number = (String) prefs.get(key);
6844 if (mergeNumber.equals(number)) {
6845 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6846 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6847 final String subscriberId = (String) prefs.get(subscriberKey);
6848 if (!TextUtils.isEmpty(subscriberId)) {
6849 result.add(subscriberId);
6850 }
6851 }
6852 }
6853 }
6854
6855 final String[] resultArray = result.toArray(new String[result.size()]);
6856 Arrays.sort(resultArray);
6857 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006858 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006859 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6860 }
6861 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006862 } finally {
6863 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006864 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006865 }
6866
6867 @Override
zoey chen38003472019-12-13 17:16:31 +08006868 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6869 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006870
6871 final long identity = Binder.clearCallingIdentity();
6872 try {
6873 final TelephonyManager telephonyManager = mApp.getSystemService(
6874 TelephonyManager.class);
6875 String subscriberId = telephonyManager.getSubscriberId(subId);
6876 if (subscriberId == null) {
6877 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006878 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006879 + subId);
6880 }
6881 return null;
6882 }
6883
6884 final SubscriptionInfo info = SubscriptionController.getInstance()
6885 .getSubscriptionInfo(subId);
6886 final ParcelUuid groupUuid = info.getGroupUuid();
6887 // If it doesn't belong to any group, return just subscriberId of itself.
6888 if (groupUuid == null) {
6889 return new String[]{subscriberId};
6890 }
6891
6892 // Get all subscriberIds from the group.
6893 final List<String> mergedSubscriberIds = new ArrayList<>();
6894 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006895 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006896 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006897 for (SubscriptionInfo subInfo : groupInfos) {
6898 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6899 if (subscriberId != null) {
6900 mergedSubscriberIds.add(subscriberId);
6901 }
6902 }
6903
6904 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6905 } finally {
6906 Binder.restoreCallingIdentity(identity);
6907
6908 }
6909 }
6910
6911 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006912 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006913 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006914 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006915
6916 final long identity = Binder.clearCallingIdentity();
6917 try {
6918 final Phone phone = getPhone(subId);
6919 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6920 } finally {
6921 Binder.restoreCallingIdentity(identity);
6922 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006923 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006924
6925 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006926 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006927 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6928 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006929 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6930 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006931
6932 final long identity = Binder.clearCallingIdentity();
6933 try {
6934 final Phone phone = getPhone(subId);
6935 if (phone == null) {
6936 return false;
6937 }
6938 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6939 cdmaNonRoamingList);
6940 } finally {
6941 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006942 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006943 }
6944
6945 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006946 @Deprecated
6947 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6948 enforceModifyPermission();
6949
6950 int returnValue = 0;
6951 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006952 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006953 if(result.exception == null) {
6954 if (result.result != null) {
6955 byte[] responseData = (byte[])(result.result);
6956 if(responseData.length > oemResp.length) {
6957 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6958 responseData.length + "bytes. Buffer Size is " +
6959 oemResp.length + "bytes.");
6960 }
6961 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6962 returnValue = responseData.length;
6963 }
6964 } else {
6965 CommandException ex = (CommandException) result.exception;
6966 returnValue = ex.getCommandError().ordinal();
6967 if(returnValue > 0) returnValue *= -1;
6968 }
6969 } catch (RuntimeException e) {
6970 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6971 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6972 if(returnValue > 0) returnValue *= -1;
6973 }
6974
6975 return returnValue;
6976 }
6977
6978 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006979 public void setRadioCapability(RadioAccessFamily[] rafs) {
6980 try {
6981 ProxyController.getInstance().setRadioCapability(rafs);
6982 } catch (RuntimeException e) {
6983 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6984 }
6985 }
6986
6987 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006988 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006989 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006990 try {
6991 TelephonyPermissions
6992 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6993 mApp, phone.getSubId(), "getRadioAccessFamily");
6994 } catch (SecurityException e) {
6995 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6996 throw e;
6997 }
chen xub97461a2018-10-26 14:17:57 -07006998 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006999 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007000 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007001 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007002 final long identity = Binder.clearCallingIdentity();
7003 try {
chen xub97461a2018-10-26 14:17:57 -07007004 TelephonyPermissions
7005 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7006 mApp, phone.getSubId(), "getRadioAccessFamily");
7007 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008 } finally {
7009 Binder.restoreCallingIdentity(identity);
7010 }
chen xub97461a2018-10-26 14:17:57 -07007011 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007012 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007013
7014 @Override
7015 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007016 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007017 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018
7019 final long identity = Binder.clearCallingIdentity();
7020 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007021 ImsManager.getInstance(defaultPhone.getContext(),
7022 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007023 } finally {
7024 Binder.restoreCallingIdentity(identity);
7025 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007026 }
7027
7028 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007029 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007030 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007031 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7032 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007033 return false;
7034 }
Svet Ganovb320e182015-04-16 12:30:10 -07007035
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007036 final long identity = Binder.clearCallingIdentity();
7037 try {
7038 // Check the user preference and the system-level IMS setting. Even if the user has
7039 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7040 // In the long run, we may instead need to check if there exists a connection service
7041 // which can support video calling.
7042 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007043 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007044 return imsManager.isVtEnabledByPlatform()
7045 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7046 && imsManager.isVtEnabledByUser();
7047 } finally {
7048 Binder.restoreCallingIdentity(identity);
7049 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007050 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007051
Andrew Leea1239f22015-03-02 17:44:07 -08007052 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007053 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7054 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007055 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007056 mApp, subId, callingPackage, callingFeatureId,
7057 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007058 return false;
7059 }
7060
7061 final long identity = Binder.clearCallingIdentity();
7062 try {
7063 CarrierConfigManager configManager =
7064 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007065 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007066 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7067 } finally {
7068 Binder.restoreCallingIdentity(identity);
7069 }
Andrew Leea1239f22015-03-02 17:44:07 -08007070 }
7071
7072 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007073 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007074 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007075 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007076 return false;
7077 }
7078
7079 final long identity = Binder.clearCallingIdentity();
7080 try {
7081 CarrierConfigManager configManager =
7082 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007083 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007084 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7085 } finally {
7086 Binder.restoreCallingIdentity(identity);
7087 }
Andrew Leea1239f22015-03-02 17:44:07 -08007088 }
7089
Andrew Lee9431b832015-03-09 18:46:45 -07007090 @Override
7091 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007092 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007093 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007094 }
7095
7096 @Override
7097 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007098 final long identity = Binder.clearCallingIdentity();
7099 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007100 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007101 } finally {
7102 Binder.restoreCallingIdentity(identity);
7103 }
Andrew Lee9431b832015-03-09 18:46:45 -07007104 }
7105
Hall Liuf6668912018-10-31 17:05:23 -07007106 /**
7107 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7108 * support for the feature and device firmware support.
7109 *
7110 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7111 */
7112 @Override
7113 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007114 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007115 final Phone phone = getPhone(subscriptionId);
7116 if (phone == null) {
7117 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7118 return false;
7119 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007121 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007122 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7123 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007124 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007125 return isCarrierSupported && isDeviceSupported;
7126 } finally {
7127 Binder.restoreCallingIdentity(identity);
7128 }
Hall Liu98187582018-01-22 19:15:32 -08007129 }
7130
Hall Liuf6668912018-10-31 17:05:23 -07007131 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007132 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7133 * RTT setting, will return true if the device and carrier both support RTT.
7134 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007135 */
7136 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007137 final long identity = Binder.clearCallingIdentity();
7138 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007139 boolean isRttSupported = isRttSupported(subscriptionId);
7140 boolean isUserRttSettingOn = Settings.Secure.getInt(
7141 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7142 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7143 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7144 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007145 } finally {
7146 Binder.restoreCallingIdentity(identity);
7147 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007148 }
7149
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007150 @Deprecated
7151 @Override
7152 public String getDeviceId(String callingPackage) {
7153 return getDeviceIdWithFeature(callingPackage, null);
7154 }
7155
Sanket Padawe7310cc72015-01-14 09:53:20 -08007156 /**
7157 * Returns the unique device ID of phone, for example, the IMEI for
7158 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7159 *
7160 * <p>Requires Permission:
7161 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7162 */
7163 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007164 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007165 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007166 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007167 return null;
7168 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007169 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007170 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007171 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007172 return null;
7173 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007174
7175 final long identity = Binder.clearCallingIdentity();
7176 try {
7177 return phone.getDeviceId();
7178 } finally {
7179 Binder.restoreCallingIdentity(identity);
7180 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007181 }
7182
Ping Sunc67b7c22016-03-02 19:16:45 +08007183 /**
7184 * {@hide}
7185 * Returns the IMS Registration Status on a particular subid
7186 *
7187 * @param subId
7188 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007189 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007190 Phone phone = getPhone(subId);
7191 if (phone != null) {
7192 return phone.isImsRegistered();
7193 } else {
7194 return false;
7195 }
7196 }
7197
Santos Cordon7a1885b2015-02-03 11:15:19 -08007198 @Override
7199 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007200 final long identity = Binder.clearCallingIdentity();
7201 try {
7202 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7203 } finally {
7204 Binder.restoreCallingIdentity(identity);
7205 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007206 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007207
Tyler Gunnf70ed162019-04-03 15:28:53 -07007208 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007209 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007210 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007211 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007212 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007213 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7214 }
7215 final long identity = Binder.clearCallingIdentity();
7216 try {
7217 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7218 } finally {
7219 Binder.restoreCallingIdentity(identity);
7220 }
7221 }
7222
7223 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007224 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007225 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7226 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007227 final long identity = Binder.clearCallingIdentity();
7228 try {
7229 Phone phone = getPhone(subscriptionId);
7230 if (phone == null) {
7231 return null;
7232 }
7233 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7234 } finally {
7235 Binder.restoreCallingIdentity(identity);
7236 }
7237 }
7238
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007239 /**
7240 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007241 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007242 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243 final long identity = Binder.clearCallingIdentity();
7244 try {
7245 Phone phone = getPhone(subId);
7246 if (phone != null) {
7247 return phone.isWifiCallingEnabled();
7248 } else {
7249 return false;
7250 }
7251 } finally {
7252 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007253 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007254 }
7255
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007256 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007257 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007258 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007259 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007260 final long identity = Binder.clearCallingIdentity();
7261 try {
7262 Phone phone = getPhone(subId);
7263 if (phone != null) {
7264 return phone.isVideoEnabled();
7265 } else {
7266 return false;
7267 }
7268 } finally {
7269 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007270 }
7271 }
7272
7273 /**
7274 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7275 * defined in {@link ImsRegistrationImplBase}.
7276 */
7277 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007278 final long identity = Binder.clearCallingIdentity();
7279 try {
7280 Phone phone = getPhone(subId);
7281 if (phone != null) {
7282 return phone.getImsRegistrationTech();
7283 } else {
7284 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7285 }
7286 } finally {
7287 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007288 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007289 }
7290
Stuart Scott8eef64f2015-04-08 15:13:54 -07007291 @Override
7292 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007293 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007294 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7295 return;
7296 }
7297
Svet Ganovcc087f82015-05-12 20:35:54 -07007298 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007299
Svet Ganovcc087f82015-05-12 20:35:54 -07007300 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007301 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7302 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007303 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007304 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007305 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007306 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007307 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7308 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007309 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007310 // There has been issues when Sms raw table somehow stores orphan
7311 // fragments. They lead to garbled message when new fragments come
7312 // in and combined with those stale ones. In case this happens again,
7313 // user can reset all network settings which will clean up this table.
7314 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007315 // Clean up IMS settings as well here.
7316 int slotId = getSlotIndex(subId);
7317 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7318 ImsManager.getInstance(mApp, slotId).factoryReset();
7319 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007320
7321 // Erase modem config if erase modem on network setting is enabled.
7322 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7323 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7324 if (configValue != null && Boolean.parseBoolean(configValue)) {
7325 sendEraseModemConfig(getDefaultPhone());
7326 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007327 } finally {
7328 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007329 }
7330 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007331
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007332 private void cleanUpSmsRawTable(Context context) {
7333 ContentResolver resolver = context.getContentResolver();
7334 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7335 resolver.delete(uri, null, null);
7336 }
7337
Narayan Kamath1c496c22015-04-16 14:40:19 +01007338 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007339 public String getSimLocaleForSubscriber(int subId) {
7340 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7341 final Phone phone = getPhone(subId);
7342 if (phone == null) {
7343 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007344 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007345 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007346 final long identity = Binder.clearCallingIdentity();
7347 try {
chen xu5d3637b2019-01-21 23:31:38 -08007348 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007349 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007350 if (info == null) {
7351 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7352 return null;
7353 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007354 // Try and fetch the locale from the carrier properties or from the SIM language
7355 // preferences (EF-PL and EF-LI)...
7356 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007357 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007358 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7359 if (localeFromDefaultSim != null) {
7360 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7361 if (DBG) log("Using locale from subId: " + subId + " locale: "
7362 + localeFromDefaultSim);
7363 return localeFromDefaultSim.toLanguageTag();
7364 } else {
7365 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 }
7367 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007368
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007369 // The SIM language preferences only store a language (e.g. fr = French), not an
7370 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7371 // the SIM and carrier preferences does not include a country we add the country
7372 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007373 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007374 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007375 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007376 return mccLocale.toLanguageTag();
7377 }
7378
7379 if (DBG) log("No locale found - returning null");
7380 return null;
7381 } finally {
7382 Binder.restoreCallingIdentity(identity);
7383 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007384 }
7385
7386 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007387 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007388 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007389 }
7390
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007391 /**
7392 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7393 */
7394 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007395 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007396 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007397 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007398
Chenjie Yu1ba97252018-01-11 18:16:20 -08007399 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007400 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007401
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007402 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007403 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7404 * representing the state of the modem.
7405 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007406 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7407 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007408 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007409 */
7410 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007411 public void requestModemActivityInfo(ResultReceiver result) {
7412 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007413 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007414
7415 final long identity = Binder.clearCallingIdentity();
7416 try {
sqian1a1be542020-03-05 11:37:28 -08007417 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007418 } finally {
7419 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007420 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007421 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007422
Siddharth Rayb8114062018-06-17 15:02:38 -07007423 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7424 // less than total activity duration.
7425 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7426 if (info == null) {
7427 return false;
7428 }
7429 int activityDurationMs =
7430 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7431 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007432 int[] txTimeMs = info.getTransmitTimeMillis();
7433 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7434 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007435 }
7436 return (info.isValid()
7437 && (info.getSleepTimeMillis() <= activityDurationMs)
7438 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007439 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007440 && (totalTxTimeMs <= activityDurationMs));
7441 }
7442
Jack Yu85bd38a2015-11-09 11:34:32 -08007443 /**
7444 * {@hide}
7445 * Returns the service state information on specified subscription.
7446 */
7447 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007448 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7449 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007450 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007451 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007452 return null;
7453 }
7454
Hall Liuf19c44f2018-11-27 14:38:17 -08007455 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7456 LocationAccessPolicy.checkLocationPermission(mApp,
7457 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7458 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007459 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007460 .setCallingPid(Binder.getCallingPid())
7461 .setCallingUid(Binder.getCallingUid())
7462 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007463 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007464 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7465 .build());
7466
7467 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7468 LocationAccessPolicy.checkLocationPermission(mApp,
7469 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7470 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007471 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007472 .setCallingPid(Binder.getCallingPid())
7473 .setCallingUid(Binder.getCallingUid())
7474 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007475 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007476 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7477 .build());
7478 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7479 boolean hasFinePermission =
7480 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7481 boolean hasCoarsePermission =
7482 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7483
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007484 final long identity = Binder.clearCallingIdentity();
7485 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007486 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7487 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7488 Rlog.d(LOG_TAG,
7489 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7490 return null;
7491 }
7492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007493 final Phone phone = getPhone(subId);
7494 if (phone == null) {
7495 return null;
7496 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007497
Hall Liuf19c44f2018-11-27 14:38:17 -08007498 ServiceState ss = phone.getServiceState();
7499
7500 // Scrub out the location info in ServiceState depending on what level of access
7501 // the caller has.
7502 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007503 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7504 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007505 } finally {
7506 Binder.restoreCallingIdentity(identity);
7507 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007508 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007509
7510 /**
7511 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7512 *
7513 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7514 * voicemail ringtone.
7515 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7516 * PhoneAccount.
7517 */
7518 @Override
7519 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007520 final long identity = Binder.clearCallingIdentity();
7521 try {
7522 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7523 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007524 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007526
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7528 } finally {
7529 Binder.restoreCallingIdentity(identity);
7530 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007531 }
7532
7533 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007534 * Sets the per-account voicemail ringtone.
7535 *
7536 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7537 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7538 *
7539 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7540 * voicemail ringtone.
7541 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7542 * PhoneAccount.
7543 */
7544 @Override
7545 public void setVoicemailRingtoneUri(String callingPackage,
7546 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007547 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007548 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007549 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7550 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7552 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7553 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007554 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007555
7556 final long identity = Binder.clearCallingIdentity();
7557 try {
7558 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7559 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007560 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007561 }
7562 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7563 } finally {
7564 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007565 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007566 }
7567
7568 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007569 * Returns whether vibration is set for voicemail notification in Phone settings.
7570 *
7571 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7572 * voicemail vibration setting.
7573 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7574 */
7575 @Override
7576 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007577 final long identity = Binder.clearCallingIdentity();
7578 try {
7579 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7580 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007581 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007582 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007583
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007584 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7585 } finally {
7586 Binder.restoreCallingIdentity(identity);
7587 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007588 }
7589
Youhan Wange64578a2016-05-02 15:32:42 -07007590 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007591 * Sets the per-account voicemail vibration.
7592 *
7593 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7594 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7595 *
7596 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7597 * voicemail vibration setting.
7598 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7599 * specific PhoneAccount.
7600 */
7601 @Override
7602 public void setVoicemailVibrationEnabled(String callingPackage,
7603 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007604 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007605 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007606 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7607 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7609 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7610 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007611 }
7612
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007613 final long identity = Binder.clearCallingIdentity();
7614 try {
7615 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7616 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007617 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007618 }
7619 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7620 } finally {
7621 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007622 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007623 }
7624
7625 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007626 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7627 *
7628 * @throws SecurityException if the caller does not have the required permission
7629 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007630 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007631 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007632 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007633 }
7634
7635 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007636 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7637 * permission.
7638 *
7639 * @throws SecurityException if the caller does not have the required permission
7640 */
7641 private void enforceSendSmsPermission() {
7642 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7643 }
7644
7645 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007646 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007647 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007648 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007649 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007650 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007651 final long identity = Binder.clearCallingIdentity();
7652 try {
7653 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007654 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007655 if (componentName == null) {
7656 throw new SecurityException(
7657 "Caller not current active visual voicemail package[null]");
7658 }
7659 String vvmPackage = componentName.getPackageName();
7660 if (!callingPackage.equals(vvmPackage)) {
7661 throw new SecurityException("Caller not current active visual voicemail package["
7662 + vvmPackage + "]");
7663 }
7664 } finally {
7665 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007666 }
7667 }
7668
7669 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007670 * Return the application ID for the app type.
7671 *
7672 * @param subId the subscription ID that this request applies to.
7673 * @param appType the uicc app type.
7674 * @return Application ID for specificied app type, or null if no uicc.
7675 */
7676 @Override
7677 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007678 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007679 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007680
7681 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007682 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007683 if (phone == null) {
7684 return null;
7685 }
7686 String aid = null;
7687 try {
7688 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7689 .getApplicationByType(appType).getAid();
7690 } catch (Exception e) {
7691 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7692 }
7693 return aid;
7694 } finally {
7695 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007696 }
Youhan Wange64578a2016-05-02 15:32:42 -07007697 }
7698
Youhan Wang4001d252016-05-11 10:29:41 -07007699 /**
7700 * Return the Electronic Serial Number.
7701 *
7702 * @param subId the subscription ID that this request applies to.
7703 * @return ESN or null if error.
7704 */
7705 @Override
7706 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007707 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007708 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007709
7710 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007711 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007712 if (phone == null) {
7713 return null;
7714 }
7715 String esn = null;
7716 try {
7717 esn = phone.getEsn();
7718 } catch (Exception e) {
7719 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7720 }
7721 return esn;
7722 } finally {
7723 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007724 }
Youhan Wang4001d252016-05-11 10:29:41 -07007725 }
7726
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007727 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007728 * Return the Preferred Roaming List Version.
7729 *
7730 * @param subId the subscription ID that this request applies to.
7731 * @return PRLVersion or null if error.
7732 */
7733 @Override
7734 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007735 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007736 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007737
7738 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007739 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007740 if (phone == null) {
7741 return null;
7742 }
7743 String cdmaPrlVersion = null;
7744 try {
7745 cdmaPrlVersion = phone.getCdmaPrlVersion();
7746 } catch (Exception e) {
7747 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7748 }
7749 return cdmaPrlVersion;
7750 } finally {
7751 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007752 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007753 }
7754
7755 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007756 * Get snapshot of Telephony histograms
7757 * @return List of Telephony histograms
7758 * @hide
7759 */
7760 @Override
7761 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007762 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7763 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007764
7765 final long identity = Binder.clearCallingIdentity();
7766 try {
7767 return RIL.getTelephonyRILTimingHistograms();
7768 } finally {
7769 Binder.restoreCallingIdentity(identity);
7770 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007771 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007772
7773 /**
7774 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007775 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7776 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007777 * Require system privileges. In the future we may add this to carrier APIs.
7778 *
Michele Berionne482f8202018-11-27 18:57:59 -08007779 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007780 */
7781 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007782 @TelephonyManager.SetCarrierRestrictionResult
7783 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007784 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007785 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007786
Michele Berionne482f8202018-11-27 18:57:59 -08007787 if (carrierRestrictionRules == null) {
7788 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007789 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007790
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007791 final long identity = Binder.clearCallingIdentity();
7792 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007793 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007794 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007795 } finally {
7796 Binder.restoreCallingIdentity(identity);
7797 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007798 }
7799
7800 /**
7801 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007802 * Get the allowed carrier list and the excluded carrier list, including the priority between
7803 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007804 * Require system privileges. In the future we may add this to carrier APIs.
7805 *
Michele Berionne482f8202018-11-27 18:57:59 -08007806 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007807 */
7808 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007809 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007810 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007811 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007812
7813 final long identity = Binder.clearCallingIdentity();
7814 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007815 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7816 if (response instanceof CarrierRestrictionRules) {
7817 return (CarrierRestrictionRules) response;
7818 }
7819 // Response is an Exception of some kind,
7820 // which is signalled to the user as a NULL retval
7821 return null;
7822 } catch (Exception e) {
7823 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7824 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007825 } finally {
7826 Binder.restoreCallingIdentity(identity);
7827 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007828 }
7829
fionaxu59545b42016-05-25 15:53:37 -07007830 /**
fionaxu59545b42016-05-25 15:53:37 -07007831 * Action set from carrier signalling broadcast receivers to enable/disable radio
7832 * @param subId the subscription ID that this action applies to.
7833 * @param enabled control enable or disable radio.
7834 * {@hide}
7835 */
7836 @Override
7837 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7838 enforceModifyPermission();
7839 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007840
7841 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007842 if (phone == null) {
7843 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7844 return;
7845 }
7846 try {
7847 phone.carrierActionSetRadioEnabled(enabled);
7848 } catch (Exception e) {
7849 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007850 } finally {
7851 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007852 }
7853 }
7854
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007855 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007856 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7857 * network status based on which carrier apps could apply actions accordingly,
7858 * enable/disable default url handler for example.
7859 *
7860 * @param subId the subscription ID that this action applies to.
7861 * @param report control start/stop reporting the default network status.
7862 * {@hide}
7863 */
7864 @Override
7865 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7866 enforceModifyPermission();
7867 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868
7869 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007870 if (phone == null) {
7871 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7872 return;
7873 }
7874 try {
7875 phone.carrierActionReportDefaultNetworkStatus(report);
7876 } catch (Exception e) {
7877 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007878 } finally {
7879 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007880 }
7881 }
7882
7883 /**
fionaxud9622282017-07-17 17:51:30 -07007884 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7885 * @param subId the subscription ID that this action applies to.
7886 * {@hide}
7887 */
7888 @Override
7889 public void carrierActionResetAll(int subId) {
7890 enforceModifyPermission();
7891 final Phone phone = getPhone(subId);
7892 if (phone == null) {
7893 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7894 return;
7895 }
7896 try {
7897 phone.carrierActionResetAll();
7898 } catch (Exception e) {
7899 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7900 }
7901 }
7902
7903 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007904 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7905 * bug report is being generated.
7906 */
7907 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007908 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007909 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7910 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007911 writer.println("Permission Denial: can't dump Phone from pid="
7912 + Binder.getCallingPid()
7913 + ", uid=" + Binder.getCallingUid()
7914 + "without permission "
7915 + android.Manifest.permission.DUMP);
7916 return;
7917 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007918 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007919 }
Jack Yueb89b242016-06-22 13:27:47 -07007920
Brad Ebingerdac2f002018-04-03 15:17:52 -07007921 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007922 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7923 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7924 @NonNull String[] args) {
7925 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7926 this, in.getFileDescriptor(), out.getFileDescriptor(),
7927 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007928 }
7929
Jack Yueb89b242016-06-22 13:27:47 -07007930 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007931 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007932 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007933 * @param reason the reason the data enable change is taking place
7934 * @param enabled True if enabling the data, otherwise disabling.
7935 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007936 */
7937 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007938 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007939 boolean enabled) {
7940 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7941 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7942 try {
7943 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007944 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007945 } catch (SecurityException se) {
7946 enforceModifyPermission();
7947 }
7948 } else {
7949 enforceModifyPermission();
7950 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007951
7952 final long identity = Binder.clearCallingIdentity();
7953 try {
7954 Phone phone = getPhone(subId);
7955 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007956 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7957 phone.carrierActionSetMeteredApnsEnabled(enabled);
7958 } else {
7959 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7960 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007961 }
7962 } finally {
7963 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007964 }
7965 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007966
7967 /**
7968 * Get Client request stats
7969 * @return List of Client Request Stats
7970 * @hide
7971 */
7972 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007973 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7974 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007975 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007976 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007977 return null;
7978 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007979 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007980
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007981 final long identity = Binder.clearCallingIdentity();
7982 try {
7983 if (phone != null) {
7984 return phone.getClientRequestStats();
7985 }
7986
7987 return null;
7988 } finally {
7989 Binder.restoreCallingIdentity(identity);
7990 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007991 }
7992
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007993 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007994 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007995 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007996 }
Jack Yueb4124c2017-02-16 15:32:43 -08007997
7998 /**
Grace Chen70990072017-03-24 17:21:30 -07007999 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008000 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008001 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008002 * @param state State of SIM (power down, power up, pass through)
8003 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8004 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8005 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008006 *
8007 **/
8008 @Override
Grace Chen70990072017-03-24 17:21:30 -07008009 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008010 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008011 Phone phone = PhoneFactory.getPhone(slotIndex);
8012
vagdeviaf9a5b92018-08-15 16:01:53 -07008013 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8014
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008015 final long identity = Binder.clearCallingIdentity();
8016 try {
8017 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08008018 phone.setSimPowerState(state, null, workSource);
8019 }
8020 } finally {
8021 Binder.restoreCallingIdentity(identity);
8022 }
8023 }
8024
8025 /**
8026 * Set SIM card power state.
8027 *
8028 * @param slotIndex SIM slot id.
8029 * @param state State of SIM (power down, power up, pass through)
8030 * @param callback callback to trigger after success or failure
8031 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8032 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8033 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8034 *
8035 **/
8036 @Override
8037 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8038 IIntegerConsumer callback) {
8039 enforceModifyPermission();
8040 Phone phone = PhoneFactory.getPhone(slotIndex);
8041
8042 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8043
8044 final long identity = Binder.clearCallingIdentity();
8045 try {
8046 if (phone != null) {
8047 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8048 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008049 }
8050 } finally {
8051 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008052 }
8053 }
Shuo Qiandd210312017-04-12 22:11:33 +00008054
Tyler Gunn65d45c22017-06-05 11:22:26 -07008055 private boolean isUssdApiAllowed(int subId) {
8056 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008057 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008058 if (configManager == null) {
8059 return false;
8060 }
8061 PersistableBundle pb = configManager.getConfigForSubId(subId);
8062 if (pb == null) {
8063 return false;
8064 }
8065 return pb.getBoolean(
8066 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8067 }
8068
Shuo Qiandd210312017-04-12 22:11:33 +00008069 /**
8070 * Check if phone is in emergency callback mode
8071 * @return true if phone is in emergency callback mode
8072 * @param subId sub id
8073 */
goneil9c5f4872017-12-05 14:07:56 -08008074 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008075 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008076 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008077 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008078
8079 final long identity = Binder.clearCallingIdentity();
8080 try {
8081 if (phone != null) {
8082 return phone.isInEcm();
8083 } else {
8084 return false;
8085 }
8086 } finally {
8087 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008088 }
8089 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008090
8091 /**
8092 * Get the current signal strength information for the given subscription.
8093 * Because this information is not updated when the device is in a low power state
8094 * it should not be relied-upon to be current.
8095 * @param subId Subscription index
8096 * @return the most recent cached signal strength info from the modem
8097 */
8098 @Override
8099 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008100 final long identity = Binder.clearCallingIdentity();
8101 try {
8102 Phone p = getPhone(subId);
8103 if (p == null) {
8104 return null;
8105 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008106
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008107 return p.getSignalStrength();
8108 } finally {
8109 Binder.restoreCallingIdentity(identity);
8110 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008111 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008112
Pengquan Meng77b7f132018-08-22 14:49:57 -07008113 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008114 * Get the current modem radio state for the given slot.
8115 * @param slotIndex slot index.
8116 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008117 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008118 * @return the current radio power state from the modem
8119 */
8120 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008121 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008122 Phone phone = PhoneFactory.getPhone(slotIndex);
8123 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008124 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8125 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008126 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8127 }
8128
8129 final long identity = Binder.clearCallingIdentity();
8130 try {
8131 return phone.getRadioPowerState();
8132 } finally {
8133 Binder.restoreCallingIdentity(identity);
8134 }
8135 }
8136 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8137 }
8138
8139 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008140 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8141 *
8142 * <p>Requires one of the following permissions:
8143 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8144 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8145 * privileges.
8146 *
8147 * @param subId subscription id
8148 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8149 * {@code false}.
8150 */
8151 @Override
8152 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008153 try {
8154 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8155 null);
8156 } catch (Exception e) {
8157 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8158 mApp, subId, "isDataRoamingEnabled");
8159 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008160
Pengquan Menga1bb6272018-09-06 09:59:22 -07008161 boolean isEnabled = false;
8162 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008163 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008164 Phone phone = getPhone(subId);
8165 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008166 } finally {
8167 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008168 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008169 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008170 }
8171
8172
8173 /**
8174 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8175 *
8176 * <p> Requires permission:
8177 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8178 * privileges.
8179 *
8180 * @param subId subscription id
8181 * @param isEnabled {@code true} means enable, {@code false} means disable.
8182 */
8183 @Override
8184 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008185 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8186 mApp, subId, "setDataRoamingEnabled");
8187
Pengquan Menga1bb6272018-09-06 09:59:22 -07008188 final long identity = Binder.clearCallingIdentity();
8189 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008190 Phone phone = getPhone(subId);
8191 if (phone != null) {
8192 phone.setDataRoamingEnabled(isEnabled);
8193 }
8194 } finally {
8195 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008196 }
8197 }
8198
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008199 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008200 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008201 TelephonyPermissions
8202 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008203 mApp, subId, "isManualNetworkSelectionAllowed");
8204
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008205 boolean isAllowed = true;
8206 final long identity = Binder.clearCallingIdentity();
8207 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008208 Phone phone = getPhone(subId);
8209 if (phone != null) {
8210 isAllowed = phone.isCspPlmnEnabled();
8211 }
8212 } finally {
8213 Binder.restoreCallingIdentity(identity);
8214 }
8215 return isAllowed;
8216 }
8217
8218 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008219 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008220 // Verify that tha callingPackage belongs to the calling UID
8221 mApp.getSystemService(AppOpsManager.class)
8222 .checkPackage(Binder.getCallingUid(), callingPackage);
8223
Jordan Liu1e142fc2019-04-22 15:10:43 -07008224 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008225 try {
8226 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008227 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008228 } catch (SecurityException e) {
8229 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8230 // has carrier privileges on an active UICC
8231 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8232 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008233 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008234 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008235 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008236
8237 final long identity = Binder.clearCallingIdentity();
8238 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008239 UiccController uiccController = UiccController.getInstance();
8240 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008241 if (hasReadPermission) {
8242 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008243 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008244
8245 // Remove private info if the caller doesn't have access
8246 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8247 for (UiccCardInfo cardInfo : cardInfos) {
8248 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8249 // is available
8250 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8251 if (card == null || card.getUiccProfile() == null) {
8252 // assume no access if the card or profile is unavailable
8253 filteredInfos.add(cardInfo.getUnprivileged());
8254 continue;
8255 }
8256 UiccProfile profile = card.getUiccProfile();
8257 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8258 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8259 filteredInfos.add(cardInfo);
8260 } else {
8261 filteredInfos.add(cardInfo.getUnprivileged());
8262 }
8263 }
8264 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008265 } finally {
8266 Binder.restoreCallingIdentity(identity);
8267 }
8268 }
8269
8270 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008271 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008272 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008273
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008274 final long identity = Binder.clearCallingIdentity();
8275 try {
8276 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8277 if (slots == null) {
8278 Rlog.i(LOG_TAG, "slots is null.");
8279 return null;
8280 }
8281
8282 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8283 for (int i = 0; i < slots.length; i++) {
8284 UiccSlot slot = slots[i];
8285 if (slot == null) {
8286 continue;
8287 }
8288
Jordan Liu7be7e652019-05-06 18:55:02 +00008289 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008290 UiccCard card = slot.getUiccCard();
8291 if (card != null) {
8292 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008293 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008294 cardId = slot.getEid();
8295 if (TextUtils.isEmpty(cardId)) {
8296 cardId = slot.getIccId();
8297 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008298 }
8299
Jordan Liu857451f2019-05-09 16:35:35 -07008300 if (cardId != null) {
8301 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8302 // if cardId is an EID, it's all digits so this is fine
8303 cardId = IccUtils.stripTrailingFs(cardId);
8304 }
8305
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008306 int cardState = 0;
8307 switch (slot.getCardState()) {
8308 case CARDSTATE_ABSENT:
8309 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8310 break;
8311 case CARDSTATE_PRESENT:
8312 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8313 break;
8314 case CARDSTATE_ERROR:
8315 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8316 break;
8317 case CARDSTATE_RESTRICTED:
8318 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8319 break;
8320 default:
8321 break;
8322
8323 }
8324
8325 infos[i] = new UiccSlotInfo(
8326 slot.isActive(),
8327 slot.isEuicc(),
8328 cardId,
8329 cardState,
8330 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008331 slot.isExtendedApduSupported(),
8332 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008333 }
8334 return infos;
8335 } finally {
8336 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008337 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008338 }
8339
8340 @Override
8341 public boolean switchSlots(int[] physicalSlots) {
8342 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008343
8344 final long identity = Binder.clearCallingIdentity();
8345 try {
8346 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8347 } finally {
8348 Binder.restoreCallingIdentity(identity);
8349 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008350 }
Jack Yu4c988042018-02-27 15:30:01 -08008351
8352 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008353 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008354 final long identity = Binder.clearCallingIdentity();
8355 try {
8356 return UiccController.getInstance().getCardIdForDefaultEuicc();
8357 } finally {
8358 Binder.restoreCallingIdentity(identity);
8359 }
8360 }
8361
Pengquan Meng85728fb2018-03-12 16:31:21 -07008362 /**
goneil47ffb6e2018-04-06 15:40:58 -07008363 * A test API to reload the UICC profile.
8364 *
8365 * <p>Requires that the calling app has permission
8366 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8367 * @hide
8368 */
8369 @Override
8370 public void refreshUiccProfile(int subId) {
8371 enforceModifyPermission();
8372
8373 final long identity = Binder.clearCallingIdentity();
8374 try {
8375 Phone phone = getPhone(subId);
8376 if (phone == null) {
8377 return;
8378 }
8379 UiccCard uiccCard = phone.getUiccCard();
8380 if (uiccCard == null) {
8381 return;
8382 }
8383 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8384 if (uiccProfile == null) {
8385 return;
8386 }
8387 uiccProfile.refresh();
8388 } finally {
8389 Binder.restoreCallingIdentity(identity);
8390 }
8391 }
8392
8393 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008394 * Returns false if the mobile data is disabled by default, otherwise return true.
8395 */
8396 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008397 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008398 }
8399
8400 /**
8401 * Returns true if the data roaming is enabled by default, i.e the system property
8402 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8403 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8404 */
8405 private boolean getDefaultDataRoamingEnabled(int subId) {
8406 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008407 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008408 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008409 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8410 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8411 return isDataRoamingEnabled;
8412 }
8413
8414 /**
8415 * Returns the default network type for the given {@code subId}, if the default network type is
8416 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8417 */
8418 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008419 List<Integer> list = TelephonyProperties.default_network();
8420 int phoneId = mSubscriptionController.getPhoneId(subId);
8421 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8422 return list.get(phoneId);
8423 }
8424 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008425 }
fionaxua13278b2018-03-21 00:08:13 -07008426
8427 @Override
8428 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008429 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008430 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008431
8432 final long identity = Binder.clearCallingIdentity();
8433 try {
8434 final Phone phone = getPhone(subId);
8435 if (phone == null) {
8436 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8437 return;
8438 }
chen xueaba88a2019-03-15 13:15:10 -07008439 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8440 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008441 if (carrierPrivilegeRules == null) {
8442 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8443 } else {
8444 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8445 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008446 } finally {
8447 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008448 }
fionaxua13278b2018-03-21 00:08:13 -07008449 }
8450
8451 @Override
8452 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008453 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008454
8455 final long identity = Binder.clearCallingIdentity();
8456 try {
8457 final Phone phone = getPhone(subId);
8458 if (phone == null) {
8459 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8460 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8461 }
8462 return phone.getCarrierIdListVersion();
8463 } finally {
8464 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008465 }
fionaxua13278b2018-03-21 00:08:13 -07008466 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008467
8468 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008469 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8470 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008471 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008472 mApp, subId, callingPackage, callingFeatureId,
8473 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008474 return -1;
8475 }
8476
8477 final long identity = Binder.clearCallingIdentity();
8478 try {
8479 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8480 } finally {
8481 Binder.restoreCallingIdentity(identity);
8482 }
8483 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008484
8485 @Override
8486 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008487 TelephonyPermissions
8488 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008489 mApp, subId, "getCdmaRoamingMode");
8490
8491 final long identity = Binder.clearCallingIdentity();
8492 try {
8493 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8494 } finally {
8495 Binder.restoreCallingIdentity(identity);
8496 }
8497 }
8498
8499 @Override
8500 public boolean setCdmaRoamingMode(int subId, int mode) {
8501 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8502 mApp, subId, "setCdmaRoamingMode");
8503
8504 final long identity = Binder.clearCallingIdentity();
8505 try {
8506 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8507 } finally {
8508 Binder.restoreCallingIdentity(identity);
8509 }
8510 }
8511
8512 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008513 public int getCdmaSubscriptionMode(int subId) {
8514 TelephonyPermissions
8515 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8516 mApp, subId, "getCdmaSubscriptionMode");
8517
8518 final long identity = Binder.clearCallingIdentity();
8519 try {
8520 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8521 } finally {
8522 Binder.restoreCallingIdentity(identity);
8523 }
8524 }
8525
8526 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008527 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8529 mApp, subId, "setCdmaSubscriptionMode");
8530
8531 final long identity = Binder.clearCallingIdentity();
8532 try {
8533 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8534 } finally {
8535 Binder.restoreCallingIdentity(identity);
8536 }
8537 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008538
sqianc5eccab2018-10-19 18:46:41 -07008539 @Override
sqian8c685422019-02-22 15:55:18 -08008540 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008541 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008542 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008543 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8544 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008545 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8546 }
8547 final long identity = Binder.clearCallingIdentity();
8548 try {
sqian854d44b2018-12-12 16:48:18 -08008549 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8550 for (Phone phone: PhoneFactory.getPhones()) {
8551 if (phone.getEmergencyNumberTracker() != null
8552 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8553 emergencyNumberListInternal.put(
8554 phone.getSubId(),
8555 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8556 }
sqian11b7a0e2018-12-05 18:48:28 -08008557 }
sqian854d44b2018-12-12 16:48:18 -08008558 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008559 } finally {
8560 Binder.restoreCallingIdentity(identity);
8561 }
sqianc5eccab2018-10-19 18:46:41 -07008562 }
8563
8564 @Override
sqian8c685422019-02-22 15:55:18 -08008565 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008566 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008567 if (!exactMatch) {
8568 TelephonyPermissions
8569 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008570 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008571 }
8572 final long identity = Binder.clearCallingIdentity();
8573 try {
sqian854d44b2018-12-12 16:48:18 -08008574 for (Phone phone: PhoneFactory.getPhones()) {
8575 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008576 && phone.getEmergencyNumberTracker()
8577 .isEmergencyNumber(number, exactMatch)) {
8578 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008579 }
sqian11b7a0e2018-12-05 18:48:28 -08008580 }
8581 return false;
8582 } finally {
8583 Binder.restoreCallingIdentity(identity);
8584 }
8585 }
8586
sqianf4ca7ed2019-01-15 18:32:07 -08008587 /**
8588 * Update emergency number list for test mode.
8589 */
8590 @Override
8591 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8592 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8593 "updateEmergencyNumberListTestMode");
8594
8595 final long identity = Binder.clearCallingIdentity();
8596 try {
8597 for (Phone phone: PhoneFactory.getPhones()) {
8598 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8599 if (tracker != null) {
8600 tracker.executeEmergencyNumberTestModeCommand(action, num);
8601 }
8602 }
8603 } finally {
8604 Binder.restoreCallingIdentity(identity);
8605 }
8606 }
8607
8608 /**
8609 * Get the full emergency number list for test mode.
8610 */
8611 @Override
8612 public List<String> getEmergencyNumberListTestMode() {
8613 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8614 "getEmergencyNumberListTestMode");
8615
8616 final long identity = Binder.clearCallingIdentity();
8617 try {
8618 Set<String> emergencyNumbers = new HashSet<>();
8619 for (Phone phone: PhoneFactory.getPhones()) {
8620 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8621 if (tracker != null) {
8622 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8623 emergencyNumbers.add(num.getNumber());
8624 }
8625 }
8626 }
8627 return new ArrayList<>(emergencyNumbers);
8628 } finally {
8629 Binder.restoreCallingIdentity(identity);
8630 }
8631 }
8632
chen xud6b45bd2018-10-30 22:27:10 -07008633 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008634 public int getEmergencyNumberDbVersion(int subId) {
8635 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8636
8637 final long identity = Binder.clearCallingIdentity();
8638 try {
8639 final Phone phone = getPhone(subId);
8640 if (phone == null) {
8641 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8642 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8643 }
8644 return phone.getEmergencyNumberDbVersion();
8645 } finally {
8646 Binder.restoreCallingIdentity(identity);
8647 }
8648 }
8649
8650 @Override
8651 public void notifyOtaEmergencyNumberDbInstalled() {
8652 enforceModifyPermission();
8653
8654 final long identity = Binder.clearCallingIdentity();
8655 try {
8656 for (Phone phone: PhoneFactory.getPhones()) {
8657 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8658 if (tracker != null) {
8659 tracker.updateOtaEmergencyNumberDatabase();
8660 }
8661 }
8662 } finally {
8663 Binder.restoreCallingIdentity(identity);
8664 }
8665 }
8666
8667 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008668 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008669 enforceActiveEmergencySessionPermission();
8670
8671 final long identity = Binder.clearCallingIdentity();
8672 try {
8673 for (Phone phone: PhoneFactory.getPhones()) {
8674 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8675 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008676 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8677 }
8678 }
8679 } finally {
8680 Binder.restoreCallingIdentity(identity);
8681 }
8682 }
8683
8684 @Override
8685 public void resetOtaEmergencyNumberDbFilePath() {
8686 enforceActiveEmergencySessionPermission();
8687
8688 final long identity = Binder.clearCallingIdentity();
8689 try {
8690 for (Phone phone: PhoneFactory.getPhones()) {
8691 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8692 if (tracker != null) {
8693 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008694 }
8695 }
8696 } finally {
8697 Binder.restoreCallingIdentity(identity);
8698 }
8699 }
8700
8701 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008702 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8703 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8704 Phone phone = getPhone(subId);
8705 if (phone == null) {
8706 return null;
8707 }
8708 final long identity = Binder.clearCallingIdentity();
8709 try {
8710 UiccProfile profile = UiccController.getInstance()
8711 .getUiccProfileForPhone(phone.getPhoneId());
8712 if (profile != null) {
8713 return profile.getCertsFromCarrierPrivilegeAccessRules();
8714 }
8715 } finally {
8716 Binder.restoreCallingIdentity(identity);
8717 }
8718 return null;
8719 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008720
8721 /**
8722 * Enable or disable a modem stack.
8723 */
8724 @Override
8725 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8726 enforceModifyPermission();
8727
8728 final long identity = Binder.clearCallingIdentity();
8729 try {
8730 Phone phone = PhoneFactory.getPhone(slotIndex);
8731 if (phone == null) {
8732 return false;
8733 } else {
8734 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8735 }
8736 } finally {
8737 Binder.restoreCallingIdentity(identity);
8738 }
8739 }
Michelecea4cf22018-12-21 15:00:11 -08008740
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008741 /**
8742 * Whether a modem stack is enabled or not.
8743 */
8744 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008745 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8746 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008747 Phone phone = PhoneFactory.getPhone(slotIndex);
8748 if (phone == null) return false;
8749
8750 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008751 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8752 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008753 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8754 }
8755
8756 final long identity = Binder.clearCallingIdentity();
8757 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008758 try {
8759 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8760 } catch (NoSuchElementException ex) {
8761 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8762 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008763 } finally {
8764 Binder.restoreCallingIdentity(identity);
8765 }
8766 }
8767
Michelecea4cf22018-12-21 15:00:11 -08008768 @Override
Michele0ea7d782019-03-19 14:58:42 -07008769 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008770 enforceModifyPermission();
8771
8772 final long identity = Binder.clearCallingIdentity();
8773 try {
8774 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008775 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008776 .commit();
8777 } finally {
8778 Binder.restoreCallingIdentity(identity);
8779 }
8780 }
8781
8782 @Override
Michele0ea7d782019-03-19 14:58:42 -07008783 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008784 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008785 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008786 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8787 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008788 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008789 }
Michelecea4cf22018-12-21 15:00:11 -08008790
8791 final long identity = Binder.clearCallingIdentity();
8792 try {
Michele0ea7d782019-03-19 14:58:42 -07008793 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008794 } finally {
8795 Binder.restoreCallingIdentity(identity);
8796 }
8797 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008798
Michele0ea7d782019-03-19 14:58:42 -07008799 @TelephonyManager.IsMultiSimSupportedResult
8800 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008801 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8802 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8803 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008804 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8805 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008806 }
8807 // Check if the hardware supports multisim functionality. If usage of multisim is not
8808 // supported by the modem, indicate that it is restricted.
8809 PhoneCapability staticCapability =
8810 mPhoneConfigurationManager.getStaticPhoneCapability();
8811 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008812 loge("isMultiSimSupportedInternal: no static configuration available");
8813 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008814 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008815 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008816 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8817 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008818 }
8819 // Check if support of multiple SIMs is restricted by carrier
8820 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008821 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008822 }
8823
Michele0ea7d782019-03-19 14:58:42 -07008824 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008825 }
8826
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008827 /**
8828 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008829 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8830 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8831 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008832 * @param numOfSims number of active sims we want to switch to
8833 */
8834 @Override
8835 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008836 if (numOfSims == 1) {
8837 enforceModifyPermission();
8838 } else {
8839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8840 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8841 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008842 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008843
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008844 try {
Michele30b57b22019-03-01 12:01:14 -08008845 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008846 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008847 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8848 return;
8849 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008850 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8851 } finally {
8852 Binder.restoreCallingIdentity(identity);
8853 }
8854 }
8855
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008856 @Override
8857 public boolean isApplicationOnUicc(int subId, int appType) {
8858 enforceReadPrivilegedPermission("isApplicationOnUicc");
8859 Phone phone = getPhone(subId);
8860 if (phone == null) {
8861 return false;
8862 }
8863 final long identity = Binder.clearCallingIdentity();
8864 try {
8865 UiccCard uiccCard = phone.getUiccCard();
8866 if (uiccCard == null) {
8867 return false;
8868 }
8869 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8870 if (uiccProfile == null) {
8871 return false;
8872 }
8873 if (TelephonyManager.APPTYPE_SIM <= appType
8874 && appType <= TelephonyManager.APPTYPE_ISIM) {
8875 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8876 }
8877 return false;
8878 } finally {
8879 Binder.restoreCallingIdentity(identity);
8880 }
8881 }
8882
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008883 /**
chen xub4baa772019-04-03 10:23:41 -07008884 * Get whether making changes to modem configurations will trigger reboot.
8885 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008886 */
8887 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008888 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8889 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008890 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008891 mApp, subId, callingPackage, callingFeatureId,
8892 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008893 return false;
8894 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008895 final long identity = Binder.clearCallingIdentity();
8896 try {
8897 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8898 } finally {
8899 Binder.restoreCallingIdentity(identity);
8900 }
8901 }
8902
Nathan Harold29f5f052019-02-15 13:41:57 -08008903 private void updateModemStateMetrics() {
8904 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8905 // TODO: check the state for each modem if the api is ready.
8906 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8907 }
8908
Pengquan Meng3889a572019-01-23 11:16:29 -08008909 @Override
8910 public int[] getSlotsMapping() {
8911 enforceReadPrivilegedPermission("getSlotsMapping");
8912
8913 final long identity = Binder.clearCallingIdentity();
8914 try {
8915 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8916 // All logical slots should have a mapping to a physical slot.
8917 int[] logicalSlotsMapping = new int[phoneCount];
8918 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8919 for (int i = 0; i < slotInfos.length; i++) {
8920 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8921 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8922 }
8923 }
8924 return logicalSlotsMapping;
8925 } finally {
8926 Binder.restoreCallingIdentity(identity);
8927 }
8928 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008929
8930 /**
8931 * Get the IRadio HAL Version
8932 */
8933 @Override
8934 public int getRadioHalVersion() {
8935 Phone phone = getDefaultPhone();
8936 if (phone == null) return -1;
8937 HalVersion hv = phone.getHalVersion();
8938 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8939 return hv.major * 100 + hv.minor;
8940 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008941
8942 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008943 * Get the current calling package name.
8944 * @return the current calling package name
8945 */
8946 @Override
8947 public String getCurrentPackageName() {
8948 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8949 }
8950
8951 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008952 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8953 * corresponding network requests on a subId.
8954 *
8955 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008956 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008957 * 2) APN is un-metered for this subscription, or
8958 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008959 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008960 *
8961 * @return whether data is allowed for a apn type.
8962 *
8963 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008964 */
8965 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008966 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008967 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8968 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008969
8970 // Now that all security checks passes, perform the operation as ourselves.
8971 final long identity = Binder.clearCallingIdentity();
8972 try {
8973 Phone phone = getPhone(subId);
8974 if (phone == null) return false;
8975
Jack Yu41407ee2019-05-13 16:54:09 -07008976 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008977 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8978 } finally {
8979 Binder.restoreCallingIdentity(identity);
8980 }
8981 }
8982
8983 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008984 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008985 enforceReadPrivilegedPermission("isApnMetered");
8986
8987 // Now that all security checks passes, perform the operation as ourselves.
8988 final long identity = Binder.clearCallingIdentity();
8989 try {
8990 Phone phone = getPhone(subId);
8991 if (phone == null) return true; // By default return true.
8992
Jack Yu41407ee2019-05-13 16:54:09 -07008993 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008994 } finally {
8995 Binder.restoreCallingIdentity(identity);
8996 }
8997 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008998
8999 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08009000 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9001 int subscriptionId, IBooleanConsumer resultCallback) {
9002 enforceModifyPermission();
9003 long token = Binder.clearCallingIdentity();
9004 try {
9005 Phone phone = getPhone(subscriptionId);
9006 if (phone == null) {
9007 try {
9008 if (resultCallback != null) {
9009 resultCallback.accept(false);
9010 }
9011 } catch (RemoteException e) {
9012 // ignore
9013 }
9014 return;
9015 }
9016 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9017 Pair.create(specifiers, (x) -> {
9018 try {
9019 if (resultCallback != null) {
9020 resultCallback.accept(x);
9021 }
9022 } catch (RemoteException e) {
9023 // ignore
9024 }
9025 });
9026 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9027 } finally {
9028 Binder.restoreCallingIdentity(token);
9029 }
9030 }
9031
9032 @Override
Sarah Chincc055732020-11-18 13:39:35 -08009033 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9034 TelephonyPermissions
9035 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9036 mApp, subId, "getSystemSelectionChannels");
9037 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9038 final long identity = Binder.clearCallingIdentity();
9039 try {
9040 List<RadioAccessSpecifier> specifiers =
9041 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9042 null, subId, workSource);
9043 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9044 return specifiers;
9045 } finally {
9046 Binder.restoreCallingIdentity(identity);
9047 }
9048 }
9049
9050 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009051 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009052 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009053 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9054 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9055 if (iccRecords == null) {
9056 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9057 return false;
9058 }
9059 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9060 }
9061
9062 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009063 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9064 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009065 if (callingPackage == null) {
9066 callingPackage = getCurrentPackageName();
9067 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009068 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9069 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009070 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9071 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009072 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9073 }
9074 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9075 Intent intent = new Intent();
9076 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9077 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9078 // Bring up choose default SMS subscription dialog right now
9079 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9080 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9081 mApp.startActivity(intent);
9082 }
chen xud5ca2d52019-05-28 15:20:57 -07009083
9084 @Override
9085 public String getMmsUAProfUrl(int subId) {
9086 //TODO investigate if this API should require proper permission check in R b/133791609
9087 final long identity = Binder.clearCallingIdentity();
9088 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009089 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9090 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9091 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9092 return carrierUAProfUrl;
9093 }
chen xud5ca2d52019-05-28 15:20:57 -07009094 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9095 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9096 } finally {
9097 Binder.restoreCallingIdentity(identity);
9098 }
9099 }
9100
9101 @Override
9102 public String getMmsUserAgent(int subId) {
9103 //TODO investigate if this API should require proper permission check in R b/133791609
9104 final long identity = Binder.clearCallingIdentity();
9105 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009106 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9107 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9108 if (!TextUtils.isEmpty(carrierUserAgent)) {
9109 return carrierUserAgent;
9110 }
chen xud5ca2d52019-05-28 15:20:57 -07009111 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9112 .getString(com.android.internal.R.string.config_mms_user_agent);
9113 } finally {
9114 Binder.restoreCallingIdentity(identity);
9115 }
9116 }
Jack Yub07d4972019-05-28 16:12:25 -07009117
9118 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009119 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9120 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9121
9122 final long identity = Binder.clearCallingIdentity();
9123 try {
9124 Phone phone = getPhone(subscriptionId);
9125 if (phone == null) return false;
9126
9127 switch (policy) {
9128 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9129 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9130 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9131 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9132 default:
9133 throw new IllegalArgumentException(policy + " is not a valid policy");
9134 }
9135 } finally {
9136 Binder.restoreCallingIdentity(identity);
9137 }
9138 }
9139
9140 @Override
9141 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9142 boolean enabled) {
9143 enforceModifyPermission();
9144
9145 final long identity = Binder.clearCallingIdentity();
9146 try {
9147 Phone phone = getPhone(subscriptionId);
9148 if (phone == null) return;
9149
9150 switch (policy) {
9151 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9152 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9153 break;
9154 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9155 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9156 break;
9157 default:
9158 throw new IllegalArgumentException(policy + " is not a valid policy");
9159 }
9160 } finally {
9161 Binder.restoreCallingIdentity(identity);
9162 }
9163 }
9164
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009165 /**
Hall Liub48cf452020-09-25 11:13:49 -07009166 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009167 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9168 * otherwise.
9169 */
9170 @Override
9171 public void setCepEnabled(boolean isCepEnabled) {
9172 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9173
9174 final long identity = Binder.clearCallingIdentity();
9175 try {
9176 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9177 for (Phone phone : PhoneFactory.getPhones()) {
9178 Phone defaultPhone = phone.getImsPhone();
9179 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9180 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9181 ImsPhoneCallTracker imsPhoneCallTracker =
9182 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9183 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9184 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9185 + imsPhone.getMsisdn());
9186 }
9187 }
9188 } finally {
9189 Binder.restoreCallingIdentity(identity);
9190 }
9191 }
allenwtsu46dcc572020-01-08 18:24:03 +08009192
9193 /**
9194 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9195 *
9196 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9197 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9198 * before being read.
9199 */
9200 @Override
9201 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9202 isCompressed) {
9203 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9204 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009205 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9206 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9207 }
9208 if (!isImsAvailableOnDevice()) {
9209 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9210 "IMS not available on device.");
9211 }
9212
9213 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009214 try {
Hui Wang068ab862020-10-31 05:12:53 +00009215 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9216 } finally {
9217 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009218 }
9219 }
zoey chenf95ca592019-12-30 16:11:23 +08009220
9221 @Override
9222 public boolean isIccLockEnabled(int subId) {
9223 enforceReadPrivilegedPermission("isIccLockEnabled");
9224
9225 // Now that all security checks passes, perform the operation as ourselves.
9226 final long identity = Binder.clearCallingIdentity();
9227 try {
9228 Phone phone = getPhone(subId);
9229 if (phone != null && phone.getIccCard() != null) {
9230 return phone.getIccCard().getIccLockEnabled();
9231 } else {
9232 return false;
9233 }
9234 } finally {
9235 Binder.restoreCallingIdentity(identity);
9236 }
9237 }
9238
9239 /**
zoey chene02881a2019-12-30 16:11:23 +08009240 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009241 *
zoey chene02881a2019-12-30 16:11:23 +08009242 * @return an integer representing the status of IccLock enabled or disabled in the following
9243 * three cases:
9244 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9245 * successfully.
9246 * - Positive number and zero for remaining password attempts.
9247 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009248 *
9249 */
9250 @Override
9251 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9252 enforceModifyPermission();
9253
9254 Phone phone = getPhone(subId);
9255 if (phone == null) {
9256 return 0;
9257 }
9258 // Now that all security checks passes, perform the operation as ourselves.
9259 final long identity = Binder.clearCallingIdentity();
9260 try {
9261 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9262 new Pair<Boolean, String>(enabled, password), phone, null);
9263 return attemptsRemaining;
9264
9265 } catch (Exception e) {
9266 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9267 } finally {
9268 Binder.restoreCallingIdentity(identity);
9269 }
9270 return 0;
9271 }
9272
9273 /**
9274 * Change the ICC password used in ICC pin lock.
9275 *
zoey chene02881a2019-12-30 16:11:23 +08009276 * @return an integer representing the status of IccLock changed in the following three cases:
9277 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9278 * - Positive number and zero for remaining password attempts.
9279 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009280 *
9281 */
9282 @Override
9283 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9284 enforceModifyPermission();
9285
9286 Phone phone = getPhone(subId);
9287 if (phone == null) {
9288 return 0;
9289 }
9290 // Now that all security checks passes, perform the operation as ourselves.
9291 final long identity = Binder.clearCallingIdentity();
9292 try {
9293 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9294 new Pair<String, String>(oldPassword, newPassword), phone, null);
9295 return attemptsRemaining;
9296
9297 } catch (Exception e) {
9298 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9299 } finally {
9300 Binder.restoreCallingIdentity(identity);
9301 }
9302 return 0;
9303 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009304
Peter Wangdafb9ac2020-01-15 14:13:38 -08009305 /**
9306 * Request for receiving user activity notification
9307 */
9308 @Override
9309 public void requestUserActivityNotification() {
9310 if (!mNotifyUserActivity.get()
9311 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9312 mNotifyUserActivity.set(true);
9313 }
9314 }
9315
9316 /**
9317 * Called when userActivity is signalled in the power manager.
9318 * This is safe to call from any thread, with any window manager locks held or not.
9319 */
9320 @Override
9321 public void userActivity() {
9322 // ***************************************
9323 // * Inherited from PhoneWindowManager *
9324 // ***************************************
9325 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9326 // WITH ITS LOCKS HELD.
9327 //
9328 // This code must be VERY careful about the locks
9329 // it acquires.
9330 // In fact, the current code acquires way too many,
9331 // and probably has lurking deadlocks.
9332
9333 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9334 throw new SecurityException("Only the OS may call notifyUserActivity()");
9335 }
9336
9337 if (mNotifyUserActivity.getAndSet(false)) {
9338 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9339 USER_ACTIVITY_NOTIFICATION_DELAY);
9340 }
9341 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009342
Malcolm Chen884180b2020-04-13 11:59:40 -07009343 @Override
9344 public boolean canConnectTo5GInDsdsMode() {
9345 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9346 }
Jack Yud10cdd42020-09-28 20:28:01 -07009347
9348 @Override
9349 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9350 String callingFeatureId) {
9351 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9352 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9353 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9354 }
9355
9356 Phone phone = getPhone(subId);
9357 if (phone == null) {
9358 throw new RuntimeException("phone is not available");
9359 }
9360 // Now that all security checks passes, perform the operation as ourselves.
9361 final long identity = Binder.clearCallingIdentity();
9362 try {
9363 return phone.getEquivalentHomePlmns();
9364 } finally {
9365 Binder.restoreCallingIdentity(identity);
9366 }
9367 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009368
Hui Wang0866fcc2020-10-12 12:14:23 -07009369 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009370 public boolean isRadioInterfaceCapabilitySupported(
9371 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9372 RadioInterfaceCapabilities radioInterfaceCapabilities =
9373 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9374 if (radioInterfaceCapabilities == null) {
9375 throw new RuntimeException("radio interface capabilities are not available");
9376 } else {
9377 return radioInterfaceCapabilities.isSupported(capability);
9378 }
9379 }
9380
9381 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009382 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9383 UaSecurityProtocolIdentifier securityProtocol,
9384 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9385 throws RemoteException {
9386 enforceModifyPermission();
9387 if (DBG) {
9388 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9389 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9390 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9391 }
9392
9393 if (!SubscriptionManager.isValidSubscriptionId(subId)
9394 || appType < TelephonyManager.APPTYPE_UNKNOWN
9395 || appType > TelephonyManager.APPTYPE_ISIM
9396 || nafUrl == null || securityProtocol == null || callback == null) {
9397 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9398 if (callback != null) {
9399 try {
9400 callback.onAuthenticationFailure(
9401 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9402 } catch (RemoteException exception) {
9403 log("Fail to notify onAuthenticationFailure due to " + exception);
9404 }
9405 return;
9406 }
9407 }
9408
9409 final long token = Binder.clearCallingIdentity();
9410 try {
9411 getGbaManager(subId).bootstrapAuthenticationRequest(
9412 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9413 forceBootStrapping, callback));
9414 } finally {
9415 Binder.restoreCallingIdentity(token);
9416 }
9417 }
9418
Jack Nudelman24d51a52020-11-24 12:08:04 -08009419 /**
9420 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9421 * requested radio power state will actually be set. See {@link
9422 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9423 *
9424 * @param subId the subscription ID of the phone requesting to set the radio power state.
9425 * @param enable {@code true} if trying to turn radio on.
9426 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9427 * false}.
9428 */
9429 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9430 Phone phone = getPhone(subId);
9431 if (phone != null) {
9432 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9433 return true;
9434 }
9435 return false;
9436 }
9437
9438 private int handleDataThrottlingRequest(int subId,
9439 DataThrottlingRequest dataThrottlingRequest) {
9440 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9441 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9442 if (!setRadioPowerForThermal(subId, true)) {
9443 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9444 }
9445
9446 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9447
9448 int thermalMitigationResult =
9449 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9450 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9451 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9452 }
9453 return thermalMitigationResult;
9454 }
9455
9456 /**
9457 * Thermal mitigation request to control functionalities at modem.
9458 *
9459 * @param subId the id of the subscription.
9460 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9461 *
9462 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9463 */
9464 @Override
9465 @ThermalMitigationResult
9466 public int sendThermalMitigationRequest(
9467 int subId,
9468 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9469 enforceModifyPermission();
9470
9471 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9472 final long identity = Binder.clearCallingIdentity();
9473
9474 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9475 try {
9476 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9477 switch (thermalMitigationAction) {
9478 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9479 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009480 handleDataThrottlingRequest(subId,
9481 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009482 break;
9483 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9484 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9485 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9486 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9487 }
9488
9489 // Ensure that radio is on. If not able to power on due to phone being
9490 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9491 if (!setRadioPowerForThermal(subId, true)) {
9492 thermalMitigationResult =
9493 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9494 break;
9495 }
9496
9497 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9498 false);
9499 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9500 break;
9501 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9502 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9503 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9504 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9505 }
9506
9507 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9508 if (registry != null) {
9509 TelephonyConnectionService service =
9510 registry.getTelephonyConnectionService();
9511 Phone phone = getPhone(subId);
9512 if (phone == null) {
9513 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009514 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009515 break;
9516 }
9517
9518 if (PhoneConstantConversions.convertCallState(phone.getState())
Daniel Bright74f1ca82020-11-13 11:49:37 -08009519 != TelephonyManager.CALL_STATE_IDLE
9520 || phone.isInEmergencySmsMode() || phone.isInEcm()
9521 || (service != null && service.isEmergencyCallPending())) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009522 String errorMessage = "Phone state is not valid. call state = "
9523 + PhoneConstantConversions.convertCallState(phone.getState())
9524 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9525 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9526 errorMessage += service == null
9527 ? " TelephonyConnectionService is null"
9528 : " isEmergencyCallPending = "
9529 + service.isEmergencyCallPending();
9530 Log.e(LOG_TAG, errorMessage);
9531 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009532 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009533 break;
9534 }
9535 } else {
9536 thermalMitigationResult =
9537 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9538 break;
9539 }
9540
9541 // Turn radio off. If not able to power off due to phone being unavailable,
9542 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9543 if (!setRadioPowerForThermal(subId, false)) {
9544 thermalMitigationResult =
9545 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9546 break;
9547 }
9548 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009549 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009550 break;
9551 default:
9552 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9553 + "not exist. Requested action: " + thermalMitigationAction);
9554 }
9555 } catch (IllegalArgumentException e) {
9556 throw e;
9557 } catch (Exception e) {
9558 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9559 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9560 } finally {
9561 Binder.restoreCallingIdentity(identity);
9562 }
9563
9564 if (DBG) {
9565 log("thermalMitigationRequest returning with thermalMitigationResult: "
9566 + thermalMitigationResult);
9567 }
9568
9569 return thermalMitigationResult;
9570 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009571
9572 /**
9573 * Set the GbaService Package Name that Telephony will bind to.
9574 *
9575 * @param subId The sim that the GbaService is associated with.
9576 * @param packageName The name of the package to be replaced with.
9577 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9578 */
9579 @Override
9580 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9581 enforceModifyPermission();
9582
9583 final long identity = Binder.clearCallingIdentity();
9584 try {
9585 return getGbaManager(subId).overrideServicePackage(packageName);
9586 } finally {
9587 Binder.restoreCallingIdentity(identity);
9588 }
9589 }
9590
9591 /**
9592 * Return the package name of the currently bound GbaService.
9593 *
9594 * @param subId The sim that the GbaService is associated with.
9595 * @return the package name of the GbaService configuration, null if GBA is not supported.
9596 */
9597 @Override
9598 public String getBoundGbaService(int subId) {
9599 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9600
9601 final long identity = Binder.clearCallingIdentity();
9602 try {
9603 return getGbaManager(subId).getServicePackage();
9604 } finally {
9605 Binder.restoreCallingIdentity(identity);
9606 }
9607 }
9608
9609 /**
9610 * Set the release time for telephony to unbind GbaService.
9611 *
9612 * @param subId The sim that the GbaService is associated with.
9613 * @param interval The release time to unbind GbaService by millisecond.
9614 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9615 */
9616 @Override
9617 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9618 enforceModifyPermission();
9619
9620 final long identity = Binder.clearCallingIdentity();
9621 try {
9622 return getGbaManager(subId).overrideReleaseTime(interval);
9623 } finally {
9624 Binder.restoreCallingIdentity(identity);
9625 }
9626 }
9627
9628 /**
9629 * Return the release time for telephony to unbind GbaService.
9630 *
9631 * @param subId The sim that the GbaService is associated with.
9632 * @return The release time to unbind GbaService by millisecond.
9633 */
9634 @Override
9635 public int getGbaReleaseTime(int subId) {
9636 enforceReadPrivilegedPermission("getGbaReleaseTime");
9637
9638 final long identity = Binder.clearCallingIdentity();
9639 try {
9640 return getGbaManager(subId).getReleaseTime();
9641 } finally {
9642 Binder.restoreCallingIdentity(identity);
9643 }
9644 }
9645
9646 private GbaManager getGbaManager(int subId) {
9647 GbaManager instance = GbaManager.getInstance(subId);
9648 if (instance == null) {
9649 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9650 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9651 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9652 }
9653 return instance;
9654 }
Hui Wang068ab862020-10-31 05:12:53 +00009655
9656 /**
9657 * indicate whether the device and the carrier can support
9658 * RCS VoLTE single registration.
9659 */
9660 @Override
9661 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9662 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9663
9664 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9665 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9666 }
9667
9668 final long identity = Binder.clearCallingIdentity();
9669 try {
9670 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9671 if (rpm != null) {
9672 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9673 }
9674 return false;
9675 } finally {
9676 Binder.restoreCallingIdentity(identity);
9677 }
9678 }
9679
9680 /**
9681 * Register RCS provisioning callback.
9682 */
9683 @Override
9684 public void registerRcsProvisioningChangedCallback(int subId,
9685 IRcsConfigCallback callback) {
9686 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9687
9688 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9689 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9690 }
9691 if (!isImsAvailableOnDevice()) {
9692 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9693 "IMS not available on device.");
9694 }
9695
9696 final long identity = Binder.clearCallingIdentity();
9697 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009698 if (!RcsProvisioningMonitor.getInstance()
9699 .registerRcsProvisioningChangedCallback(subId, callback)) {
9700 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9701 "Service not available for the subscription.");
9702 }
Hui Wang068ab862020-10-31 05:12:53 +00009703 } finally {
9704 Binder.restoreCallingIdentity(identity);
9705 }
9706 }
9707
9708 /**
9709 * Unregister RCS provisioning callback.
9710 */
9711 @Override
9712 public void unregisterRcsProvisioningChangedCallback(int subId,
9713 IRcsConfigCallback callback) {
9714 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9715
9716 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9717 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9718 }
9719 if (!isImsAvailableOnDevice()) {
9720 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9721 "IMS not available on device.");
9722 }
9723
9724 final long identity = Binder.clearCallingIdentity();
9725 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009726 RcsProvisioningMonitor.getInstance()
9727 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009728 } finally {
9729 Binder.restoreCallingIdentity(identity);
9730 }
9731 }
9732
9733 /**
9734 * trigger RCS reconfiguration.
9735 */
9736 public void triggerRcsReconfiguration(int subId) {
9737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9738 mApp, subId, "triggerRcsReconfiguration");
9739
9740 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9741 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9742 }
9743 if (!isImsAvailableOnDevice()) {
9744 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9745 "IMS not available on device.");
9746 }
9747
9748 final long identity = Binder.clearCallingIdentity();
9749 try {
9750 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9751 } finally {
9752 Binder.restoreCallingIdentity(identity);
9753 }
9754 }
9755
9756 /**
9757 * Provide the client configuration parameters of the RCS application.
9758 */
9759 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9761 mApp, subId, "setRcsClientConfiguration");
9762
9763 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9764 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9765 }
9766 if (!isImsAvailableOnDevice()) {
9767 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9768 "IMS not available on device.");
9769 }
9770
9771 final long identity = Binder.clearCallingIdentity();
9772
9773 try {
9774 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9775 if (configBinder == null) {
9776 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9777 } else {
9778 configBinder.setRcsClientConfiguration(rcc);
9779 }
9780 } catch (RemoteException e) {
9781 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9782 } finally {
9783 Binder.restoreCallingIdentity(identity);
9784 }
9785 }
9786
9787 /**
9788 * Overrides the config of RCS VoLTE single registration enabled for the device.
9789 */
9790 @Override
9791 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9792 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9793 "setDeviceSingleRegistrationEnabledOverride");
9794 enforceModifyPermission();
9795
9796 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9797 : Boolean.parseBoolean(enabledStr);
9798 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009799 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009800 }
9801
9802 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009803 * Sends a device to device communication message. Only usable via shell.
9804 * @param message message to send.
9805 * @param value message value.
9806 */
9807 @Override
9808 public void sendDeviceToDeviceMessage(int message, int value) {
9809 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9810 "setCarrierSingleRegistrationEnabledOverride");
9811 enforceModifyPermission();
9812
9813 final long identity = Binder.clearCallingIdentity();
9814 try {
9815 TelephonyConnectionService service =
9816 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9817 if (service == null) {
9818 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9819 return;
9820 }
9821 service.sendTestDeviceToDeviceMessage(message, value);
9822 } finally {
9823 Binder.restoreCallingIdentity(identity);
9824 }
9825 }
9826
9827
9828 /**
Hui Wang068ab862020-10-31 05:12:53 +00009829 * Gets the config of RCS VoLTE single registration enabled for the device.
9830 */
9831 @Override
9832 public boolean getDeviceSingleRegistrationEnabled() {
9833 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9834 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9835 }
9836
9837 /**
9838 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9839 */
9840 @Override
9841 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9842 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9843 "setCarrierSingleRegistrationEnabledOverride");
9844 enforceModifyPermission();
9845
9846 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9847 : Boolean.parseBoolean(enabledStr);
9848 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9849 subId, enabled);
9850 }
9851
9852 /**
9853 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9854 */
9855 @Override
9856 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9857 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9858 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9859 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009860
9861 /**
9862 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9863 * their mobile plan.
9864 */
9865 @Override
9866 public String getMobileProvisioningUrl() {
9867 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9868 final long identity = Binder.clearCallingIdentity();
9869 try {
9870 return getDefaultPhone().getMobileProvisioningUrl();
9871 } finally {
9872 Binder.restoreCallingIdentity(identity);
9873 }
9874 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009875
James.cf Linbcdf8b32021-01-14 16:44:13 +08009876 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009877 * Get the EAB contact from the EAB database.
9878 */
9879 @Override
9880 public String getContactFromEab(String contact) {
9881 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9882 enforceModifyPermission();
9883 final long identity = Binder.clearCallingIdentity();
9884 try {
9885 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9886 } finally {
9887 Binder.restoreCallingIdentity(identity);
9888 }
9889 }
9890
9891 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009892 * Remove the EAB contacts from the EAB database.
9893 */
9894 @Override
9895 public int removeContactFromEab(int subId, String contacts) {
9896 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9897 enforceModifyPermission();
9898 final long identity = Binder.clearCallingIdentity();
9899 try {
9900 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9901 } finally {
9902 Binder.restoreCallingIdentity(identity);
9903 }
9904 }
9905
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009906 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +08009907 public boolean getDeviceUceEnabled() {
9908 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
9909 final long identity = Binder.clearCallingIdentity();
9910 try {
9911 return mApp.getDeviceUceEnabled();
9912 } finally {
9913 Binder.restoreCallingIdentity(identity);
9914 }
9915 }
9916
9917 @Override
9918 public void setDeviceUceEnabled(boolean isEnabled) {
9919 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
9920 final long identity = Binder.clearCallingIdentity();
9921 try {
9922 mApp.setDeviceUceEnabled(isEnabled);
9923 } finally {
9924 Binder.restoreCallingIdentity(identity);
9925 }
9926 }
9927
9928 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009929 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9930 String callingPackage) {
9931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9932 mApp, subId, "setSignalStrengthUpdateRequest");
9933
9934 final int callingUid = Binder.getCallingUid();
9935 // Verify that tha callingPackage belongs to the calling UID
9936 mApp.getSystemService(AppOpsManager.class)
9937 .checkPackage(callingUid, callingPackage);
9938
9939 validateSignalStrengthUpdateRequest(request, callingUid);
9940
9941 final long identity = Binder.clearCallingIdentity();
9942 try {
9943 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
9944 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9945
9946 if (result instanceof IllegalStateException) {
9947 throw (IllegalStateException) result;
9948 }
9949 } finally {
9950 Binder.restoreCallingIdentity(identity);
9951 }
9952 }
9953
9954 @Override
9955 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9956 String callingPackage) {
9957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9958 mApp, subId, "clearSignalStrengthUpdateRequest");
9959
9960 final int callingUid = Binder.getCallingUid();
9961 // Verify that tha callingPackage belongs to the calling UID
9962 mApp.getSystemService(AppOpsManager.class)
9963 .checkPackage(callingUid, callingPackage);
9964
9965 final long identity = Binder.clearCallingIdentity();
9966 try {
9967 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
9968 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9969
9970 if (result instanceof IllegalStateException) {
9971 throw (IllegalStateException) result;
9972 }
9973 } finally {
9974 Binder.restoreCallingIdentity(identity);
9975 }
9976 }
9977
9978 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
9979 int callingUid) {
9980 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
9981 // phone/system process do not have further restriction on request
9982 return;
9983 }
9984
9985 // Applications has restrictions on how to use the request:
9986 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
9987 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
9988 // This is not system caller which has been checked above
9989 throw new IllegalArgumentException(
9990 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
9991 }
9992
9993 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
9994 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
9995 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
9996 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
9997 || info.isEnabled()) {
9998 throw new IllegalArgumentException(
9999 "Only system can set hide fields in SignalThresholdInfo");
10000 }
10001
10002 // Thresholds length for each RAN need in range. This has been validated in
10003 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10004 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10005 final int[] thresholds = info.getThresholds();
10006 Objects.requireNonNull(thresholds);
10007 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10008 || thresholds.length
10009 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10010 throw new IllegalArgumentException(
10011 "thresholds length is out of range: " + thresholds.length);
10012 }
10013 }
10014 }
Michele Berionned9fbae52020-11-13 02:36:59 +000010015
10016 /**
10017 * Prepare TelephonyManager for an unattended reboot. The reboot is
10018 * required to be done shortly after the API is invoked.
10019 */
10020 @Override
10021 @TelephonyManager.PrepareUnattendedRebootResult
10022 public int prepareForUnattendedReboot() {
10023 enforceRebootPermission();
10024
10025 final long identity = Binder.clearCallingIdentity();
10026 try {
10027 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10028 } finally {
10029 Binder.restoreCallingIdentity(identity);
10030 }
10031 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010032}