blob: 1fcf3b60f56d6e38be8b54a9b2587b8b2d3797bf [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;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Jack Nudelman24d51a52020-11-24 12:08:04 -080067import android.telephony.Annotation.ThermalMitigationResult;
sqian80370722020-01-29 15:02:51 -080068import android.telephony.CallForwardingInfo;
Sooraj Sasindran1f812e02020-10-30 13:17:53 -070069import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070070import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080071import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070072import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080073import android.telephony.CellIdentityCdma;
74import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070076import android.telephony.CellInfoGsm;
77import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070078import android.telephony.ClientRequestStats;
Jack Nudelman24d51a52020-11-24 12:08:04 -080079import android.telephony.DataThrottlingRequest;
Hui Wang0866fcc2020-10-12 12:14:23 -070080import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070081import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070082import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080083import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070084import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080085import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070086import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080087import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080088import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070089import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080090import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080092import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080093import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080094import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080095import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070096import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070097import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080098import android.telephony.TelephonyScanManager;
Jack Nudelman24d51a52020-11-24 12:08:04 -080099import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800100import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000101import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700102import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700103import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800104import android.telephony.data.ApnSetting;
105import android.telephony.emergency.EmergencyNumber;
Hui Wang0866fcc2020-10-12 12:14:23 -0700106import android.telephony.gba.GbaAuthRequest;
107import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700108import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800109import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700110import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700111import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800112import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700113import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800114import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700115import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700116import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800117import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800118import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800119import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800120import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800122import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700123import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800125import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800126
Andrew Lee312e8172014-10-23 17:01:36 -0700127import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800128import com.android.ims.internal.IImsServiceFeatureCallback;
sqian80370722020-01-29 15:02:51 -0800129import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700130import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700131import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700132import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800133import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700134import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700135import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800136import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang0866fcc2020-10-12 12:14:23 -0700138import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800139import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800140import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700141import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700142import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800143import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800145import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700146import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700147import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700148import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700150import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800151import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700152import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700153import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700154import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700155import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700156import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700157import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700158import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700159import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800160import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800161import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800162import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700163import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800164import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700165import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800166import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700167import com.android.internal.telephony.imsphone.ImsPhone;
168import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800169import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900170import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700171import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800172import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700173import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800174import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700175import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800176import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700177import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800178import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000179import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800180import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700181import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700182import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800183import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700184import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700185import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800186import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700187import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700188import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800189import com.android.services.telephony.TelecomAccountRegistry;
190import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800191import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800192
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700193import java.io.FileDescriptor;
194import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800196import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800197import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800198import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800199import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100200import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800201import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700202import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800203import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800204import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800205import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206
207/**
208 * Implementation of the ITelephony interface.
209 */
Santos Cordon117fee72014-05-16 17:56:12 -0700210public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700211 private static final String LOG_TAG = "PhoneInterfaceManager";
212 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
213 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800214 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700215
216 // Message codes used with mMainThreadHandler
217 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700218 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
219 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700220 private static final int CMD_OPEN_CHANNEL = 9;
221 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
222 private static final int CMD_CLOSE_CHANNEL = 11;
223 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800224 private static final int CMD_NV_READ_ITEM = 13;
225 private static final int EVENT_NV_READ_ITEM_DONE = 14;
226 private static final int CMD_NV_WRITE_ITEM = 15;
227 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
228 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
229 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700230 private static final int CMD_RESET_MODEM_CONFIG = 19;
231 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800232 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
233 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
234 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
235 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800236 private static final int CMD_SEND_ENVELOPE = 25;
237 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000238 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
239 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700240 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
241 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
242 private static final int CMD_EXCHANGE_SIM_IO = 31;
243 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800244 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
245 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700246 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
247 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700248 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
249 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700250 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
251 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
252 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
253 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700254 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
255 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
256 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
257 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700258 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800259 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
260 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000261 private static final int CMD_SWITCH_SLOTS = 50;
262 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700263 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
264 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
265 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
266 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
267 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
268 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
269 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
270 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700271 private static final int CMD_GET_ALL_CELL_INFO = 60;
272 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
273 private static final int CMD_GET_CELL_LOCATION = 62;
274 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700275 private static final int CMD_MODEM_REBOOT = 64;
276 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700277 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
278 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800279 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
280 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700281 private static final int CMD_GET_MODEM_STATUS = 70;
282 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700283 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
284 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700285 private static final int CMD_ERASE_MODEM_CONFIG = 74;
286 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800287 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
288 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
289 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
290 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800291 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
292 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800293 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800294 private static final int CMD_GET_CALL_FORWARDING = 83;
295 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
296 private static final int CMD_SET_CALL_FORWARDING = 85;
297 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
298 private static final int CMD_GET_CALL_WAITING = 87;
299 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
300 private static final int CMD_SET_CALL_WAITING = 89;
301 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700302 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
303 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
304 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
305 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700306 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
307 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800308 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
309 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800310 private static final int CMD_SET_DATA_THROTTLING = 99;
311 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800312 private static final int CMD_SET_SIM_POWER = 101;
313 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700314
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800315 // Parameters of select command.
316 private static final int SELECT_COMMAND = 0xA4;
317 private static final int SELECT_P1 = 0x04;
318 private static final int SELECT_P2 = 0;
319 private static final int SELECT_P3 = 0x10;
320
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700321 /** The singleton instance. */
322 private static PhoneInterfaceManager sInstance;
323
Wink Saville3ab207e2014-11-20 13:07:20 -0800324 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800325 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800326 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700327 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800328 private AppOpsManager mAppOps;
329 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800330 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800331 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700332 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333
Peter Wangdafb9ac2020-01-15 14:13:38 -0800334 /** User Activity */
335 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800336 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
337
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700338 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
339
Derek Tan97ebb422014-09-05 16:55:38 -0700340 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
341 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800342 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800343 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700344
Michelecea4cf22018-12-21 15:00:11 -0800345 // String to store multi SIM allowed
346 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
347
Derek Tan740e1672017-06-27 14:56:27 -0700348 // The AID of ISD-R.
349 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
350
yinxub1bed742017-04-17 11:45:04 -0700351 private NetworkScanRequestTracker mNetworkScanRequestTracker;
352
David Kelly5e06a7f2018-03-12 14:10:59 +0000353 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
354 private static final int MANUFACTURER_CODE_LENGTH = 8;
355
Jack Nudelman24d51a52020-11-24 12:08:04 -0800356 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
357
Derek Tan89e89d42014-07-08 17:00:10 -0700358 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700359 * Experiment flag to enable erase modem config on reset network, default value is false
360 */
361 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
362 "reset_network_erase_modem_config_enabled";
363
364 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700365 * A request object to use for transmitting data to an ICC.
366 */
367 private static final class IccAPDUArgument {
368 public int channel, cla, command, p1, p2, p3;
369 public String data;
370
371 public IccAPDUArgument(int channel, int cla, int command,
372 int p1, int p2, int p3, String data) {
373 this.channel = channel;
374 this.cla = cla;
375 this.command = command;
376 this.p1 = p1;
377 this.p2 = p2;
378 this.p3 = p3;
379 this.data = data;
380 }
381 }
382
383 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700384 * A request object to use for transmitting data to an ICC.
385 */
386 private static final class ManualNetworkSelectionArgument {
387 public OperatorInfo operatorInfo;
388 public boolean persistSelection;
389
390 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
391 this.operatorInfo = operatorInfo;
392 this.persistSelection = persistSelection;
393 }
394 }
395
396 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
398 * request after sending. The main thread will notify the request when it is complete.
399 */
400 private static final class MainThreadRequest {
401 /** The argument to use for the request */
402 public Object argument;
403 /** The result of the request that is run on the main thread */
404 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800405 // The subscriber id that this request applies to. Defaults to
406 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
407 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408
Nathan Harold92bed182018-10-12 18:16:49 -0700409 // In cases where subId is unavailable, the caller needs to specify the phone.
410 public Phone phone;
411
vagdeviaf9a5b92018-08-15 16:01:53 -0700412 public WorkSource workSource;
413
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414 public MainThreadRequest(Object argument) {
415 this.argument = argument;
416 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800417
Nathan Harold92bed182018-10-12 18:16:49 -0700418 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
419 this.argument = argument;
420 if (phone != null) {
421 this.phone = phone;
422 }
423 this.workSource = workSource;
424 }
425
vagdeviaf9a5b92018-08-15 16:01:53 -0700426 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800427 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800428 if (subId != null) {
429 this.subId = subId;
430 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700431 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433 }
434
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800435 private static final class IncomingThirdPartyCallArgs {
436 public final ComponentName component;
437 public final String callId;
438 public final String callerDisplayName;
439
440 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
441 String callerDisplayName) {
442 this.component = component;
443 this.callId = callId;
444 this.callerDisplayName = callerDisplayName;
445 }
446 }
447
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 /**
449 * A handler that processes messages on the main thread in the phone process. Since many
450 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
451 * inbound binder threads to the main thread in the phone process. The Binder thread
452 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
453 * on, which will be notified when the operation completes and will contain the result of the
454 * request.
455 *
456 * <p>If a MainThreadRequest object is provided in the msg.obj field,
457 * note that request.result must be set to something non-null for the calling thread to
458 * unblock.
459 */
460 private final class MainThreadHandler extends Handler {
461 @Override
462 public void handleMessage(Message msg) {
463 MainThreadRequest request;
464 Message onCompleted;
465 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800466 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800468 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469
470 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700471 case CMD_HANDLE_USSD_REQUEST: {
472 request = (MainThreadRequest) msg.obj;
473 final Phone phone = getPhoneFromRequest(request);
474 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
475 String ussdRequest = ussdObject.first;
476 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700477
Pengquan Menga1bb6272018-09-06 09:59:22 -0700478 if (!isUssdApiAllowed(request.subId)) {
479 // Carrier does not support use of this API, return failure.
480 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
481 UssdResponse response = new UssdResponse(ussdRequest, null);
482 Bundle returnData = new Bundle();
483 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
484 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700485
Pengquan Menga1bb6272018-09-06 09:59:22 -0700486 request.result = true;
487 notifyRequester(request);
488 return;
489 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700490
Pengquan Menga1bb6272018-09-06 09:59:22 -0700491 try {
492 request.result = phone != null
493 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
494 } catch (CallStateException cse) {
495 request.result = false;
496 }
497 // Wake up the requesting thread
498 notifyRequester(request);
499 break;
pkanwar32d516d2016-10-14 19:37:38 -0700500 }
501
Yorke Lee716f67e2015-06-17 15:39:16 -0700502 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700503 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700504 final Phone phone = getPhoneFromRequest(request);
505 request.result = phone != null ?
506 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
507 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700508 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700509 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700510 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700511 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700512
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700513 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700514 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700515 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800516 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700517 if (uiccCard == null) {
518 loge("iccTransmitApduLogicalChannel: No UICC");
519 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700520 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700521 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700522 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
523 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700524 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700525 iccArgument.channel, iccArgument.cla, iccArgument.command,
526 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700527 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700528 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700529 break;
530
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700532 ar = (AsyncResult) msg.obj;
533 request = (MainThreadRequest) ar.userObj;
534 if (ar.exception == null && ar.result != null) {
535 request.result = ar.result;
536 } else {
537 request.result = new IccIoResult(0x6F, 0, (byte[])null);
538 if (ar.result == null) {
539 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800540 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700541 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800542 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700543 } else {
544 loge("iccTransmitApduLogicalChannel: Unknown exception");
545 }
546 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700547 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700548 break;
549
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700550 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
551 request = (MainThreadRequest) msg.obj;
552 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800553 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700554 if (uiccCard == null) {
555 loge("iccTransmitApduBasicChannel: No UICC");
556 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 } else {
559 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
560 request);
561 uiccCard.iccTransmitApduBasicChannel(
562 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
563 iccArgument.p3, iccArgument.data, onCompleted);
564 }
565 break;
566
567 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
568 ar = (AsyncResult) msg.obj;
569 request = (MainThreadRequest) ar.userObj;
570 if (ar.exception == null && ar.result != null) {
571 request.result = ar.result;
572 } else {
573 request.result = new IccIoResult(0x6F, 0, (byte[])null);
574 if (ar.result == null) {
575 loge("iccTransmitApduBasicChannel: Empty response");
576 } else if (ar.exception instanceof CommandException) {
577 loge("iccTransmitApduBasicChannel: CommandException: " +
578 ar.exception);
579 } else {
580 loge("iccTransmitApduBasicChannel: Unknown exception");
581 }
582 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 break;
585
586 case CMD_EXCHANGE_SIM_IO:
587 request = (MainThreadRequest) msg.obj;
588 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800589 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 if (uiccCard == null) {
591 loge("iccExchangeSimIO: No UICC");
592 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 } else {
595 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
596 request);
597 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
598 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
599 iccArgument.data, onCompleted);
600 }
601 break;
602
603 case EVENT_EXCHANGE_SIM_IO_DONE:
604 ar = (AsyncResult) msg.obj;
605 request = (MainThreadRequest) ar.userObj;
606 if (ar.exception == null && ar.result != null) {
607 request.result = ar.result;
608 } else {
609 request.result = new IccIoResult(0x6f, 0, (byte[])null);
610 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700611 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 break;
613
Derek Tan4d5e5c12014-02-04 11:54:58 -0800614 case CMD_SEND_ENVELOPE:
615 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800616 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700617 if (uiccCard == null) {
618 loge("sendEnvelopeWithStatus: No UICC");
619 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700621 } else {
622 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
623 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
624 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800625 break;
626
627 case EVENT_SEND_ENVELOPE_DONE:
628 ar = (AsyncResult) msg.obj;
629 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700630 if (ar.exception == null && ar.result != null) {
631 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800632 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700633 request.result = new IccIoResult(0x6F, 0, (byte[])null);
634 if (ar.result == null) {
635 loge("sendEnvelopeWithStatus: Empty response");
636 } else if (ar.exception instanceof CommandException) {
637 loge("sendEnvelopeWithStatus: CommandException: " +
638 ar.exception);
639 } else {
640 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
641 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800642 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700643 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800644 break;
645
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 case CMD_OPEN_CHANNEL:
647 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800648 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800649 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700650 if (uiccCard == null) {
651 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800652 request.result = new IccOpenLogicalChannelResponse(-1,
653 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700655 } else {
656 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800657 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
658 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700659 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 break;
661
662 case EVENT_OPEN_CHANNEL_DONE:
663 ar = (AsyncResult) msg.obj;
664 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700665 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 int[] result = (int[]) ar.result;
668 int channelId = result[0];
669 byte[] selectResponse = null;
670 if (result.length > 1) {
671 selectResponse = new byte[result.length - 1];
672 for (int i = 1; i < result.length; ++i) {
673 selectResponse[i - 1] = (byte) result[i];
674 }
675 }
676 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700677 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 if (ar.result == null) {
680 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700682 if (ar.exception != null) {
683 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
684 }
685
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700686 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700687 if (ar.exception instanceof CommandException) {
688 CommandException.Error error =
689 ((CommandException) (ar.exception)).getCommandError();
690 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700691 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700692 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700693 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700694 }
695 }
696 openChannelResp = new IccOpenLogicalChannelResponse(
697 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700698 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700699 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700700 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 break;
702
703 case CMD_CLOSE_CHANNEL:
704 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800705 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700706 if (uiccCard == null) {
707 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900708 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700709 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700710 } else {
711 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
712 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
713 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 break;
715
716 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800717 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
718 break;
719
720 case CMD_NV_READ_ITEM:
721 request = (MainThreadRequest) msg.obj;
722 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800723 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
724 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800725 break;
726
727 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700728 ar = (AsyncResult) msg.obj;
729 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800730 if (ar.exception == null && ar.result != null) {
731 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700732 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800733 request.result = "";
734 if (ar.result == null) {
735 loge("nvReadItem: Empty response");
736 } else if (ar.exception instanceof CommandException) {
737 loge("nvReadItem: CommandException: " +
738 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700739 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800740 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 }
742 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700743 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700744 break;
745
Jake Hambye994d462014-02-03 13:10:13 -0800746 case CMD_NV_WRITE_ITEM:
747 request = (MainThreadRequest) msg.obj;
748 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
749 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800750 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700751 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800752 break;
753
754 case EVENT_NV_WRITE_ITEM_DONE:
755 handleNullReturnEvent(msg, "nvWriteItem");
756 break;
757
758 case CMD_NV_WRITE_CDMA_PRL:
759 request = (MainThreadRequest) msg.obj;
760 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800761 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800762 break;
763
764 case EVENT_NV_WRITE_CDMA_PRL_DONE:
765 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
766 break;
767
chen xu6dac5ab2018-10-26 17:39:23 -0700768 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800769 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700770 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800771 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800772 break;
773
chen xu6dac5ab2018-10-26 17:39:23 -0700774 case EVENT_RESET_MODEM_CONFIG_DONE:
775 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800776 break;
777
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700778 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
779 request = (MainThreadRequest) msg.obj;
780 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
781 request);
782 Phone phone = getPhoneFromRequest(request);
783 if (phone != null) {
784 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
785 } else {
786 loge("isNRDualConnectivityEnabled: No phone object");
787 request.result = false;
788 notifyRequester(request);
789 }
790 break;
791 }
792
793 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
794 ar = (AsyncResult) msg.obj;
795 request = (MainThreadRequest) ar.userObj;
796 if (ar.exception == null && ar.result != null) {
797 request.result = ar.result;
798 } else {
799 // request.result must be set to something non-null
800 // for the calling thread to unblock
801 if (request.result != null) {
802 request.result = ar.result;
803 } else {
804 request.result = false;
805 }
806 if (ar.result == null) {
807 loge("isNRDualConnectivityEnabled: Empty response");
808 } else if (ar.exception instanceof CommandException) {
809 loge("isNRDualConnectivityEnabled: CommandException: "
810 + ar.exception);
811 } else {
812 loge("isNRDualConnectivityEnabled: Unknown exception");
813 }
814 }
815 notifyRequester(request);
816 break;
817
818 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
819 request = (MainThreadRequest) msg.obj;
820 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
821 Phone phone = getPhoneFromRequest(request);
822 if (phone != null) {
823 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
824 request.workSource);
825 } else {
826 loge("enableNrDualConnectivity: No phone object");
827 request.result =
828 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
829 notifyRequester(request);
830 }
831 break;
832 }
833
834 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
835 ar = (AsyncResult) msg.obj;
836 request = (MainThreadRequest) ar.userObj;
837 if (ar.exception == null) {
838 request.result =
839 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
840 } else {
841 request.result =
842 TelephonyManager
843 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
844 if (ar.exception instanceof CommandException) {
845 CommandException.Error error =
846 ((CommandException) (ar.exception)).getCommandError();
847 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
848 request.result =
849 TelephonyManager
850 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
851 }
852 loge("enableNrDualConnectivity" + ": CommandException: "
853 + ar.exception);
854 } else {
855 loge("enableNrDualConnectivity" + ": Unknown exception");
856 }
857 }
858 notifyRequester(request);
859 break;
860 }
861
Jake Hamby7c27be32014-03-03 13:25:59 -0800862 case CMD_GET_PREFERRED_NETWORK_TYPE:
863 request = (MainThreadRequest) msg.obj;
864 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700865 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800866 break;
867
868 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
869 ar = (AsyncResult) msg.obj;
870 request = (MainThreadRequest) ar.userObj;
871 if (ar.exception == null && ar.result != null) {
872 request.result = ar.result; // Integer
873 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530874 // request.result must be set to something non-null
875 // for the calling thread to unblock
876 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800877 if (ar.result == null) {
878 loge("getPreferredNetworkType: Empty response");
879 } else if (ar.exception instanceof CommandException) {
880 loge("getPreferredNetworkType: CommandException: " +
881 ar.exception);
882 } else {
883 loge("getPreferredNetworkType: Unknown exception");
884 }
885 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700886 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800887 break;
888
889 case CMD_SET_PREFERRED_NETWORK_TYPE:
890 request = (MainThreadRequest) msg.obj;
891 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
892 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700893 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800894 break;
895
896 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
897 handleNullReturnEvent(msg, "setPreferredNetworkType");
898 break;
899
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000900 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
901 request = (MainThreadRequest)msg.obj;
902 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800903 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000904 break;
905
906 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
907 ar = (AsyncResult)msg.obj;
908 request = (MainThreadRequest)ar.userObj;
909 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700910 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000911 break;
912
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800913 case CMD_SET_VOICEMAIL_NUMBER:
914 request = (MainThreadRequest) msg.obj;
915 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
916 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800917 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
918 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800919 break;
920
921 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
922 handleNullReturnEvent(msg, "setVoicemailNumber");
923 break;
924
Stuart Scott54788802015-03-30 13:18:01 -0700925 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
926 request = (MainThreadRequest) msg.obj;
927 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
928 request);
929 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
930 break;
931
932 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
933 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
934 break;
935
Shishir Agrawal302c8692015-06-19 13:49:39 -0700936 case CMD_PERFORM_NETWORK_SCAN:
937 request = (MainThreadRequest) msg.obj;
938 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
939 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
940 break;
941
Hall Liua1acea22020-09-18 19:04:59 -0700942 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800943 request = (MainThreadRequest) msg.obj;
944 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700945 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
946 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
947 request.argument;
948 int callForwardingReason = args.first;
949 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800950 break;
Hall Liua1acea22020-09-18 19:04:59 -0700951 }
952 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800953 ar = (AsyncResult) msg.obj;
954 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700955 TelephonyManager.CallForwardingInfoCallback callback =
956 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
957 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800958 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700959 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800960 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
961 for (CallForwardInfo callForwardInfo : callForwardInfos) {
962 // Service Class is a bit mask per 3gpp 27.007. Search for
963 // any service for voice call.
964 if ((callForwardInfo.serviceClass
965 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700966 callForwardingInfo = new CallForwardingInfo(true,
967 callForwardInfo.reason,
968 callForwardInfo.number,
969 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800970 break;
971 }
972 }
973 // Didn't find a call forward info for voice call.
974 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700975 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
976 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800977 }
Hall Liua1acea22020-09-18 19:04:59 -0700978 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -0800979 } else {
980 if (ar.result == null) {
981 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
982 }
983 if (ar.exception != null) {
984 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
985 }
Hall Liuae527aa2020-09-29 17:10:18 -0700986 int errorCode = TelephonyManager
987 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -0800988 if (ar.exception instanceof CommandException) {
989 CommandException.Error error =
990 ((CommandException) (ar.exception)).getCommandError();
991 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -0700992 errorCode = TelephonyManager
993 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -0800994 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -0700995 errorCode = TelephonyManager
996 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -0800997 }
998 }
Hall Liua1acea22020-09-18 19:04:59 -0700999 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001000 }
sqian80370722020-01-29 15:02:51 -08001001 break;
Hall Liua1acea22020-09-18 19:04:59 -07001002 }
sqian80370722020-01-29 15:02:51 -08001003
Hall Liua1acea22020-09-18 19:04:59 -07001004 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001005 request = (MainThreadRequest) msg.obj;
1006 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001007 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001008 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001009 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1010 request.argument).first;
1011 request.phone.setCallForwardingOption(
1012 callForwardingInfoToSet.isEnabled()
1013 ? CommandsInterface.CF_ACTION_ENABLE
1014 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001015 callForwardingInfoToSet.getReason(),
1016 callForwardingInfoToSet.getNumber(),
1017 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1018 break;
Hall Liua1acea22020-09-18 19:04:59 -07001019 }
sqian80370722020-01-29 15:02:51 -08001020
Hall Liua1acea22020-09-18 19:04:59 -07001021 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001022 ar = (AsyncResult) msg.obj;
1023 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001024 Consumer<Integer> callback =
1025 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1026 request.argument).second;
1027 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001028 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001029 int errorCode = TelephonyManager.CallForwardingInfoCallback
1030 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001031 if (ar.exception instanceof CommandException) {
1032 CommandException.Error error =
1033 ((CommandException) (ar.exception)).getCommandError();
1034 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001035 errorCode = TelephonyManager.CallForwardingInfoCallback
1036 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001037 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001038 errorCode = TelephonyManager.CallForwardingInfoCallback
1039 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001040 }
1041 }
1042 callback.accept(errorCode);
1043 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001044 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001045 }
sqian80370722020-01-29 15:02:51 -08001046 break;
Hall Liua1acea22020-09-18 19:04:59 -07001047 }
sqian80370722020-01-29 15:02:51 -08001048
Hall Liua1acea22020-09-18 19:04:59 -07001049 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001050 request = (MainThreadRequest) msg.obj;
1051 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1052 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1053 break;
Hall Liua1acea22020-09-18 19:04:59 -07001054 }
sqian80370722020-01-29 15:02:51 -08001055
Hall Liua1acea22020-09-18 19:04:59 -07001056 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001057 ar = (AsyncResult) msg.obj;
1058 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001059 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001060 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1061 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001062 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001063 // Service Class is a bit mask per 3gpp 27.007.
1064 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001065 if (callForwardResults.length > 1
1066 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001067 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001068 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001069 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1070 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001071 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001072 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001073 }
1074 } else {
1075 if (ar.result == null) {
1076 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1077 }
1078 if (ar.exception != null) {
1079 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1080 }
1081 if (ar.exception instanceof CommandException) {
1082 CommandException.Error error =
1083 ((CommandException) (ar.exception)).getCommandError();
1084 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1085 callForwardingStatus =
1086 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1087 }
1088 }
1089 }
Hall Liua1acea22020-09-18 19:04:59 -07001090 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001091 break;
Hall Liua1acea22020-09-18 19:04:59 -07001092 }
sqian80370722020-01-29 15:02:51 -08001093
Hall Liua1acea22020-09-18 19:04:59 -07001094 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001095 request = (MainThreadRequest) msg.obj;
1096 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001097 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1098 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001099 break;
Hall Liua1acea22020-09-18 19:04:59 -07001100 }
sqian80370722020-01-29 15:02:51 -08001101
Hall Liua1acea22020-09-18 19:04:59 -07001102 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001103 ar = (AsyncResult) msg.obj;
1104 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001105 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1106 Consumer<Integer> callback =
1107 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1108 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001109 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001110 if (ar.exception instanceof CommandException) {
1111 CommandException.Error error =
1112 ((CommandException) (ar.exception)).getCommandError();
1113 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1114 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1115 } else {
1116 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1117 }
1118 } else {
1119 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1120 }
1121 } else {
1122 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1123 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001124 }
sqian80370722020-01-29 15:02:51 -08001125 break;
Hall Liua1acea22020-09-18 19:04:59 -07001126 }
sqian80370722020-01-29 15:02:51 -08001127
Shishir Agrawal302c8692015-06-19 13:49:39 -07001128 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1129 ar = (AsyncResult) msg.obj;
1130 request = (MainThreadRequest) ar.userObj;
1131 CellNetworkScanResult cellScanResult;
1132 if (ar.exception == null && ar.result != null) {
1133 cellScanResult = new CellNetworkScanResult(
1134 CellNetworkScanResult.STATUS_SUCCESS,
1135 (List<OperatorInfo>) ar.result);
1136 } else {
1137 if (ar.result == null) {
1138 loge("getCellNetworkScanResults: Empty response");
1139 }
1140 if (ar.exception != null) {
1141 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1142 }
1143 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1144 if (ar.exception instanceof CommandException) {
1145 CommandException.Error error =
1146 ((CommandException) (ar.exception)).getCommandError();
1147 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1148 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1149 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1150 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1151 }
1152 }
1153 cellScanResult = new CellNetworkScanResult(errorCode, null);
1154 }
1155 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001156 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001157 break;
1158
1159 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1160 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001161 ManualNetworkSelectionArgument selArg =
1162 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001163 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1164 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001165 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1166 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001167 break;
1168
1169 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001170 ar = (AsyncResult) msg.obj;
1171 request = (MainThreadRequest) ar.userObj;
1172 if (ar.exception == null) {
1173 request.result = true;
1174 } else {
1175 request.result = false;
1176 loge("setNetworkSelectionModeManual " + ar.exception);
1177 }
1178 notifyRequester(request);
1179 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001180 break;
1181
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001182 case CMD_GET_MODEM_ACTIVITY_INFO:
1183 request = (MainThreadRequest) msg.obj;
1184 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001185 if (defaultPhone != null) {
1186 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001187 } else {
1188 ResultReceiver result = (ResultReceiver) request.argument;
1189 Bundle bundle = new Bundle();
1190 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1191 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1192 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001193 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001194 break;
1195
1196 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1197 ar = (AsyncResult) msg.obj;
1198 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001199 ResultReceiver result = (ResultReceiver) request.argument;
1200
1201 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001202 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001203 // Update the last modem activity info and the result of the request.
1204 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1205 if (isModemActivityInfoValid(info)) {
1206 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1207 int[] txTimeMs = info.getTransmitTimeMillis();
1208 int[] lastModemTxTimeMs = mLastModemActivityInfo
1209 .getTransmitTimeMillis();
1210 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1211 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1212 }
1213 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1214 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1215 + mLastModemActivityInfo.getSleepTimeMillis());
1216 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1217 + mLastModemActivityInfo.getIdleTimeMillis());
1218 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1219 mLastModemActivityInfo.setReceiveTimeMillis(
1220 info.getReceiveTimeMillis()
1221 + mLastModemActivityInfo.getReceiveTimeMillis());
1222 }
1223 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1224 mLastModemActivityInfo.getSleepTimeMillis(),
1225 mLastModemActivityInfo.getIdleTimeMillis(),
1226 mLastModemActivityInfo.getTransmitTimeMillis(),
1227 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001228 } else {
1229 if (ar.result == null) {
1230 loge("queryModemActivityInfo: Empty response");
1231 } else if (ar.exception instanceof CommandException) {
1232 loge("queryModemActivityInfo: CommandException: " +
1233 ar.exception);
1234 } else {
1235 loge("queryModemActivityInfo: Unknown exception");
1236 }
1237 }
sqian1a1be542020-03-05 11:37:28 -08001238 Bundle bundle = new Bundle();
1239 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1240 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001241 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001242 break;
1243
Meng Wang1a7c35a2016-05-05 20:56:15 -07001244 case CMD_SET_ALLOWED_CARRIERS:
1245 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001246 CarrierRestrictionRules argument =
1247 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001248 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001249 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001250 break;
1251
1252 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1253 ar = (AsyncResult) msg.obj;
1254 request = (MainThreadRequest) ar.userObj;
1255 if (ar.exception == null && ar.result != null) {
1256 request.result = ar.result;
1257 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001258 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1259 if (ar.exception instanceof CommandException) {
1260 loge("setAllowedCarriers: CommandException: " + ar.exception);
1261 CommandException.Error error =
1262 ((CommandException) (ar.exception)).getCommandError();
1263 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1264 request.result =
1265 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1266 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001267 } else {
1268 loge("setAllowedCarriers: Unknown exception");
1269 }
1270 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001271 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001272 break;
1273
1274 case CMD_GET_ALLOWED_CARRIERS:
1275 request = (MainThreadRequest) msg.obj;
1276 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001277 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001278 break;
1279
1280 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1281 ar = (AsyncResult) msg.obj;
1282 request = (MainThreadRequest) ar.userObj;
1283 if (ar.exception == null && ar.result != null) {
1284 request.result = ar.result;
1285 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001286 request.result = new IllegalStateException(
1287 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001288 if (ar.result == null) {
1289 loge("getAllowedCarriers: Empty response");
1290 } else if (ar.exception instanceof CommandException) {
1291 loge("getAllowedCarriers: CommandException: " +
1292 ar.exception);
1293 } else {
1294 loge("getAllowedCarriers: Unknown exception");
1295 }
1296 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001297 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001298 break;
1299
Nathan Haroldb3014052017-01-25 15:57:32 -08001300 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1301 ar = (AsyncResult) msg.obj;
1302 request = (MainThreadRequest) ar.userObj;
1303 if (ar.exception == null && ar.result != null) {
1304 request.result = ar.result;
1305 } else {
1306 request.result = new IllegalArgumentException(
1307 "Failed to retrieve Forbidden Plmns");
1308 if (ar.result == null) {
1309 loge("getForbiddenPlmns: Empty response");
1310 } else {
1311 loge("getForbiddenPlmns: Unknown exception");
1312 }
1313 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001314 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001315 break;
1316
1317 case CMD_GET_FORBIDDEN_PLMNS:
1318 request = (MainThreadRequest) msg.obj;
1319 uiccCard = getUiccCardFromRequest(request);
1320 if (uiccCard == null) {
1321 loge("getForbiddenPlmns() UiccCard is null");
1322 request.result = new IllegalArgumentException(
1323 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001324 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001325 break;
1326 }
1327 Integer appType = (Integer) request.argument;
1328 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1329 if (uiccApp == null) {
1330 loge("getForbiddenPlmns() no app with specified type -- "
1331 + appType);
1332 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001333 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001334 break;
1335 } else {
1336 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1337 + " specified type -- " + appType);
1338 }
1339 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1340 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1341 onCompleted);
1342 break;
1343
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001344 case CMD_SWITCH_SLOTS:
1345 request = (MainThreadRequest) msg.obj;
1346 int[] physicalSlots = (int[]) request.argument;
1347 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1348 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1349 break;
1350
1351 case EVENT_SWITCH_SLOTS_DONE:
1352 ar = (AsyncResult) msg.obj;
1353 request = (MainThreadRequest) ar.userObj;
1354 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001355 notifyRequester(request);
1356 break;
1357 case CMD_GET_NETWORK_SELECTION_MODE:
1358 request = (MainThreadRequest) msg.obj;
1359 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1360 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1361 break;
1362
1363 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1364 ar = (AsyncResult) msg.obj;
1365 request = (MainThreadRequest) ar.userObj;
1366 if (ar.exception != null) {
1367 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1368 } else {
1369 int mode = ((int[]) ar.result)[0];
1370 if (mode == 0) {
1371 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1372 } else {
1373 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1374 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001375 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001376 notifyRequester(request);
1377 break;
1378 case CMD_GET_CDMA_ROAMING_MODE:
1379 request = (MainThreadRequest) msg.obj;
1380 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1381 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1382 break;
1383 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1384 ar = (AsyncResult) msg.obj;
1385 request = (MainThreadRequest) ar.userObj;
1386 if (ar.exception != null) {
1387 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1388 } else {
1389 request.result = ((int[]) ar.result)[0];
1390 }
1391 notifyRequester(request);
1392 break;
1393 case CMD_SET_CDMA_ROAMING_MODE:
1394 request = (MainThreadRequest) msg.obj;
1395 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1396 int mode = (int) request.argument;
1397 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1398 break;
1399 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1400 ar = (AsyncResult) msg.obj;
1401 request = (MainThreadRequest) ar.userObj;
1402 request.result = ar.exception == null;
1403 notifyRequester(request);
1404 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001405 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1406 request = (MainThreadRequest) msg.obj;
1407 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1408 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1409 break;
1410 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1411 ar = (AsyncResult) msg.obj;
1412 request = (MainThreadRequest) ar.userObj;
1413 if (ar.exception != null) {
1414 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1415 } else {
1416 request.result = ((int[]) ar.result)[0];
1417 }
1418 notifyRequester(request);
1419 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001420 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1421 request = (MainThreadRequest) msg.obj;
1422 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1423 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001424 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1425 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001426 break;
1427 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1428 ar = (AsyncResult) msg.obj;
1429 request = (MainThreadRequest) ar.userObj;
1430 request.result = ar.exception == null;
1431 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001432 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001433 case CMD_GET_ALL_CELL_INFO:
1434 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001435 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001436 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001437 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001438 case EVENT_GET_ALL_CELL_INFO_DONE:
1439 ar = (AsyncResult) msg.obj;
1440 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001441 // If a timeout occurs, the response will be null
1442 request.result = (ar.exception == null && ar.result != null)
1443 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001444 synchronized (request) {
1445 request.notifyAll();
1446 }
1447 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001448 case CMD_REQUEST_CELL_INFO_UPDATE:
1449 request = (MainThreadRequest) msg.obj;
1450 request.phone.requestCellInfoUpdate(request.workSource,
1451 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1452 break;
1453 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1454 ar = (AsyncResult) msg.obj;
1455 request = (MainThreadRequest) ar.userObj;
1456 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1457 try {
1458 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001459 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001460 cb.onError(
1461 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1462 ar.exception.getClass().getName(),
1463 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001464 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001465 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001466 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001467 } else {
1468 // use the result as returned
1469 cb.onCellInfo((List<CellInfo>) ar.result);
1470 }
1471 } catch (RemoteException re) {
1472 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1473 }
1474 break;
Sarah Chincc055732020-11-18 13:39:35 -08001475 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001476 request = (MainThreadRequest) msg.obj;
1477 WorkSource ws = (WorkSource) request.argument;
1478 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001479 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001480 break;
Sarah Chincc055732020-11-18 13:39:35 -08001481 }
1482 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001483 ar = (AsyncResult) msg.obj;
1484 request = (MainThreadRequest) ar.userObj;
1485 if (ar.exception == null) {
1486 request.result = ar.result;
1487 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001488 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001489 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001490 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001491 }
1492
1493 synchronized (request) {
1494 request.notifyAll();
1495 }
1496 break;
Sarah Chincc055732020-11-18 13:39:35 -08001497 }
chen xu6dac5ab2018-10-26 17:39:23 -07001498 case CMD_MODEM_REBOOT:
1499 request = (MainThreadRequest) msg.obj;
1500 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001501 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001502 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001503 case EVENT_CMD_MODEM_REBOOT_DONE:
1504 handleNullReturnEvent(msg, "rebootModem");
1505 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001506 case CMD_REQUEST_ENABLE_MODEM:
1507 request = (MainThreadRequest) msg.obj;
1508 boolean enable = (boolean) request.argument;
1509 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001510 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001511 PhoneConfigurationManager.getInstance()
1512 .enablePhone(request.phone, enable, onCompleted);
1513 break;
1514 case EVENT_ENABLE_MODEM_DONE:
1515 ar = (AsyncResult) msg.obj;
1516 request = (MainThreadRequest) ar.userObj;
1517 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001518 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001519 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001520 if ((boolean) request.result) {
1521 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1522 updateModemStateMetrics();
1523 } else {
1524 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1525 + ar.exception);
1526 }
1527 notifyRequester(request);
1528 break;
1529 case CMD_GET_MODEM_STATUS:
1530 request = (MainThreadRequest) msg.obj;
1531 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1532 PhoneConfigurationManager.getInstance()
1533 .getPhoneStatusFromModem(request.phone, onCompleted);
1534 break;
1535 case EVENT_GET_MODEM_STATUS_DONE:
1536 ar = (AsyncResult) msg.obj;
1537 request = (MainThreadRequest) ar.userObj;
1538 int id = request.phone.getPhoneId();
1539 if (ar.exception == null && ar.result != null) {
1540 request.result = ar.result;
1541 //update the cache as modem status has changed
1542 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1543 (boolean) request.result);
1544 } else {
1545 // Return true if modem status cannot be retrieved. For most cases,
1546 // modem status is on. And for older version modems, GET_MODEM_STATUS
1547 // and disable modem are not supported. Modem is always on.
1548 // TODO: this should be fixed in R to support a third
1549 // status UNKNOWN b/131631629
1550 request.result = true;
1551 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1552 + ar.exception);
1553 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001554 notifyRequester(request);
1555 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001556 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1557 request = (MainThreadRequest) msg.obj;
1558 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1559 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1560 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1561 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1562 break;
1563 }
1564 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1565 ar = (AsyncResult) msg.obj;
1566 request = (MainThreadRequest) ar.userObj;
1567 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1568 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1569 args.second.accept(ar.exception == null);
1570 notifyRequester(request);
1571 break;
1572 }
Sarah Chincc055732020-11-18 13:39:35 -08001573 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1574 request = (MainThreadRequest) msg.obj;
1575 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1576 Phone phone = getPhoneFromRequest(request);
1577 if (phone != null) {
1578 phone.getSystemSelectionChannels(onCompleted);
1579 } else {
1580 loge("getSystemSelectionChannels: No phone object");
1581 request.result = new ArrayList<RadioAccessSpecifier>();
1582 notifyRequester(request);
1583 }
1584 break;
1585 }
1586 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1587 ar = (AsyncResult) msg.obj;
1588 request = (MainThreadRequest) ar.userObj;
1589 if (ar.exception == null && ar.result != null) {
1590 request.result = ar.result;
1591 } else {
1592 request.result = new IllegalArgumentException(
1593 "Failed to retrieve system selection channels");
1594 if (ar.result == null) {
1595 loge("getSystemSelectionChannels: Empty response");
1596 } else {
1597 loge("getSystemSelectionChannels: Unknown exception");
1598 }
1599 }
1600 notifyRequester(request);
1601 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001602 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1603 ar = (AsyncResult) msg.obj;
1604 request = (MainThreadRequest) ar.userObj;
1605 if (ar.exception == null && ar.result != null) {
1606 request.result = ar.result;
1607 } else {
1608 request.result = -1;
1609 loge("Failed to set Forbidden Plmns");
1610 if (ar.result == null) {
1611 loge("setForbidenPlmns: Empty response");
1612 } else if (ar.exception != null) {
1613 loge("setForbiddenPlmns: Exception: " + ar.exception);
1614 request.result = -1;
1615 } else {
1616 loge("setForbiddenPlmns: Unknown exception");
1617 }
1618 }
1619 notifyRequester(request);
1620 break;
1621 case CMD_SET_FORBIDDEN_PLMNS:
1622 request = (MainThreadRequest) msg.obj;
1623 uiccCard = getUiccCardFromRequest(request);
1624 if (uiccCard == null) {
1625 loge("setForbiddenPlmns: UiccCard is null");
1626 request.result = -1;
1627 notifyRequester(request);
1628 break;
1629 }
1630 Pair<Integer, List<String>> setFplmnsArgs =
1631 (Pair<Integer, List<String>>) request.argument;
1632 appType = setFplmnsArgs.first;
1633 List<String> fplmns = setFplmnsArgs.second;
1634 uiccApp = uiccCard.getApplicationByType(appType);
1635 if (uiccApp == null) {
1636 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1637 request.result = -1;
1638 loge("Failed to get UICC App");
1639 notifyRequester(request);
1640 } else {
1641 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1642 ((SIMRecords) uiccApp.getIccRecords())
1643 .setForbiddenPlmns(onCompleted, fplmns);
1644 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001645 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001646 case CMD_ERASE_MODEM_CONFIG:
1647 request = (MainThreadRequest) msg.obj;
1648 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1649 defaultPhone.eraseModemConfig(onCompleted);
1650 break;
1651 case EVENT_ERASE_MODEM_CONFIG_DONE:
1652 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001653 break;
zoey chenf95ca592019-12-30 16:11:23 +08001654
1655 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1656 request = (MainThreadRequest) msg.obj;
1657 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1658 Pair<String, String> changed = (Pair<String, String>) request.argument;
1659 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1660 changed.first, changed.second, onCompleted);
1661 break;
1662 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1663 ar = (AsyncResult) msg.obj;
1664 request = (MainThreadRequest) ar.userObj;
1665 if (ar.exception == null) {
1666 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1667 } else {
1668 request.result = msg.arg1;
1669 }
1670 notifyRequester(request);
1671 break;
1672
1673 case CMD_SET_ICC_LOCK_ENABLED:
1674 request = (MainThreadRequest) msg.obj;
1675 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1676 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1677 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1678 enabled.first, enabled.second, onCompleted);
1679 break;
1680 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1681 ar = (AsyncResult) msg.obj;
1682 request = (MainThreadRequest) ar.userObj;
1683 if (ar.exception == null) {
1684 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1685 } else {
1686 request.result = msg.arg1;
1687 }
1688 notifyRequester(request);
1689 break;
1690
Peter Wangdafb9ac2020-01-15 14:13:38 -08001691 case MSG_NOTIFY_USER_ACTIVITY:
1692 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001693 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001694 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1695 getDefaultPhone().getContext().sendBroadcastAsUser(
1696 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1697 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001698
1699 case CMD_SET_DATA_THROTTLING: {
1700 request = (MainThreadRequest) msg.obj;
1701 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1702 DataThrottlingRequest dataThrottlingRequest =
1703 (DataThrottlingRequest) request.argument;
1704 Phone phone = getPhoneFromRequest(request);
1705 if (phone != null) {
1706 phone.setDataThrottling(onCompleted,
1707 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1708 dataThrottlingRequest.getCompletionDurationMillis());
1709 } else {
1710 loge("setDataThrottling: No phone object");
1711 request.result =
1712 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1713 notifyRequester(request);
1714 }
1715
1716 break;
1717 }
1718 case EVENT_SET_DATA_THROTTLING_DONE:
1719 ar = (AsyncResult) msg.obj;
1720 request = (MainThreadRequest) ar.userObj;
1721
1722 if (ar.exception == null) {
1723 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1724 } else if (ar.exception instanceof CommandException) {
1725 loge("setDataThrottling: CommandException: " + ar.exception);
1726 CommandException.Error error =
1727 ((CommandException) (ar.exception)).getCommandError();
1728
1729 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1730 request.result = TelephonyManager
1731 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1732 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1733 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1734 } else {
1735 request.result =
1736 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1737 }
1738 } else {
1739 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1740 }
1741 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1742 notifyRequester(request);
1743 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001744
1745 case CMD_SET_SIM_POWER: {
1746 request = (MainThreadRequest) msg.obj;
1747 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1748 request = (MainThreadRequest) msg.obj;
1749 int stateToSet =
1750 ((Pair<Integer, IIntegerConsumer>)
1751 request.argument).first;
1752 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1753 break;
1754 }
1755 case EVENT_SET_SIM_POWER_DONE: {
1756 ar = (AsyncResult) msg.obj;
1757 request = (MainThreadRequest) ar.userObj;
1758 IIntegerConsumer callback =
1759 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1760 if (ar.exception != null) {
1761 loge("setSimPower exception: " + ar.exception);
1762 int errorCode = TelephonyManager.CallForwardingInfoCallback
1763 .RESULT_ERROR_UNKNOWN;
1764 if (ar.exception instanceof CommandException) {
1765 CommandException.Error error =
1766 ((CommandException) (ar.exception)).getCommandError();
1767 if (error == CommandException.Error.SIM_ERR) {
1768 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1769 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1770 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1771 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1772 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1773 } else {
1774 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1775 }
1776 }
1777 try {
1778 callback.accept(errorCode);
1779 } catch (RemoteException e) {
1780 // Ignore if the remote process is no longer available to call back.
1781 Log.w(LOG_TAG, "setSimPower: callback not available.");
1782 }
1783 } else {
1784 try {
1785 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1786 } catch (RemoteException e) {
1787 // Ignore if the remote process is no longer available to call back.
1788 Log.w(LOG_TAG, "setSimPower: callback not available.");
1789 }
1790 }
1791 break;
1792 }
1793
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 default:
1795 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1796 break;
1797 }
1798 }
Jake Hambye994d462014-02-03 13:10:13 -08001799
Pengquan Menga1bb6272018-09-06 09:59:22 -07001800 private void notifyRequester(MainThreadRequest request) {
1801 synchronized (request) {
1802 request.notifyAll();
1803 }
1804 }
1805
Jake Hambye994d462014-02-03 13:10:13 -08001806 private void handleNullReturnEvent(Message msg, String command) {
1807 AsyncResult ar = (AsyncResult) msg.obj;
1808 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1809 if (ar.exception == null) {
1810 request.result = true;
1811 } else {
1812 request.result = false;
1813 if (ar.exception instanceof CommandException) {
1814 loge(command + ": CommandException: " + ar.exception);
1815 } else {
1816 loge(command + ": Unknown exception");
1817 }
1818 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001819 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001820 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001821 }
1822
1823 /**
1824 * Posts the specified command to be executed on the main thread,
1825 * waits for the request to complete, and returns the result.
1826 * @see #sendRequestAsync
1827 */
1828 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001829 return sendRequest(
1830 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001831 }
1832
1833 /**
1834 * Posts the specified command to be executed on the main thread,
1835 * waits for the request to complete, and returns the result.
1836 * @see #sendRequestAsync
1837 */
1838 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1839 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001840 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001841 }
1842
1843 /**
1844 * Posts the specified command to be executed on the main thread,
1845 * waits for the request to complete, and returns the result.
1846 * @see #sendRequestAsync
1847 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001848 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001849 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001850 }
1851
1852 /**
1853 * Posts the specified command to be executed on the main thread,
1854 * waits for the request to complete, and returns the result.
1855 * @see #sendRequestAsync
1856 */
Nathan Harold92bed182018-10-12 18:16:49 -07001857 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1858 return sendRequest(command, argument, subId, null, workSource);
1859 }
1860
1861 /**
1862 * Posts the specified command to be executed on the main thread,
1863 * waits for the request to complete, and returns the result.
1864 * @see #sendRequestAsync
1865 */
1866 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1867 return sendRequest(
1868 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1869 }
1870
1871 /**
1872 * Posts the specified command to be executed on the main thread,
1873 * waits for the request to complete, and returns the result.
1874 * @see #sendRequestAsync
1875 */
1876 private Object sendRequest(
1877 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001878 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1879 throw new RuntimeException("This method will deadlock if called from the main thread.");
1880 }
1881
Nathan Harold92bed182018-10-12 18:16:49 -07001882 MainThreadRequest request = null;
1883 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1884 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1885 } else if (phone != null) {
1886 request = new MainThreadRequest(argument, phone, workSource);
1887 } else {
1888 request = new MainThreadRequest(argument, subId, workSource);
1889 }
1890
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 Message msg = mMainThreadHandler.obtainMessage(command, request);
1892 msg.sendToTarget();
1893
1894 // Wait for the request to complete
1895 synchronized (request) {
1896 while (request.result == null) {
1897 try {
1898 request.wait();
1899 } catch (InterruptedException e) {
1900 // Do nothing, go back and wait until the request is complete
1901 }
1902 }
1903 }
1904 return request.result;
1905 }
1906
1907 /**
1908 * Asynchronous ("fire and forget") version of sendRequest():
1909 * Posts the specified command to be executed on the main thread, and
1910 * returns immediately.
1911 * @see #sendRequest
1912 */
1913 private void sendRequestAsync(int command) {
1914 mMainThreadHandler.sendEmptyMessage(command);
1915 }
1916
1917 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001918 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001919 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001920 */
1921 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001922 sendRequestAsync(command, argument, null, null);
1923 }
1924
1925 /**
1926 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1927 * @see {@link #sendRequest(int,Object)}
1928 */
1929 private void sendRequestAsync(
1930 int command, Object argument, Phone phone, WorkSource workSource) {
1931 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001932 Message msg = mMainThreadHandler.obtainMessage(command, request);
1933 msg.sendToTarget();
1934 }
1935
1936 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 * Initialize the singleton PhoneInterfaceManager instance.
1938 * This is only done once, at startup, from PhoneApp.onCreate().
1939 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001940 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 synchronized (PhoneInterfaceManager.class) {
1942 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001943 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001944 } else {
1945 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1946 }
1947 return sInstance;
1948 }
1949 }
1950
1951 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001952 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001955 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001956 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001957 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1958 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001959 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001960 mTelephonySharedPreferences =
1961 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001962 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001963 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001964 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001965
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 publish();
1967 }
1968
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001969 private Phone getDefaultPhone() {
1970 Phone thePhone = getPhone(getDefaultSubscription());
1971 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1972 }
1973
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 private void publish() {
1975 if (DBG) log("publish: " + this);
1976
Peter Wangc035ce42020-01-08 21:00:22 -08001977 TelephonyFrameworkInitializer
1978 .getTelephonyServiceManager()
1979 .getTelephonyServiceRegisterer()
1980 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001981 }
1982
Stuart Scott584921c2015-01-15 17:10:34 -08001983 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001984 if (request.phone != null) {
1985 return request.phone;
1986 } else {
1987 return getPhoneFromSubId(request.subId);
1988 }
1989 }
1990
1991 private Phone getPhoneFromSubId(int subId) {
1992 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1993 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001994 }
1995
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001996 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1997 Phone phone = getPhoneFromRequest(request);
1998 return phone == null ? null :
1999 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2000 }
2001
Wink Saville36469e72014-06-11 15:17:00 -07002002 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002003 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002004 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002005 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002006
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002007 private void sendEraseModemConfig(Phone phone) {
2008 if (phone != null) {
2009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2010 mApp, phone.getSubId(), "eraseModemConfig");
2011 final long identity = Binder.clearCallingIdentity();
2012 try {
2013 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2014 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2015 } finally {
2016 Binder.restoreCallingIdentity(identity);
2017 }
2018 }
2019 }
2020
Peter Wang050bb052020-01-13 23:33:09 -08002021 private boolean isImsAvailableOnDevice() {
2022 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2023 if (pm == null) {
2024 // For some reason package manger is not available.. This will fail internally anyway,
2025 // so do not throw error and allow.
2026 return true;
2027 }
2028 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2029 }
2030
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002032 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002033 }
2034
Wink Savilleb564aae2014-10-23 10:18:09 -07002035 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002036 if (DBG) log("dial: " + number);
2037 // No permission check needed here: This is just a wrapper around the
2038 // ACTION_DIAL intent, which is available to any app since it puts up
2039 // the UI before it does anything.
2040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002041 final long identity = Binder.clearCallingIdentity();
2042 try {
2043 String url = createTelUrl(number);
2044 if (url == null) {
2045 return;
2046 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002048 // PENDING: should we just silently fail if phone is offhook or ringing?
2049 PhoneConstants.State state = mCM.getState(subId);
2050 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2051 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2052 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2053 mApp.startActivity(intent);
2054 }
2055 } finally {
2056 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002057 }
2058 }
2059
2060 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002061 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002062 }
2063
Wink Savilleb564aae2014-10-23 10:18:09 -07002064 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002065 if (DBG) log("call: " + number);
2066
2067 // This is just a wrapper around the ACTION_CALL intent, but we still
2068 // need to do a permission check since we're calling startActivity()
2069 // from the context of the phone app.
2070 enforceCallPermission();
2071
Jordan Liu1617b712019-07-10 15:06:26 -07002072 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002073 != AppOpsManager.MODE_ALLOWED) {
2074 return;
2075 }
2076
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002077 final long identity = Binder.clearCallingIdentity();
2078 try {
2079 String url = createTelUrl(number);
2080 if (url == null) {
2081 return;
2082 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002083
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002084 boolean isValid = false;
2085 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2086 if (slist != null) {
2087 for (SubscriptionInfo subInfoRecord : slist) {
2088 if (subInfoRecord.getSubscriptionId() == subId) {
2089 isValid = true;
2090 break;
2091 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002092 }
Wink Saville08874612014-08-31 19:19:58 -07002093 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002094 if (!isValid) {
2095 return;
2096 }
Wink Saville08874612014-08-31 19:19:58 -07002097
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002098 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2099 intent.putExtra(SUBSCRIPTION_KEY, subId);
2100 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2101 mApp.startActivity(intent);
2102 } finally {
2103 Binder.restoreCallingIdentity(identity);
2104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002105 }
2106
Wink Savilleb564aae2014-10-23 10:18:09 -07002107 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002108 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002109 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2110 }
2111
Wink Savilleb564aae2014-10-23 10:18:09 -07002112 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002113 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002114 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2115 }
2116
Wink Savilleb564aae2014-10-23 10:18:09 -07002117 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002119
2120 final long identity = Binder.clearCallingIdentity();
2121 try {
2122 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2123 checkSimPin.start();
2124 return checkSimPin.unlockSim(null, pin);
2125 } finally {
2126 Binder.restoreCallingIdentity(identity);
2127 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002128 }
2129
Wink Savilleb564aae2014-10-23 10:18:09 -07002130 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002131 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002132
2133 final long identity = Binder.clearCallingIdentity();
2134 try {
2135 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2136 checkSimPuk.start();
2137 return checkSimPuk.unlockSim(puk, pin);
2138 } finally {
2139 Binder.restoreCallingIdentity(identity);
2140 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002141 }
2142
2143 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002144 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002145 * a synchronous one.
2146 */
2147 private static class UnlockSim extends Thread {
2148
2149 private final IccCard mSimCard;
2150
2151 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002152 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2153 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154
2155 // For replies from SimCard interface
2156 private Handler mHandler;
2157
2158 // For async handler to identify request type
2159 private static final int SUPPLY_PIN_COMPLETE = 100;
2160
2161 public UnlockSim(IccCard simCard) {
2162 mSimCard = simCard;
2163 }
2164
2165 @Override
2166 public void run() {
2167 Looper.prepare();
2168 synchronized (UnlockSim.this) {
2169 mHandler = new Handler() {
2170 @Override
2171 public void handleMessage(Message msg) {
2172 AsyncResult ar = (AsyncResult) msg.obj;
2173 switch (msg.what) {
2174 case SUPPLY_PIN_COMPLETE:
2175 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2176 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002177 mRetryCount = msg.arg1;
2178 if (ar.exception != null) {
2179 if (ar.exception instanceof CommandException &&
2180 ((CommandException)(ar.exception)).getCommandError()
2181 == CommandException.Error.PASSWORD_INCORRECT) {
2182 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002183 } //When UiccCardApp dispose,handle message and return exception
2184 else if (ar.exception instanceof CommandException &&
2185 ((CommandException) (ar.exception)).getCommandError()
2186 == CommandException.Error.ABORTED) {
2187 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002188 } else {
2189 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2190 }
2191 } else {
2192 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2193 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194 mDone = true;
2195 UnlockSim.this.notifyAll();
2196 }
2197 break;
2198 }
2199 }
2200 };
2201 UnlockSim.this.notifyAll();
2202 }
2203 Looper.loop();
2204 }
2205
2206 /*
2207 * Use PIN or PUK to unlock SIM card
2208 *
2209 * If PUK is null, unlock SIM card with PIN
2210 *
2211 * If PUK is not null, unlock SIM card with PUK and set PIN code
2212 */
Wink Saville9de0f752013-10-22 19:04:03 -07002213 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002214
2215 while (mHandler == null) {
2216 try {
2217 wait();
2218 } catch (InterruptedException e) {
2219 Thread.currentThread().interrupt();
2220 }
2221 }
2222 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2223
2224 if (puk == null) {
2225 mSimCard.supplyPin(pin, callback);
2226 } else {
2227 mSimCard.supplyPuk(puk, pin, callback);
2228 }
2229
2230 while (!mDone) {
2231 try {
2232 Log.d(LOG_TAG, "wait for done");
2233 wait();
2234 } catch (InterruptedException e) {
2235 // Restore the interrupted status
2236 Thread.currentThread().interrupt();
2237 }
2238 }
2239 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002240 int[] resultArray = new int[2];
2241 resultArray[0] = mResult;
2242 resultArray[1] = mRetryCount;
2243 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002244 }
2245 }
2246
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002247 /**
2248 * This method has been removed due to privacy and stability concerns.
2249 */
2250 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002252 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2253 return;
Wink Saville36469e72014-06-11 15:17:00 -07002254 }
2255
Nathan Harold1f889d82020-06-04 17:05:26 -07002256 @Override
2257 public void updateServiceLocationWithPackageName(String callingPackage) {
2258 mApp.getSystemService(AppOpsManager.class)
2259 .checkPackage(Binder.getCallingUid(), callingPackage);
2260
2261 final int targetSdk = getTargetSdk(callingPackage);
2262 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2263 // Callers targeting S have no business invoking this method.
2264 return;
2265 }
2266
2267 LocationAccessPolicy.LocationPermissionResult locationResult =
2268 LocationAccessPolicy.checkLocationPermission(mApp,
2269 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2270 .setCallingPackage(callingPackage)
2271 .setCallingFeatureId(null)
2272 .setCallingPid(Binder.getCallingPid())
2273 .setCallingUid(Binder.getCallingUid())
2274 .setMethod("updateServiceLocation")
2275 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2276 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2277 .build());
2278 // Apps that lack location permission have no business calling this method;
2279 // however, because no permission was declared in the public API, denials must
2280 // all be "soft".
2281 switch (locationResult) {
2282 case DENIED_HARD: /* fall through */
2283 case DENIED_SOFT:
2284 return;
2285 }
2286
2287 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002288 final long identity = Binder.clearCallingIdentity();
2289 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002290 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002291 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002292 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002293 }
2294 } finally {
2295 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 }
2298
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002299 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002300 @Override
2301 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002302 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002303 }
2304
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002305
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002306 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002307 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2308 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2309 callingFeatureId);
2310 }
2311
2312 @Deprecated
2313 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002314 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002315 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2316 }
2317
2318 @Override
2319 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2320 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002321 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002322 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002323 return false;
2324 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002325
2326 final long identity = Binder.clearCallingIdentity();
2327 try {
2328 return isRadioOnForSubscriber(subId);
2329 } finally {
2330 Binder.restoreCallingIdentity(identity);
2331 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002332 }
2333
2334 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002335 final long identity = Binder.clearCallingIdentity();
2336 try {
2337 final Phone phone = getPhone(subId);
2338 if (phone != null) {
2339 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2340 } else {
2341 return false;
2342 }
2343 } finally {
2344 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002345 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002346 }
2347
2348 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002349 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 }
Wink Saville36469e72014-06-11 15:17:00 -07002351
Wink Savilleb564aae2014-10-23 10:18:09 -07002352 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002354
2355 final long identity = Binder.clearCallingIdentity();
2356 try {
2357 final Phone phone = getPhone(subId);
2358 if (phone != null) {
2359 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2360 }
2361 } finally {
2362 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002363 }
Wink Saville36469e72014-06-11 15:17:00 -07002364 }
2365
2366 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002367 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002368 }
2369
Wink Savilleb564aae2014-10-23 10:18:09 -07002370 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002371 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002372
2373 final long identity = Binder.clearCallingIdentity();
2374 try {
2375 final Phone phone = getPhone(subId);
2376 if (phone == null) {
2377 return false;
2378 }
2379 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2380 toggleRadioOnOffForSubscriber(subId);
2381 }
2382 return true;
2383 } finally {
2384 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002385 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386 }
Wink Saville36469e72014-06-11 15:17:00 -07002387
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002388 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002389 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002390 /*
2391 * If any of the Radios are available, it will need to be
2392 * shutdown. So return true if any Radio is available.
2393 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002394 final long identity = Binder.clearCallingIdentity();
2395 try {
2396 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2397 Phone phone = PhoneFactory.getPhone(i);
2398 if (phone != null && phone.isRadioAvailable()) return true;
2399 }
2400 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2401 return false;
2402 } finally {
2403 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002404 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002405 }
2406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002407 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002408 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002409 enforceModifyPermission();
2410
2411 final long identity = Binder.clearCallingIdentity();
2412 try {
2413 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2414 logv("Shutting down Phone " + i);
2415 shutdownRadioUsingPhoneId(i);
2416 }
2417 } finally {
2418 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002419 }
2420 }
2421
2422 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002423 Phone phone = PhoneFactory.getPhone(phoneId);
2424 if (phone != null && phone.isRadioAvailable()) {
2425 phone.shutdownRadio();
2426 }
2427 }
2428
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002430 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002431
2432 final long identity = Binder.clearCallingIdentity();
2433 try {
2434 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2435 if (defaultPhone != null) {
2436 defaultPhone.setRadioPower(turnOn);
2437 return true;
2438 } else {
2439 loge("There's no default phone.");
2440 return false;
2441 }
2442 } finally {
2443 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002444 }
Wink Saville36469e72014-06-11 15:17:00 -07002445 }
2446
Wink Savilleb564aae2014-10-23 10:18:09 -07002447 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002449
2450 final long identity = Binder.clearCallingIdentity();
2451 try {
2452 final Phone phone = getPhone(subId);
2453 if (phone != null) {
2454 phone.setRadioPower(turnOn);
2455 return true;
2456 } else {
2457 return false;
2458 }
2459 } finally {
2460 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002461 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 }
2463
Wink Saville36469e72014-06-11 15:17:00 -07002464 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002465 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 public boolean enableDataConnectivity() {
2467 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002468
2469 final long identity = Binder.clearCallingIdentity();
2470 try {
2471 int subId = mSubscriptionController.getDefaultDataSubId();
2472 final Phone phone = getPhone(subId);
2473 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002474 phone.getDataEnabledSettings().setDataEnabled(
2475 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002476 return true;
2477 } else {
2478 return false;
2479 }
2480 } finally {
2481 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 }
2484
Wink Saville36469e72014-06-11 15:17:00 -07002485 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002486 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 public boolean disableDataConnectivity() {
2488 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002489
2490 final long identity = Binder.clearCallingIdentity();
2491 try {
2492 int subId = mSubscriptionController.getDefaultDataSubId();
2493 final Phone phone = getPhone(subId);
2494 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002495 phone.getDataEnabledSettings().setDataEnabled(
2496 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002497 return true;
2498 } else {
2499 return false;
2500 }
2501 } finally {
2502 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 }
2505
Sanket Padawe356d7632015-06-22 14:03:32 -07002506 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002507 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508 final long identity = Binder.clearCallingIdentity();
2509 try {
2510 final Phone phone = getPhone(subId);
2511 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002512 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513 } else {
2514 return false;
2515 }
2516 } finally {
2517 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 }
2520
2521 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002522 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002523 }
2524
pkanwarae03a6b2016-11-06 20:37:09 -08002525 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002526 enforceCallPermission();
2527
2528 final long identity = Binder.clearCallingIdentity();
2529 try {
2530 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2531 return;
2532 }
2533 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2534 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2535 } finally {
2536 Binder.restoreCallingIdentity(identity);
2537 }
pkanwar32d516d2016-10-14 19:37:38 -07002538 };
2539
Wink Savilleb564aae2014-10-23 10:18:09 -07002540 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002542
2543 final long identity = Binder.clearCallingIdentity();
2544 try {
2545 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2546 return false;
2547 }
2548 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2549 } finally {
2550 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552 }
2553
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002554 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002555 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002556 }
2557
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002558 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002559 final long identity = Binder.clearCallingIdentity();
2560 try {
2561 Phone phone = PhoneFactory.getPhone(slotIndex);
2562 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2563 PhoneConstantConversions.convertCallState(phone.getState());
2564 } finally {
2565 Binder.restoreCallingIdentity(identity);
2566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567 }
2568
Sanket Padawe356d7632015-06-22 14:03:32 -07002569 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002570 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002571 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2572 }
2573
2574 @Override
2575 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002576 final long identity = Binder.clearCallingIdentity();
2577 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002578 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002579 if (phone != null) {
2580 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2581 } else {
2582 return PhoneConstantConversions.convertDataState(
2583 PhoneConstants.DataState.DISCONNECTED);
2584 }
2585 } finally {
2586 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002587 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002588 }
2589
Sanket Padawe356d7632015-06-22 14:03:32 -07002590 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002591 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002592 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2593 }
2594
2595 @Override
2596 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597 final long identity = Binder.clearCallingIdentity();
2598 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002599 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 if (phone != null) {
2601 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2602 } else {
2603 return TelephonyManager.DATA_ACTIVITY_NONE;
2604 }
2605 } finally {
2606 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608 }
2609
2610 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002611 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002612 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002613 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002614
2615 LocationAccessPolicy.LocationPermissionResult locationResult =
2616 LocationAccessPolicy.checkLocationPermission(mApp,
2617 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2618 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002619 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002620 .setCallingPid(Binder.getCallingPid())
2621 .setCallingUid(Binder.getCallingUid())
2622 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002623 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002624 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2625 .build());
2626 switch (locationResult) {
2627 case DENIED_HARD:
2628 throw new SecurityException("Not allowed to access cell location");
2629 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002630 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2631 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002632 }
2633
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002634 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002635 final long identity = Binder.clearCallingIdentity();
2636 try {
2637 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002638 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002639 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640 } finally {
2641 Binder.restoreCallingIdentity(identity);
2642 }
Svetoslav64fad262015-04-14 14:35:21 -07002643 }
2644
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002645 @Override
Jack Yu01425032020-02-22 19:38:58 -08002646 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002647 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2648 // registered cell info, so return a NULL country instead.
2649 final long identity = Binder.clearCallingIdentity();
2650 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002651 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2652 // Get default phone in this case.
2653 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2654 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002655 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002657 if (phone == null) return "";
2658 ServiceStateTracker sst = phone.getServiceStateTracker();
2659 if (sst == null) return "";
2660 LocaleTracker lt = sst.getLocaleTracker();
2661 if (lt == null) return "";
2662 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2663 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2664 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002665 } finally {
2666 Binder.restoreCallingIdentity(identity);
2667 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002668 }
2669
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002670 /**
2671 * This method was removed due to potential issues caused by performing partial
2672 * updates of service state, and lack of a credible use case.
2673 *
2674 * This has the ability to break the telephony implementation by disabling notification of
2675 * changes in device connectivity. DO NOT USE THIS!
2676 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002677 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678 public void enableLocationUpdates() {
2679 mApp.enforceCallingOrSelfPermission(
2680 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002681 }
2682
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002683 /**
2684 * This method was removed due to potential issues caused by performing partial
2685 * updates of service state, and lack of a credible use case.
2686 *
2687 * This has the ability to break the telephony implementation by disabling notification of
2688 * changes in device connectivity. DO NOT USE THIS!
2689 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002690 @Override
2691 public void disableLocationUpdates() {
2692 mApp.enforceCallingOrSelfPermission(
2693 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694 }
2695
Nathan Harold31d7ff32018-10-15 20:20:30 -07002696 /**
2697 * Returns the target SDK version number for a given package name.
2698 *
Nathan Haroldec184742019-07-10 17:04:16 -07002699 * This call MUST be invoked before clearing the calling UID.
2700 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002701 * @return target SDK if the package is found or INT_MAX.
2702 */
2703 private int getTargetSdk(String packageName) {
2704 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002705 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002706 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002707 if (ai != null) return ai.targetSdkVersion;
2708 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002709 loge("Failed to get package info for pkg="
2710 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002711 }
2712 return Integer.MAX_VALUE;
2713 }
2714
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002715 @Override
2716 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002717 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2718 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002719 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002720 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2721 throw new SecurityException(
2722 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2723 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002724
Jordan Liu1617b712019-07-10 15:06:26 -07002725 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2727 return null;
2728 }
Svetoslav64fad262015-04-14 14:35:21 -07002729
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002730 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002731
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002732 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002733 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734
Nathan Haroldf180aac2018-06-01 18:43:55 -07002735 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2736 for (CellInfo ci : info) {
2737 if (ci instanceof CellInfoGsm) {
2738 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2739 } else if (ci instanceof CellInfoWcdma) {
2740 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2741 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002743 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002744 }
2745
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002746 private List<CellInfo> getCachedCellInfo() {
2747 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2748 for (Phone phone : PhoneFactory.getPhones()) {
2749 List<CellInfo> info = phone.getAllCellInfo();
2750 if (info != null) cellInfos.addAll(info);
2751 }
2752 return cellInfos;
2753 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002754
2755 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002756 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002757 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002758 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002759
2760 LocationAccessPolicy.LocationPermissionResult locationResult =
2761 LocationAccessPolicy.checkLocationPermission(mApp,
2762 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2763 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002764 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002765 .setCallingPid(Binder.getCallingPid())
2766 .setCallingUid(Binder.getCallingUid())
2767 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002768 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002769 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2770 .build());
2771 switch (locationResult) {
2772 case DENIED_HARD:
2773 throw new SecurityException("Not allowed to access cell info");
2774 case DENIED_SOFT:
2775 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 }
2777
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002778 final int targetSdk = getTargetSdk(callingPackage);
2779 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2780 return getCachedCellInfo();
2781 }
2782
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002783 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002784 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785 final long identity = Binder.clearCallingIdentity();
2786 try {
2787 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2788 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002789 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002790 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002791 if (info != null) cellInfos.addAll(info);
2792 }
2793 return cellInfos;
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002796 }
2797 }
2798
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002799 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002800 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2801 String callingFeatureId) {
2802 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2803 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002804 }
2805
2806 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002807 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2808 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002809 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002810 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002811 }
2812
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002813 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2814 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002815 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002816 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002817
2818 LocationAccessPolicy.LocationPermissionResult locationResult =
2819 LocationAccessPolicy.checkLocationPermission(mApp,
2820 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2821 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002822 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002823 .setCallingPid(Binder.getCallingPid())
2824 .setCallingUid(Binder.getCallingUid())
2825 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002826 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2827 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002828 .build());
2829 switch (locationResult) {
2830 case DENIED_HARD:
Hall Liuaa4283b2020-05-21 17:09:35 -07002831 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2832 // Safetynet logging for b/154934934
2833 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2834 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002835 throw new SecurityException("Not allowed to access cell info");
2836 case DENIED_SOFT:
Hall Liuaa4283b2020-05-21 17:09:35 -07002837 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2838 // Safetynet logging for b/154934934
2839 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2840 }
Nathan Harold5320c422019-05-09 10:26:08 -07002841 try {
2842 cb.onCellInfo(new ArrayList<CellInfo>());
2843 } catch (RemoteException re) {
2844 // Drop without consequences
2845 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002846 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002847 }
2848
Nathan Harolda939a962019-05-09 10:13:47 -07002849
2850 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002851 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2852
2853 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2854 }
2855
2856 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002857 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002858 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002859 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002860
2861 final long identity = Binder.clearCallingIdentity();
2862 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002863 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864 } finally {
2865 Binder.restoreCallingIdentity(identity);
2866 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002867 }
2868
Shishir Agrawala9f32182016-04-12 12:00:16 -07002869 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002870 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002871 Phone phone = PhoneFactory.getPhone(slotIndex);
2872 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002873 return null;
2874 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002875 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002876 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002877 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002878 return null;
2879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880
2881 final long identity = Binder.clearCallingIdentity();
2882 try {
2883 return phone.getImei();
2884 } finally {
2885 Binder.restoreCallingIdentity(identity);
2886 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002887 }
2888
2889 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002890 public String getTypeAllocationCodeForSlot(int slotIndex) {
2891 Phone phone = PhoneFactory.getPhone(slotIndex);
2892 String tac = null;
2893 if (phone != null) {
2894 String imei = phone.getImei();
2895 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2896 }
2897 return tac;
2898 }
2899
2900 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002901 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002902 Phone phone = PhoneFactory.getPhone(slotIndex);
2903 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002904 return null;
2905 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002906
Jeff Davidson913390f2018-02-23 17:11:49 -08002907 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002908 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002909 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002910 return null;
2911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002912
2913 final long identity = Binder.clearCallingIdentity();
2914 try {
2915 return phone.getMeid();
2916 } finally {
2917 Binder.restoreCallingIdentity(identity);
2918 }
Jack Yu2af8d712017-03-15 17:14:14 -07002919 }
2920
2921 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002922 public String getManufacturerCodeForSlot(int slotIndex) {
2923 Phone phone = PhoneFactory.getPhone(slotIndex);
2924 String manufacturerCode = null;
2925 if (phone != null) {
2926 String meid = phone.getMeid();
2927 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2928 }
2929 return manufacturerCode;
2930 }
2931
2932 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002933 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2934 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002935 Phone phone = PhoneFactory.getPhone(slotIndex);
2936 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002937 return null;
2938 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002939 int subId = phone.getSubId();
2940 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002941 mApp, subId, callingPackage, callingFeatureId,
2942 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002943 return null;
2944 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002945
2946 final long identity = Binder.clearCallingIdentity();
2947 try {
2948 return phone.getDeviceSvn();
2949 } finally {
2950 Binder.restoreCallingIdentity(identity);
2951 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002952 }
2953
fionaxu43304da2017-11-27 22:51:16 -08002954 @Override
2955 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002956 final long identity = Binder.clearCallingIdentity();
2957 try {
2958 final Phone phone = getPhone(subId);
2959 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2960 } finally {
2961 Binder.restoreCallingIdentity(identity);
2962 }
fionaxu43304da2017-11-27 22:51:16 -08002963 }
2964
2965 @Override
2966 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002967 final long identity = Binder.clearCallingIdentity();
2968 try {
2969 final Phone phone = getPhone(subId);
2970 return phone == null ? null : phone.getCarrierName();
2971 } finally {
2972 Binder.restoreCallingIdentity(identity);
2973 }
fionaxu43304da2017-11-27 22:51:16 -08002974 }
2975
calvinpanffe225e2018-11-01 19:43:06 +08002976 @Override
chen xu0026ca62019-03-06 15:28:50 -08002977 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002978 final long identity = Binder.clearCallingIdentity();
2979 try {
2980 final Phone phone = getPhone(subId);
2981 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002982 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002983 } finally {
2984 Binder.restoreCallingIdentity(identity);
2985 }
2986 }
2987
2988 @Override
chen xu0026ca62019-03-06 15:28:50 -08002989 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002990 final long identity = Binder.clearCallingIdentity();
2991 try {
2992 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002993 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002994 } finally {
2995 Binder.restoreCallingIdentity(identity);
2996 }
2997 }
2998
chen xu651eec72018-11-11 19:03:44 -08002999 @Override
chen xu864e11c2018-12-06 22:10:03 -08003000 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3001 if (!isSubscriptionMccMnc) {
3002 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3003 }
chen xu651eec72018-11-11 19:03:44 -08003004 final Phone phone = PhoneFactory.getPhone(slotIndex);
3005 if (phone == null) {
3006 return TelephonyManager.UNKNOWN_CARRIER_ID;
3007 }
3008 final long identity = Binder.clearCallingIdentity();
3009 try {
3010 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3011 } finally {
3012 Binder.restoreCallingIdentity(identity);
3013 }
3014 }
3015
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003016 //
3017 // Internal helper methods.
3018 //
3019
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003020 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003021 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3022 *
3023 * @throws SecurityException if the caller does not have the required permission
3024 */
3025 private void enforceModifyPermission() {
3026 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3027 }
3028
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003029 /**
3030 * Make sure the caller is system.
3031 *
3032 * @throws SecurityException if the caller is not system.
3033 */
3034 private void enforceSystemCaller() {
3035 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3036 throw new SecurityException("Caller must be system");
3037 }
3038 }
3039
Shuo Qianf2b2df42019-11-13 17:43:31 -08003040 private void enforceActiveEmergencySessionPermission() {
3041 mApp.enforceCallingOrSelfPermission(
3042 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3043 }
3044
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003045 /**
3046 * Make sure the caller has the CALL_PHONE permission.
3047 *
3048 * @throws SecurityException if the caller does not have the required permission
3049 */
3050 private void enforceCallPermission() {
3051 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3052 }
3053
paulhu423b5f22019-08-23 19:17:33 +08003054 private void enforceSettingsPermission() {
3055 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003056 }
3057
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003058 private String createTelUrl(String number) {
3059 if (TextUtils.isEmpty(number)) {
3060 return null;
3061 }
3062
Jake Hambye994d462014-02-03 13:10:13 -08003063 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003064 }
3065
Ihab Awadf9e92732013-12-05 18:02:52 -08003066 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003067 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3068 }
3069
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003070 private static void logv(String msg) {
3071 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3072 }
3073
Ihab Awadf9e92732013-12-05 18:02:52 -08003074 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003075 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3076 }
3077
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003078 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003079 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003080 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003081 }
3082
Sanket Padawe356d7632015-06-22 14:03:32 -07003083 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003084 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003085 final long identity = Binder.clearCallingIdentity();
3086 try {
3087 final Phone phone = PhoneFactory.getPhone(slotIndex);
3088 if (phone == null) {
3089 return PhoneConstants.PHONE_TYPE_NONE;
3090 } else {
3091 return phone.getPhoneType();
3092 }
3093 } finally {
3094 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003095 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003096 }
3097
3098 /**
3099 * Returns the CDMA ERI icon index to display
3100 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003101 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003102 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3103 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3104 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003105 }
3106
Sanket Padawe356d7632015-06-22 14:03:32 -07003107 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003108 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3109 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003111 mApp, subId, callingPackage, callingFeatureId,
3112 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003113 return -1;
3114 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003115
3116 final long identity = Binder.clearCallingIdentity();
3117 try {
3118 final Phone phone = getPhone(subId);
3119 if (phone != null) {
3120 return phone.getCdmaEriIconIndex();
3121 } else {
3122 return -1;
3123 }
3124 } finally {
3125 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003127 }
3128
3129 /**
3130 * Returns the CDMA ERI icon mode,
3131 * 0 - ON
3132 * 1 - FLASHING
3133 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003134 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003135 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3136 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3137 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003138 }
3139
Sanket Padawe356d7632015-06-22 14:03:32 -07003140 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003141 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3142 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003143 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003144 mApp, subId, callingPackage, callingFeatureId,
3145 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003146 return -1;
3147 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003148
3149 final long identity = Binder.clearCallingIdentity();
3150 try {
3151 final Phone phone = getPhone(subId);
3152 if (phone != null) {
3153 return phone.getCdmaEriIconMode();
3154 } else {
3155 return -1;
3156 }
3157 } finally {
3158 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003159 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003160 }
3161
3162 /**
3163 * Returns the CDMA ERI text,
3164 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003165 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003166 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3167 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3168 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003169 }
3170
Sanket Padawe356d7632015-06-22 14:03:32 -07003171 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003172 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3173 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003174 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003175 mApp, subId, callingPackage, callingFeatureId,
3176 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003177 return null;
3178 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003179
3180 final long identity = Binder.clearCallingIdentity();
3181 try {
3182 final Phone phone = getPhone(subId);
3183 if (phone != null) {
3184 return phone.getCdmaEriText();
3185 } else {
3186 return null;
3187 }
3188 } finally {
3189 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003190 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003191 }
3192
3193 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003194 * Returns the CDMA MDN.
3195 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003196 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003197 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003198 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3199 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200
3201 final long identity = Binder.clearCallingIdentity();
3202 try {
3203 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003204 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205 return phone.getLine1Number();
3206 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003207 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003208 return null;
3209 }
3210 } finally {
3211 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003212 }
3213 }
3214
3215 /**
3216 * Returns the CDMA MIN.
3217 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003218 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003219 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3221 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003222
3223 final long identity = Binder.clearCallingIdentity();
3224 try {
3225 final Phone phone = getPhone(subId);
3226 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3227 return phone.getCdmaMin();
3228 } else {
3229 return null;
3230 }
3231 } finally {
3232 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003233 }
3234 }
3235
Hall Liud892bec2018-11-30 14:51:45 -08003236 @Override
3237 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3238 INumberVerificationCallback callback, String callingPackage) {
3239 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3240 != PERMISSION_GRANTED) {
3241 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3242 }
3243 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3244
3245 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3246 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3247 throw new SecurityException("Calling package must be configured in the device config");
3248 }
3249
3250 if (range == null) {
3251 throw new NullPointerException("Range must be non-null");
3252 }
3253
3254 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003255 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003256
3257 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3258 }
3259
Junda Liuca05d5d2014-08-14 22:36:34 -07003260 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003261 * Returns true if CDMA provisioning needs to run.
3262 */
3263 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003264 final long identity = Binder.clearCallingIdentity();
3265 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003266 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003267 } finally {
3268 Binder.restoreCallingIdentity(identity);
3269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003270 }
3271
3272 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003273 * Sets the voice mail number of a given subId.
3274 */
3275 @Override
3276 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003277 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3278 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003279
3280 final long identity = Binder.clearCallingIdentity();
3281 try {
3282 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3283 new Pair<String, String>(alphaTag, number), new Integer(subId));
3284 return success;
3285 } finally {
3286 Binder.restoreCallingIdentity(identity);
3287 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003288 }
3289
Ta-wei Yen87c49842016-05-13 21:19:52 -07003290 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003291 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3292 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003293 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3294 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003295 if (!TextUtils.equals(callingPackage, systemDialer)) {
3296 throw new SecurityException("caller must be system dialer");
3297 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003298
3299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3302 if (phoneAccountHandle == null) {
3303 return null;
3304 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003305 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003306 } finally {
3307 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003308 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003309 }
3310
3311 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003312 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3313 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003314 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003316 mApp, subId, callingPackage, callingFeatureId,
3317 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003318 return null;
3319 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003320
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003321 final long identity = Binder.clearCallingIdentity();
3322 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003323 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003324 } finally {
3325 Binder.restoreCallingIdentity(identity);
3326 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003327 }
3328
3329 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003330 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3331 VisualVoicemailSmsFilterSettings settings) {
3332 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003333
3334 final long identity = Binder.clearCallingIdentity();
3335 try {
3336 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003337 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003338 } finally {
3339 Binder.restoreCallingIdentity(identity);
3340 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003341 }
3342
3343 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003344 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3345 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003346
3347 final long identity = Binder.clearCallingIdentity();
3348 try {
3349 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003350 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003351 } finally {
3352 Binder.restoreCallingIdentity(identity);
3353 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003354 }
3355
3356 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003357 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3358 String callingPackage, int subId) {
3359 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003360
3361 final long identity = Binder.clearCallingIdentity();
3362 try {
3363 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003364 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003365 } finally {
3366 Binder.restoreCallingIdentity(identity);
3367 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003368 }
3369
3370 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003371 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003372 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003373
3374 final long identity = Binder.clearCallingIdentity();
3375 try {
3376 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003377 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003378 } finally {
3379 Binder.restoreCallingIdentity(identity);
3380 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003381 }
3382
3383 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003384 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3385 String callingAttributionTag, int subId, String number, int port, String text,
3386 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003387 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003388 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003389 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003390 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003391 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3392 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003393 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003394
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003395 /**
fionaxu0152e512016-11-14 13:36:14 -08003396 * Sets the voice activation state of a given subId.
3397 */
3398 @Override
3399 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3401 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003402
3403 final long identity = Binder.clearCallingIdentity();
3404 try {
3405 final Phone phone = getPhone(subId);
3406 if (phone != null) {
3407 phone.setVoiceActivationState(activationState);
3408 } else {
3409 loge("setVoiceActivationState fails with invalid subId: " + subId);
3410 }
3411 } finally {
3412 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003413 }
3414 }
3415
3416 /**
3417 * Sets the data activation state of a given subId.
3418 */
3419 @Override
3420 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3422 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003423
3424 final long identity = Binder.clearCallingIdentity();
3425 try {
3426 final Phone phone = getPhone(subId);
3427 if (phone != null) {
3428 phone.setDataActivationState(activationState);
3429 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003430 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003431 }
3432 } finally {
3433 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003434 }
3435 }
3436
3437 /**
3438 * Returns the voice activation state of a given subId.
3439 */
3440 @Override
3441 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003442 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003443
fionaxu0152e512016-11-14 13:36:14 -08003444 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003445 final long identity = Binder.clearCallingIdentity();
3446 try {
3447 if (phone != null) {
3448 return phone.getVoiceActivationState();
3449 } else {
3450 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3451 }
3452 } finally {
3453 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003454 }
3455 }
3456
3457 /**
3458 * Returns the data activation state of a given subId.
3459 */
3460 @Override
3461 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003462 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003463
fionaxu0152e512016-11-14 13:36:14 -08003464 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003465 final long identity = Binder.clearCallingIdentity();
3466 try {
3467 if (phone != null) {
3468 return phone.getDataActivationState();
3469 } else {
3470 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3471 }
3472 } finally {
3473 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003474 }
3475 }
3476
3477 /**
Wink Saville36469e72014-06-11 15:17:00 -07003478 * Returns the unread count of voicemails for a subId
3479 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003480 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003481 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3482 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003483 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003484 mApp, subId, callingPackage, callingFeatureId,
3485 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003486 return 0;
3487 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003488 final long identity = Binder.clearCallingIdentity();
3489 try {
3490 final Phone phone = getPhone(subId);
3491 if (phone != null) {
3492 return phone.getVoiceMessageCount();
3493 } else {
3494 return 0;
3495 }
3496 } finally {
3497 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003498 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003499 }
3500
3501 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003502 * returns true, if the device is in a state where both voice and data
3503 * are supported simultaneously. This can change based on location or network condition.
3504 */
3505 @Override
3506 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003507 final long identity = Binder.clearCallingIdentity();
3508 try {
3509 final Phone phone = getPhone(subId);
3510 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3511 } finally {
3512 Binder.restoreCallingIdentity(identity);
3513 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003514 }
3515
3516 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003517 * Send the dialer code if called from the current default dialer or the caller has
3518 * carrier privilege.
3519 * @param inputCode The dialer code to send
3520 */
3521 @Override
3522 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003523 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003524 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003525 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3526 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003527 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003528 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003529 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003530 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003531
3532 final long identity = Binder.clearCallingIdentity();
3533 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003534 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003535 } finally {
3536 Binder.restoreCallingIdentity(identity);
3537 }
fionaxu235cc5e2017-03-06 22:25:57 -08003538 }
3539
Pengquan Menga1bb6272018-09-06 09:59:22 -07003540 @Override
3541 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003542 TelephonyPermissions
3543 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3544 mApp, subId, "getNetworkSelectionMode");
3545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 if (!isActiveSubscription(subId)) {
3548 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3549 }
3550 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3551 } finally {
3552 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003553 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003554 }
3555
Brad Ebinger35c841c2018-10-01 10:40:55 -07003556 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003557 public boolean isInEmergencySmsMode() {
3558 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3559 final long identity = Binder.clearCallingIdentity();
3560 try {
3561 for (Phone phone : PhoneFactory.getPhones()) {
3562 if (phone.isInEmergencySmsMode()) {
3563 return true;
3564 }
3565 }
3566 } finally {
3567 Binder.restoreCallingIdentity(identity);
3568 }
3569 return false;
3570 }
3571
shilu366312e2019-12-17 09:28:10 -08003572 /**
3573 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3574 * @param subId The subscription to use to check the configuration.
3575 * @param c The callback that will be used to send the result.
3576 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003577 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003578 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3579 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003580 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3581 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003582
Brad Ebinger77b832e2019-10-17 17:03:22 -07003583 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3584 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3585 "IMS not available on device.");
3586 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003587 final long token = Binder.clearCallingIdentity();
3588 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003589 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003590 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003591 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003592 } catch (ImsException e) {
3593 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003594 } finally {
3595 Binder.restoreCallingIdentity(token);
3596 }
3597 }
3598
shilu366312e2019-12-17 09:28:10 -08003599 /**
3600 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3601 * @param subId The subscription to use to check the configuration.
3602 * @param c The callback that will be used to send the result.
3603 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003604 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003605 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003606 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3607 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003608 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3609 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3610 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003611 final long token = Binder.clearCallingIdentity();
3612 try {
3613 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3614 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3615 .removeRegistrationCallbackForSubscription(c, subId);
3616 } catch (ImsException e) {
3617 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3618 + "is inactive, ignoring unregister.");
3619 // If the subscription is no longer active, just return, since the callback
3620 // will already have been removed internally.
3621 } finally {
3622 Binder.restoreCallingIdentity(token);
3623 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003624 }
3625
Brad Ebinger774ba362019-10-22 17:36:18 -07003626 /**
3627 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3628 */
3629 @Override
3630 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3631 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3632 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3633 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3634 "IMS not available on device.");
3635 }
3636 final long token = Binder.clearCallingIdentity();
3637 try {
3638 Phone phone = getPhone(subId);
3639 if (phone == null) {
3640 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3641 + subId + "'");
3642 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3643 }
3644 phone.getImsRegistrationState(regState -> {
3645 try {
3646 consumer.accept((regState == null)
3647 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3648 } catch (RemoteException e) {
3649 // Ignore if the remote process is no longer available to call back.
3650 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3651 }
3652 });
3653 } finally {
3654 Binder.restoreCallingIdentity(token);
3655 }
3656 }
3657
3658 /**
3659 * Get the transport type for the IMS service registration state.
3660 */
3661 @Override
3662 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003663 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3664 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003665 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3666 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3667 "IMS not available on device.");
3668 }
3669 final long token = Binder.clearCallingIdentity();
3670 try {
3671 Phone phone = getPhone(subId);
3672 if (phone == null) {
3673 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3674 + subId + "'");
3675 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3676 }
3677 phone.getImsRegistrationTech(regTech -> {
3678 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3679 int regTechConverted = (regTech == null)
3680 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3681 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3682 regTechConverted);
3683 try {
3684 consumer.accept(regTechConverted);
3685 } catch (RemoteException e) {
3686 // Ignore if the remote process is no longer available to call back.
3687 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3688 }
3689 });
3690 } finally {
3691 Binder.restoreCallingIdentity(token);
3692 }
3693 }
3694
shilu366312e2019-12-17 09:28:10 -08003695 /**
3696 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3697 * @param subId The subscription to use to check the configuration.
3698 * @param c The callback that will be used to send the result.
3699 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003700 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003701 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3702 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003703 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3704 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003705 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3706 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3707 "IMS not available on device.");
3708 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003709 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3710 final long token = Binder.clearCallingIdentity();
3711 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003712 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003713 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003714 } catch (ImsException e) {
3715 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003716 } finally {
3717 Binder.restoreCallingIdentity(token);
3718 }
3719 }
3720
shilu366312e2019-12-17 09:28:10 -08003721 /**
3722 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3723 * @param subId The subscription to use to check the configuration.
3724 * @param c The callback that will be used to send the result.
3725 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003726 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003727 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003728 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3729 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003730 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3731 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3732 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003733
3734 final long token = Binder.clearCallingIdentity();
3735 try {
3736 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3737 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003738 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003739 } catch (ImsException e) {
3740 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3741 + "is inactive, ignoring unregister.");
3742 // If the subscription is no longer active, just return, since the callback
3743 // will already have been removed internally.
3744 } finally {
3745 Binder.restoreCallingIdentity(token);
3746 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003747 }
3748
3749 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003750 public boolean isCapable(int subId, int capability, int regTech) {
3751 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003752 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3753 final long token = Binder.clearCallingIdentity();
3754 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003755 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003756 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003757 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003758 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3759 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003760 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003761 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3762 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003763 } finally {
3764 Binder.restoreCallingIdentity(token);
3765 }
3766 }
3767
3768 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003769 public boolean isAvailable(int subId, int capability, int regTech) {
3770 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003771 final long token = Binder.clearCallingIdentity();
3772 try {
3773 Phone phone = getPhone(subId);
3774 if (phone == null) return false;
3775 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003776 } catch (com.android.ims.ImsException e) {
3777 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3778 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003779 } finally {
3780 Binder.restoreCallingIdentity(token);
3781 }
3782 }
3783
Brad Ebinger77b832e2019-10-17 17:03:22 -07003784 /**
3785 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3786 * subscription.
3787 * @param subId The subscription to use to check the configuration.
3788 * @param callback The callback that will be used to send the result.
3789 * @param capability The MmTelFeature capability that will be used to send the result.
3790 * @param transportType The transport type of the MmTelFeature capability.
3791 */
3792 @Override
3793 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3794 int transportType) {
3795 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3796 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3797 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3798 "IMS not available on device.");
3799 }
3800 final long token = Binder.clearCallingIdentity();
3801 try {
3802 int slotId = getSlotIndex(subId);
3803 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3804 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3805 + subId + "'");
3806 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3807 }
3808 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3809 transportType, aBoolean -> {
3810 try {
3811 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3812 } catch (RemoteException e) {
3813 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3814 + "running. Ignore");
3815 }
3816 });
3817 } finally {
3818 Binder.restoreCallingIdentity(token);
3819 }
3820 }
3821
shilu366312e2019-12-17 09:28:10 -08003822 /**
3823 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3824 * @param subId The subscription to use to check the configuration.
3825 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003826 @Override
3827 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003828 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3829 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003830
Brad Ebinger35c841c2018-10-01 10:40:55 -07003831 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3832 final long token = Binder.clearCallingIdentity();
3833 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003834 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003835 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003836 } catch (ImsException e) {
3837 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003838 } finally {
3839 Binder.restoreCallingIdentity(token);
3840 }
3841 }
3842
3843 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003844 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003846 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003847 final long identity = Binder.clearCallingIdentity();
3848 try {
3849 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003850 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003851 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003852 } catch (ImsException e) {
3853 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003854 } finally {
3855 Binder.restoreCallingIdentity(identity);
3856 }
3857 }
3858
shilu366312e2019-12-17 09:28:10 -08003859 /**
3860 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3861 * @param subId The subscription to use to check the configuration.
3862 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003863 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003864 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003865 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3866 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003867 final long identity = Binder.clearCallingIdentity();
3868 try {
3869 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003870 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3871 } catch (ImsException e) {
3872 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003873 } finally {
3874 Binder.restoreCallingIdentity(identity);
3875 }
3876 }
3877
3878 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003879 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003881 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003882 final long identity = Binder.clearCallingIdentity();
3883 try {
3884 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003885 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003886 } catch (ImsException e) {
3887 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003888 } finally {
3889 Binder.restoreCallingIdentity(identity);
3890 }
3891 }
3892
shilu366312e2019-12-17 09:28:10 -08003893 /**
3894 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3895 * @param subId The subscription to use to check the configuration.
3896 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003897 @Override
3898 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003899 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3900 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003901 final long identity = Binder.clearCallingIdentity();
3902 try {
3903 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003904 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003905 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003906 } catch (ImsException e) {
3907 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003908 } finally {
3909 Binder.restoreCallingIdentity(identity);
3910 }
3911 }
3912
3913 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003914 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003915 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003916 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003917 final long identity = Binder.clearCallingIdentity();
3918 try {
3919 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003920 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003921 } catch (ImsException e) {
3922 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003923 } finally {
3924 Binder.restoreCallingIdentity(identity);
3925 }
3926 }
3927
shilu366312e2019-12-17 09:28:10 -08003928 /**
3929 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3930 * @param subId The subscription to use to check the configuration.
3931 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003932 @Override
3933 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003934 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3935 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003936 final long identity = Binder.clearCallingIdentity();
3937 try {
3938 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003939 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003940 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003941 } catch (ImsException e) {
3942 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003943 } finally {
3944 Binder.restoreCallingIdentity(identity);
3945 }
3946 }
3947
3948 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003949 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003951 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003952 final long identity = Binder.clearCallingIdentity();
3953 try {
3954 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003955 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003956 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003957 } catch (ImsException e) {
3958 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003959 } finally {
3960 Binder.restoreCallingIdentity(identity);
3961 }
3962 }
3963
3964 @Override
3965 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3966 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3967 "setVoWiFiNonPersistent");
3968 final long identity = Binder.clearCallingIdentity();
3969 try {
3970 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003971 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003972 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003973 } catch (ImsException e) {
3974 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003975 } finally {
3976 Binder.restoreCallingIdentity(identity);
3977 }
3978 }
3979
shilu366312e2019-12-17 09:28:10 -08003980 /**
3981 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3982 * @param subId The subscription to use to check the configuration.
3983 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003984 @Override
3985 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003986 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3987 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003988 final long identity = Binder.clearCallingIdentity();
3989 try {
3990 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003991 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003992 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003993 } catch (ImsException e) {
3994 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003995 } finally {
3996 Binder.restoreCallingIdentity(identity);
3997 }
3998 }
3999
4000 @Override
4001 public void setVoWiFiModeSetting(int subId, int mode) {
4002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4003 "setVoWiFiModeSetting");
4004 final long identity = Binder.clearCallingIdentity();
4005 try {
4006 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004007 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004008 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
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
4016 @Override
4017 public int getVoWiFiRoamingModeSetting(int subId) {
4018 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4019 final long identity = Binder.clearCallingIdentity();
4020 try {
4021 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004022 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004023 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004024 } catch (ImsException e) {
4025 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004026 } finally {
4027 Binder.restoreCallingIdentity(identity);
4028 }
4029 }
4030
4031 @Override
4032 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4034 "setVoWiFiRoamingModeSetting");
4035 final long identity = Binder.clearCallingIdentity();
4036 try {
4037 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004038 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004040 } catch (ImsException e) {
4041 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004042 } finally {
4043 Binder.restoreCallingIdentity(identity);
4044 }
4045 }
4046
4047 @Override
4048 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4050 "setRttCapabilityEnabled");
4051 final long identity = Binder.clearCallingIdentity();
4052 try {
4053 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004054 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4055 } catch (ImsException e) {
4056 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004057 } finally {
4058 Binder.restoreCallingIdentity(identity);
4059 }
4060 }
4061
shilu366312e2019-12-17 09:28:10 -08004062 /**
4063 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4064 * @param subId The subscription to use to check the configuration.
4065 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004066 @Override
4067 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004068 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4069 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004070 final long identity = Binder.clearCallingIdentity();
4071 try {
4072 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004073 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004075 } catch (ImsException e) {
4076 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004077 } finally {
4078 Binder.restoreCallingIdentity(identity);
4079 }
4080 }
4081
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004082 @Override
4083 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4084 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4085 final long identity = Binder.clearCallingIdentity();
4086 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004087 if (!isImsAvailableOnDevice()) {
4088 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4089 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004090 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004091 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004092 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004093 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004094 } catch (ImsException e) {
4095 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004096 } finally {
4097 Binder.restoreCallingIdentity(identity);
4098 }
4099 }
4100
4101 @Override
4102 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4103 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4104 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004105 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4106 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4107 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004108 try {
4109 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004110 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004111 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004112 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004113 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4114 + "is inactive, ignoring unregister.");
4115 // If the subscription is no longer active, just return, since the callback will already
4116 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004117 } finally {
4118 Binder.restoreCallingIdentity(identity);
4119 }
4120 }
4121
allenwtsu99c623b2020-01-03 18:24:23 +08004122
4123 private void checkModifyPhoneStatePermission(int subId, String message) {
4124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4125 message);
4126 }
4127
4128 private boolean isImsProvisioningRequired(int subId, int capability,
4129 boolean isMmtelCapability) {
4130 Phone phone = getPhone(subId);
4131 if (phone == null) {
4132 loge("phone instance null for subid " + subId);
4133 return false;
4134 }
4135 if (isMmtelCapability) {
4136 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4137 return false;
4138 }
4139 } else {
4140 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4141 return false;
4142 }
4143 }
4144 return true;
4145 }
4146
4147 @Override
4148 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4149 boolean isProvisioned) {
4150 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4151
4152 final long identity = Binder.clearCallingIdentity();
4153 try {
4154 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4155 if (!isImsProvisioningRequired(subId, capability, false)) {
4156 return;
4157 }
4158
4159 // this capability requires provisioning, route to the correct API.
4160 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4161 switch (capability) {
4162 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4163 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4164 ims.setEabProvisioned(isProvisioned);
4165 break;
4166 default: {
4167 throw new IllegalArgumentException("Tried to set provisioning for "
4168 + "rcs capability '" + capability + "', which does not require "
4169 + "provisioning.");
4170 }
4171 }
4172 } finally {
4173 Binder.restoreCallingIdentity(identity);
4174 }
4175
4176 }
4177
4178
4179 @Override
4180 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4181 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4182 final long identity = Binder.clearCallingIdentity();
4183 try {
4184 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4185 if (!isImsProvisioningRequired(subId, capability, false)) {
4186 return true;
4187 }
4188
4189 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4190 switch (capability) {
4191 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4192 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4193 return ims.isEabProvisionedOnDevice();
4194
4195 default: {
4196 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4197 + "capability '" + capability + "', which does not require "
4198 + "provisioning.");
4199 }
4200 }
4201
4202 } finally {
4203 Binder.restoreCallingIdentity(identity);
4204 }
4205 }
4206
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004207 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004208 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4209 boolean isProvisioned) {
4210 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4211 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4212 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4213 }
allenwtsu99c623b2020-01-03 18:24:23 +08004214 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004215 final long identity = Binder.clearCallingIdentity();
4216 try {
4217 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004218 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004219 return;
4220 }
4221
4222 // this capability requires provisioning, route to the correct API.
4223 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4224 switch (capability) {
4225 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4226 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4227 ims.setVolteProvisioned(isProvisioned);
4228 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4229 ims.setWfcProvisioned(isProvisioned);
4230 }
4231 break;
4232 }
4233 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4234 // There is currently no difference in VT provisioning type.
4235 ims.setVtProvisioned(isProvisioned);
4236 break;
4237 }
4238 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4239 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4240 // change the capability of the feature instead if needed.
4241 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4242 == isProvisioned) {
4243 // No change in provisioning.
4244 return;
4245 }
4246 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4247 try {
4248 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004249 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004250 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4251 + ", Exception" + e.getMessage());
4252 }
4253 break;
4254 }
4255 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004256 throw new IllegalArgumentException("Tried to set provisioning for "
4257 + "MmTel capability '" + capability + "', which does not require "
4258 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004259 }
4260 }
4261
4262 } finally {
4263 Binder.restoreCallingIdentity(identity);
4264 }
4265 }
4266
4267 @Override
4268 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4269 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4270 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4271 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4272 }
4273 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4274 final long identity = Binder.clearCallingIdentity();
4275 try {
4276 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004277 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004278 return true;
4279 }
4280
4281 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4282 switch (capability) {
4283 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4284 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4285 return ims.isVolteProvisionedOnDevice();
4286 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4287 return ims.isWfcProvisionedOnDevice();
4288 }
4289 // This should never happen, since we are checking tech above to make sure it
4290 // is either LTE or IWLAN.
4291 throw new IllegalArgumentException("Invalid radio technology for voice "
4292 + "capability.");
4293 }
4294 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4295 // There is currently no difference in VT provisioning type.
4296 return ims.isVtProvisionedOnDevice();
4297 }
4298 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4299 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4300 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4301 }
4302 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004303 throw new IllegalArgumentException(
4304 "Tried to get provisioning for MmTel capability '" + capability
4305 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004306 }
4307 }
4308
4309 } finally {
4310 Binder.restoreCallingIdentity(identity);
4311 }
4312 }
4313
4314 @Override
4315 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4316 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4317 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4318 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4319 }
4320 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4321 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4322 return (provisionedBits & capability) > 0;
4323 }
4324
4325 @Override
4326 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4327 boolean isProvisioned) {
4328 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4329 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4330 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4331 }
4332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4333 "setProvisioningStatusForCapability");
4334 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4335 // If the current provisioning status for capability already matches isProvisioned,
4336 // do nothing.
4337 if (((provisionedBits & capability) > 0) == isProvisioned) {
4338 return;
4339 }
4340 if (isProvisioned) {
4341 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4342 } else {
4343 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4344 }
4345 }
4346
4347 /**
4348 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4349 * technology. The bitfield should mirror the bitfield defined by
4350 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4351 */
4352 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4353 String key = getMmTelProvisioningKey(subId, tech);
4354 // Default is no capabilities are provisioned.
4355 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4356 }
4357
4358 /**
4359 * Sets the MmTel capability provisioning bitfield (defined by
4360 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4361 * technology specified.
4362 *
4363 * Note: This is a synchronous command and should not be called on UI thread.
4364 */
4365 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4366 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4367 String key = getMmTelProvisioningKey(subId, tech);
4368 editor.putInt(key, newField);
4369 editor.commit();
4370 }
4371
4372 private static String getMmTelProvisioningKey(int subId, int tech) {
4373 // resulting key is provision_ims_mmtel_{subId}_{tech}
4374 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4375 }
4376
4377 /**
4378 * Query CarrierConfig to see if the specified capability requires provisioning for the
4379 * carrier associated with the subscription id.
4380 */
4381 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4382 int capability) {
4383 CarrierConfigManager configManager = new CarrierConfigManager(context);
4384 PersistableBundle c = configManager.getConfigForSubId(subId);
4385 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004386 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004387 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4388 false);
4389 boolean requireVoiceVtProvisioning = c.getBoolean(
4390 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4391
4392 // First check to make sure that the capability requires provisioning.
4393 switch (capability) {
4394 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4395 // intentional fallthrough
4396 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4397 if (requireVoiceVtProvisioning) {
4398 // Voice and Video requires provisioning
4399 return true;
4400 }
4401 break;
4402 }
4403 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4404 if (requireUtProvisioning) {
4405 // UT requires provisioning
4406 return true;
4407 }
4408 break;
4409 }
4410 }
4411 return false;
4412 }
4413
allenwtsu99c623b2020-01-03 18:24:23 +08004414 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4415 int capability) {
4416 CarrierConfigManager configManager = new CarrierConfigManager(context);
4417 PersistableBundle c = configManager.getConfigForSubId(subId);
4418
4419 boolean requireRcsProvisioning = c.getBoolean(
4420 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4421
4422 // First check to make sure that the capability requires provisioning.
4423 switch (capability) {
4424 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4425 // intentional fallthrough
4426 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4427 if (requireRcsProvisioning) {
4428 // OPTION or PRESENCE requires provisioning
4429 return true;
4430 }
4431 break;
4432 }
4433 }
4434 return false;
4435 }
4436
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004437 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004438 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004439 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4440 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4441 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004442 enforceReadPrivilegedPermission("getImsProvisioningInt");
4443 final long identity = Binder.clearCallingIdentity();
4444 try {
4445 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004446 int slotId = getSlotIndex(subId);
4447 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4448 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4449 + subId + "' for key:" + key);
4450 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4451 }
4452 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004453 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004454 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4455 + subId + "' for key:" + key);
4456 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004457 } finally {
4458 Binder.restoreCallingIdentity(identity);
4459 }
4460 }
4461
4462 @Override
4463 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004464 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4465 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4466 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004467 enforceReadPrivilegedPermission("getImsProvisioningString");
4468 final long identity = Binder.clearCallingIdentity();
4469 try {
4470 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004471 int slotId = getSlotIndex(subId);
4472 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4473 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4474 + subId + "' for key:" + key);
4475 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4476 }
4477 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004478 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004479 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4480 + subId + "' for key:" + key);
4481 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004482 } finally {
4483 Binder.restoreCallingIdentity(identity);
4484 }
4485 }
4486
4487 @Override
4488 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004489 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4490 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4491 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4493 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004494 final long identity = Binder.clearCallingIdentity();
4495 try {
4496 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004497 int slotId = getSlotIndex(subId);
4498 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4499 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4500 + subId + "' for key:" + key);
4501 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4502 }
4503 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004504 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004505 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4506 + "' for key:" + key);
4507 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004508 } finally {
4509 Binder.restoreCallingIdentity(identity);
4510 }
4511 }
4512
4513 @Override
4514 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004515 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4516 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4517 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004518 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4519 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004520 final long identity = Binder.clearCallingIdentity();
4521 try {
4522 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004523 int slotId = getSlotIndex(subId);
4524 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4525 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4526 + subId + "' for key:" + key);
4527 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4528 }
4529 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004530 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004531 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4532 + "' for key:" + key);
4533 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004534 } finally {
4535 Binder.restoreCallingIdentity(identity);
4536 }
4537 }
4538
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004539 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004540 int slotId = SubscriptionManager.getSlotIndex(subId);
4541 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004542 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4543 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004544 }
4545 return slotId;
4546 }
4547
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004548 private int getSlotIndex(int subId) {
4549 int slotId = SubscriptionManager.getSlotIndex(subId);
4550 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4551 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4552 }
4553 return slotId;
4554 }
4555
Wink Saville36469e72014-06-11 15:17:00 -07004556 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004557 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004558 */
4559 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004560 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4561 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004562 final int targetSdk = getTargetSdk(callingPackage);
4563 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004564 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004565 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004566 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004567 mApp, subId, callingPackage, callingFeatureId,
4568 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004569 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4570 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004572 final long identity = Binder.clearCallingIdentity();
4573 try {
4574 final Phone phone = getPhone(subId);
4575 if (phone != null) {
4576 return phone.getServiceState().getDataNetworkType();
4577 } else {
4578 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4579 }
4580 } finally {
4581 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004583 }
4584
4585 /**
4586 * Returns the data network type
4587 */
4588 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004589 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4590 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4591 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004592 }
4593
4594 /**
4595 * Returns the data network type for a subId
4596 */
4597 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004598 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4599 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004600 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004601 mApp, subId, callingPackage, callingFeatureId,
4602 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004603 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4604 }
4605
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004606 final long identity = Binder.clearCallingIdentity();
4607 try {
4608 final Phone phone = getPhone(subId);
4609 if (phone != null) {
4610 return phone.getServiceState().getDataNetworkType();
4611 } else {
4612 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4613 }
4614 } finally {
4615 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004616 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004617 }
4618
4619 /**
Wink Saville36469e72014-06-11 15:17:00 -07004620 * Returns the Voice network type for a subId
4621 */
4622 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004623 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4624 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004625 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004626 mApp, subId, callingPackage, callingFeatureId,
4627 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004628 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4629 }
4630
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004631 final long identity = Binder.clearCallingIdentity();
4632 try {
4633 final Phone phone = getPhone(subId);
4634 if (phone != null) {
4635 return phone.getServiceState().getVoiceNetworkType();
4636 } else {
4637 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4638 }
4639 } finally {
4640 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004641 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004642 }
4643
4644 /**
4645 * @return true if a ICC card is present
4646 */
4647 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004648 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004649 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4650 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004651 }
4652
4653 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004654 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004655 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004656 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004657 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004658 final long identity = Binder.clearCallingIdentity();
4659 try {
4660 final Phone phone = PhoneFactory.getPhone(slotIndex);
4661 if (phone != null) {
4662 return phone.getIccCard().hasIccCard();
4663 } else {
4664 return false;
4665 }
4666 } finally {
4667 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004668 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004669 }
4670
4671 /**
4672 * Return if the current radio is LTE on CDMA. This
4673 * is a tri-state return value as for a period of time
4674 * the mode may be unknown.
4675 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004676 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004677 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004678 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004679 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004680 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004681 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4682 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4683 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004684 }
4685
Sanket Padawe356d7632015-06-22 14:03:32 -07004686 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004687 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4688 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004689 try {
4690 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4691 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004692 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4693 }
4694
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004695 final long identity = Binder.clearCallingIdentity();
4696 try {
4697 final Phone phone = getPhone(subId);
4698 if (phone == null) {
4699 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4700 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004701 return TelephonyProperties.lte_on_cdma_device()
4702 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004703 }
4704 } finally {
4705 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004706 }
Wink Saville36469e72014-06-11 15:17:00 -07004707 }
4708
Wink Saville36469e72014-06-11 15:17:00 -07004709 /**
4710 * {@hide}
4711 * Returns Default subId, 0 in the case of single standby.
4712 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004713 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004714 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004715 }
4716
Shishir Agrawala9f32182016-04-12 12:00:16 -07004717 private int getSlotForDefaultSubscription() {
4718 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4719 }
4720
Wink Savilleb564aae2014-10-23 10:18:09 -07004721 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004722 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004723 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004724
Pengquan Menge92a50d2018-09-21 15:54:48 -07004725 private boolean isActiveSubscription(int subId) {
4726 return mSubscriptionController.isActiveSubId(subId);
4727 }
4728
Ihab Awadf2177b72013-11-25 13:33:23 -08004729 /**
4730 * @see android.telephony.TelephonyManager.WifiCallingChoices
4731 */
4732 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004733 final long identity = Binder.clearCallingIdentity();
4734 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004735 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004736 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4737 getWhenToMakeWifiCallsDefaultPreference());
4738 } finally {
4739 Binder.restoreCallingIdentity(identity);
4740 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004741 }
4742
4743 /**
4744 * @see android.telephony.TelephonyManager.WifiCallingChoices
4745 */
4746 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004747 final long identity = Binder.clearCallingIdentity();
4748 try {
4749 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004750 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004751 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4752 } finally {
4753 Binder.restoreCallingIdentity(identity);
4754 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004755 }
4756
Sailesh Nepald1e68152013-12-12 19:08:02 -08004757 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004758 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004759 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004760 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004761
Jordan Liu4c733742019-02-28 12:03:40 -08004762 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4763 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4764 if (phoneId == -1) {
4765 throw new IllegalArgumentException("Given slot index: " + slotIndex
4766 + " does not correspond to an active phone");
4767 }
4768 return PhoneFactory.getPhone(phoneId);
4769 }
4770
Shishir Agrawal566b7612013-10-28 14:41:00 -07004771 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004772 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4773 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4775 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004776 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004777 if (DBG) {
4778 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4779 }
4780 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4781 p2);
4782 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004783
Jordan Liu4c733742019-02-28 12:03:40 -08004784
4785 @Override
4786 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4787 int slotIndex, String callingPackage, String aid, int p2) {
4788 enforceModifyPermission();
4789 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4790 if (DBG) {
4791 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4792 }
4793 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4794 callingPackage, aid, p2);
4795 }
4796
4797 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4798 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004799 final long identity = Binder.clearCallingIdentity();
4800 try {
4801 if (TextUtils.equals(ISDR_AID, aid)) {
4802 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004803 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4804 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004805 if (bestComponent == null
4806 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4807 loge("The calling package is not allowed to access ISD-R.");
4808 throw new SecurityException(
4809 "The calling package is not allowed to access ISD-R.");
4810 }
Derek Tan740e1672017-06-27 14:56:27 -07004811 }
Derek Tan740e1672017-06-27 14:56:27 -07004812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004813 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004814 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4815 null /* workSource */);
4816 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004817 return response;
4818 } finally {
4819 Binder.restoreCallingIdentity(identity);
4820 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004821 }
4822
4823 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004824 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4826 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004827 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4828 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4829 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004830
Jordan Liu4c733742019-02-28 12:03:40 -08004831 @Override
4832 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4833 enforceModifyPermission();
4834 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4835 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4836 channel);
4837 }
4838
4839 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004840 final long identity = Binder.clearCallingIdentity();
4841 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004842 if (channel < 0) {
4843 return false;
4844 }
Jordan Liu4c733742019-02-28 12:03:40 -08004845 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4846 null /* workSource */);
4847 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004848 return success;
4849 } finally {
4850 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004851 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004852 }
4853
4854 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004855 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004856 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4858 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004859 if (DBG) {
4860 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4861 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4862 + p3 + " data=" + data);
4863 }
4864 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4865 command, p1, p2, p3, data);
4866 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004867
Jordan Liu4c733742019-02-28 12:03:40 -08004868 @Override
4869 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4870 int command, int p1, int p2, int p3, String data) {
4871 enforceModifyPermission();
4872 if (DBG) {
4873 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4874 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4875 + p3 + " data=" + data);
4876 }
4877 return iccTransmitApduLogicalChannelWithPermission(
4878 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4879 data);
4880 }
4881
4882 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4883 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004884 final long identity = Binder.clearCallingIdentity();
4885 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004886 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004887 return "";
4888 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004889
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004890 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004891 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4892 null /* workSource */);
4893 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004894
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004895 // Append the returned status code to the end of the response payload.
4896 String s = Integer.toHexString(
4897 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4898 if (response.payload != null) {
4899 s = IccUtils.bytesToHexString(response.payload) + s;
4900 }
4901 return s;
4902 } finally {
4903 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004904 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004905 }
Jake Hambye994d462014-02-03 13:10:13 -08004906
Evan Charltonc66da362014-05-16 14:06:40 -07004907 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004908 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4909 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4911 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004912 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004913 if (DBG) {
4914 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4915 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4916 }
4917 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4918 cla, command, p1, p2, p3, data);
4919 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004920
Jordan Liu4c733742019-02-28 12:03:40 -08004921 @Override
4922 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4923 int command, int p1, int p2, int p3, String data) {
4924 enforceModifyPermission();
4925 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4926 if (DBG) {
4927 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4928 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4929 + " data=" + data);
4930 }
4931
4932 return iccTransmitApduBasicChannelWithPermission(
4933 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4934 p2, p3, data);
4935 }
4936
4937 // open APDU basic channel assuming the caller has sufficient permissions
4938 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4939 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004940 final long identity = Binder.clearCallingIdentity();
4941 try {
4942 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4943 && TextUtils.equals(ISDR_AID, data)) {
4944 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004945 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4946 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004947 if (bestComponent == null
4948 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4949 loge("The calling package is not allowed to select ISD-R.");
4950 throw new SecurityException(
4951 "The calling package is not allowed to select ISD-R.");
4952 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004953 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004954
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004955 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004956 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4957 null /* workSource */);
4958 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004959
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004960 // Append the returned status code to the end of the response payload.
4961 String s = Integer.toHexString(
4962 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4963 if (response.payload != null) {
4964 s = IccUtils.bytesToHexString(response.payload) + s;
4965 }
4966 return s;
4967 } finally {
4968 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004969 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004970 }
4971
4972 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004973 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004974 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4976 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004978 final long identity = Binder.clearCallingIdentity();
4979 try {
4980 if (DBG) {
4981 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4982 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4983 }
4984
4985 IccIoResult response =
4986 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4987 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4988 subId);
4989
4990 if (DBG) {
4991 log("Exchange SIM_IO [R]" + response);
4992 }
4993
4994 byte[] result = null;
4995 int length = 2;
4996 if (response.payload != null) {
4997 length = 2 + response.payload.length;
4998 result = new byte[length];
4999 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5000 } else {
5001 result = new byte[length];
5002 }
5003
5004 result[length - 1] = (byte) response.sw2;
5005 result[length - 2] = (byte) response.sw1;
5006 return result;
5007 } finally {
5008 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005009 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005010 }
5011
Nathan Haroldb3014052017-01-25 15:57:32 -08005012 /**
5013 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5014 * on a particular subscription
5015 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005016 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5017 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005018 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005019 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005020 return null;
5021 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005022
5023 final long identity = Binder.clearCallingIdentity();
5024 try {
5025 if (appType != TelephonyManager.APPTYPE_USIM
5026 && appType != TelephonyManager.APPTYPE_SIM) {
5027 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5028 return null;
5029 }
5030 Object response = sendRequest(
5031 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5032 if (response instanceof String[]) {
5033 return (String[]) response;
5034 }
yincheng zhaod698b842019-09-06 17:06:54 -07005035 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005036 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005037 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038 } finally {
5039 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005040 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005041 }
5042
yincheng zhaod698b842019-09-06 17:06:54 -07005043 /**
5044 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5045 * subscription.
5046 *
5047 * @param subId the id of the subscription.
5048 * @param appType the uicc app type, must be USIM or SIM.
5049 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5050 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005051 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005052 * @return number of fplmns that is successfully written to the SIM.
5053 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005054 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5055 String callingFeatureId) {
5056 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5057 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005058 if (DBG) logv("no permissions for setForbiddenplmns");
5059 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5060 }
5061 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5062 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5063 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5064 }
5065 if (fplmns == null) {
5066 throw new IllegalArgumentException("Fplmn List provided is null");
5067 }
5068 for (String fplmn : fplmns) {
5069 if (!CellIdentity.isValidPlmn(fplmn)) {
5070 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5071 }
5072 }
5073 final long identity = Binder.clearCallingIdentity();
5074 try {
5075 Object response = sendRequest(
5076 CMD_SET_FORBIDDEN_PLMNS,
5077 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5078 subId);
5079 return (int) response;
5080 } finally {
5081 Binder.restoreCallingIdentity(identity);
5082 }
5083 }
5084
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005085 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005086 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5088 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005090 final long identity = Binder.clearCallingIdentity();
5091 try {
5092 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5093 if (response.payload == null) {
5094 return "";
5095 }
Evan Charltonc66da362014-05-16 14:06:40 -07005096
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005097 // Append the returned status code to the end of the response payload.
5098 String s = Integer.toHexString(
5099 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5100 s = IccUtils.bytesToHexString(response.payload) + s;
5101 return s;
5102 } finally {
5103 Binder.restoreCallingIdentity(identity);
5104 }
Evan Charltonc66da362014-05-16 14:06:40 -07005105 }
5106
Jake Hambye994d462014-02-03 13:10:13 -08005107 /**
5108 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5109 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5110 *
5111 * @param itemID the ID of the item to read
5112 * @return the NV item as a String, or null on error.
5113 */
5114 @Override
5115 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005116 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005117 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5118 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005119
5120 final long identity = Binder.clearCallingIdentity();
5121 try {
5122 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005123 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005124 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5125 return value;
5126 } finally {
5127 Binder.restoreCallingIdentity(identity);
5128 }
Jake Hambye994d462014-02-03 13:10:13 -08005129 }
5130
5131 /**
5132 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5133 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5134 *
5135 * @param itemID the ID of the item to read
5136 * @param itemValue the value to write, as a String
5137 * @return true on success; false on any failure
5138 */
5139 @Override
5140 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005141 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005142 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5143 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005144
5145 final long identity = Binder.clearCallingIdentity();
5146 try {
5147 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5148 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005149 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005150 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5151 return success;
5152 } finally {
5153 Binder.restoreCallingIdentity(identity);
5154 }
Jake Hambye994d462014-02-03 13:10:13 -08005155 }
5156
5157 /**
5158 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5159 * Used for device configuration by some CDMA operators.
5160 *
5161 * @param preferredRoamingList byte array containing the new PRL
5162 * @return true on success; false on any failure
5163 */
5164 @Override
5165 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5167 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168
5169 final long identity = Binder.clearCallingIdentity();
5170 try {
5171 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5172 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5173 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5174 return success;
5175 } finally {
5176 Binder.restoreCallingIdentity(identity);
5177 }
Jake Hambye994d462014-02-03 13:10:13 -08005178 }
5179
5180 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005181 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005182 * Used for device configuration by some CDMA operators.
5183 *
chen xu6dac5ab2018-10-26 17:39:23 -07005184 * @param slotIndex - device slot.
5185 *
Jake Hambye994d462014-02-03 13:10:13 -08005186 * @return true on success; false on any failure
5187 */
5188 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005189 public boolean resetModemConfig(int slotIndex) {
5190 Phone phone = PhoneFactory.getPhone(slotIndex);
5191 if (phone != null) {
5192 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5193 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005194
chen xu6dac5ab2018-10-26 17:39:23 -07005195 final long identity = Binder.clearCallingIdentity();
5196 try {
5197 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5198 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5199 return success;
5200 } finally {
5201 Binder.restoreCallingIdentity(identity);
5202 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005203 }
chen xu6dac5ab2018-10-26 17:39:23 -07005204 return false;
5205 }
5206
5207 /**
5208 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5209 *
5210 * @param slotIndex - device slot.
5211 *
5212 * @return true on success; false on any failure
5213 */
5214 @Override
5215 public boolean rebootModem(int slotIndex) {
5216 Phone phone = PhoneFactory.getPhone(slotIndex);
5217 if (phone != null) {
5218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5219 mApp, phone.getSubId(), "rebootModem");
5220
5221 final long identity = Binder.clearCallingIdentity();
5222 try {
5223 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5224 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5225 return success;
5226 } finally {
5227 Binder.restoreCallingIdentity(identity);
5228 }
5229 }
5230 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005231 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005232
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005233 public String[] getPcscfAddress(String apnType, String callingPackage,
5234 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005235 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005236 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5237 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005238 return new String[0];
5239 }
5240
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 final long identity = Binder.clearCallingIdentity();
5242 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005243 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244 } finally {
5245 Binder.restoreCallingIdentity(identity);
5246 }
Wink Saville36469e72014-06-11 15:17:00 -07005247 }
5248
Brad Ebinger51f743a2017-01-23 13:50:20 -08005249 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005250 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5251 * {@link #disableIms(int)}.
5252 * @param slotIndex device slot.
5253 */
5254 public void resetIms(int slotIndex) {
5255 enforceModifyPermission();
5256
5257 final long identity = Binder.clearCallingIdentity();
5258 try {
5259 if (mImsResolver == null) {
5260 // may happen if the does not support IMS.
5261 return;
5262 }
5263 mImsResolver.disableIms(slotIndex);
5264 mImsResolver.enableIms(slotIndex);
5265 } finally {
5266 Binder.restoreCallingIdentity(identity);
5267 }
5268 }
5269
5270 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005271 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5272 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005273 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005274 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005275 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276
5277 final long identity = Binder.clearCallingIdentity();
5278 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005279 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005280 // may happen if the device does not support IMS.
5281 return;
5282 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005283 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 } finally {
5285 Binder.restoreCallingIdentity(identity);
5286 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005287 }
5288
5289 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005290 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5291 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005292 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005293 public void disableIms(int slotId) {
5294 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005295
5296 final long identity = Binder.clearCallingIdentity();
5297 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005298 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005299 // may happen if the device does not support IMS.
5300 return;
5301 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005302 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005303 } finally {
5304 Binder.restoreCallingIdentity(identity);
5305 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005306 }
5307
5308 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005309 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5310 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005311 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005312 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005313 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005314 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005315
5316 final long identity = Binder.clearCallingIdentity();
5317 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005318 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005319 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5320 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005321 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005322 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323 } finally {
5324 Binder.restoreCallingIdentity(identity);
5325 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005326 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005327 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005328 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5329 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005330 @Override
5331 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005332 enforceModifyPermission();
5333
5334 final long identity = Binder.clearCallingIdentity();
5335 try {
5336 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005337 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005338 } finally {
5339 Binder.restoreCallingIdentity(identity);
5340 }
5341 }
5342
5343 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005344 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005345 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005346 */
5347 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5348 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005349
5350 final long identity = Binder.clearCallingIdentity();
5351 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005352 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005353 // may happen if the device does not support IMS.
5354 return null;
5355 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005356 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357 } finally {
5358 Binder.restoreCallingIdentity(identity);
5359 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005360 }
5361
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005362 /**
5363 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005364 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005365 */
5366 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5367 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005368
5369 final long identity = Binder.clearCallingIdentity();
5370 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005371 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005372 // may happen if the device does not support IMS.
5373 return null;
5374 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005375 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005376 } finally {
5377 Binder.restoreCallingIdentity(identity);
5378 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005379 }
5380
Brad Ebinger884c07b2018-02-15 16:17:40 -08005381 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005382 * Sets the ImsService Package Name that Telephony will bind to.
5383 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005384 * @param slotIndex the slot ID that the ImsService should bind for.
5385 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005386 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005387 * @param featureTypes An integer array of feature types associated with a packageName.
5388 * @param packageName The name of the package that the current configuration will be replaced
5389 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005390 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005391 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005392 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5393 int[] featureTypes, String packageName) {
5394 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5395 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5397 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005398 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400 final long identity = Binder.clearCallingIdentity();
5401 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005402 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005403 // may happen if the device does not support IMS.
5404 return false;
5405 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005406 Map<Integer, String> featureConfig = new HashMap<>();
5407 for (int featureType : featureTypes) {
5408 featureConfig.put(featureType, packageName);
5409 }
5410 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5411 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005412 } finally {
5413 Binder.restoreCallingIdentity(identity);
5414 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005415 }
5416
5417 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005418 * Clears any carrier ImsService overrides for the slot index specified that were previously
5419 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5420 *
5421 * This should only be used for testing.
5422 *
5423 * @param slotIndex the slot ID that the ImsService should bind for.
5424 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5425 */
5426 @Override
5427 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5428 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5429 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5430 "clearCarrierImsServiceOverride");
5431 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5432 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5433 "clearCarrierImsServiceOverride");
5434
5435 final long identity = Binder.clearCallingIdentity();
5436 try {
5437 if (mImsResolver == null) {
5438 // may happen if the device does not support IMS.
5439 return false;
5440 }
5441 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5442 } finally {
5443 Binder.restoreCallingIdentity(identity);
5444 }
5445 }
5446
5447 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005448 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005449 *
5450 * @param slotId The slot that the ImsService is associated with.
5451 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5452 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005453 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005454 * @return the package name of the ImsService configuration.
5455 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005456 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5457 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005458 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005459 TelephonyPermissions
5460 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5461 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5462 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005463
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005464 final long identity = Binder.clearCallingIdentity();
5465 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005466 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005467 // may happen if the device does not support IMS.
5468 return "";
5469 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005470 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005471 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5472 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005473 } finally {
5474 Binder.restoreCallingIdentity(identity);
5475 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005476 }
5477
Brad Ebinger77b832e2019-10-17 17:03:22 -07005478 /**
5479 * Get the MmTelFeature state associated with the requested subscription id.
5480 * @param subId The subscription that the MmTelFeature is associated with.
5481 * @param callback A callback with an integer containing the
5482 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5483 */
5484 @Override
5485 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5486 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5487 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5488 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5489 "IMS not available on device.");
5490 }
5491 final long token = Binder.clearCallingIdentity();
5492 try {
5493 int slotId = getSlotIndex(subId);
5494 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5495 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5496 + subId + "'");
5497 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5498 }
5499 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5500 try {
5501 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5502 } catch (RemoteException e) {
5503 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5504 + "Ignore");
5505 }
5506 });
5507 } finally {
5508 Binder.restoreCallingIdentity(token);
5509 }
5510 }
5511
Wink Saville36469e72014-06-11 15:17:00 -07005512 public void setImsRegistrationState(boolean registered) {
5513 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005514
5515 final long identity = Binder.clearCallingIdentity();
5516 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005517 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005518 } finally {
5519 Binder.restoreCallingIdentity(identity);
5520 }
Wink Saville36469e72014-06-11 15:17:00 -07005521 }
5522
5523 /**
Stuart Scott54788802015-03-30 13:18:01 -07005524 * Set the network selection mode to automatic.
5525 *
5526 */
5527 @Override
5528 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5530 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005531
5532 final long identity = Binder.clearCallingIdentity();
5533 try {
shilufc958392020-01-20 11:36:01 -08005534 if (!isActiveSubscription(subId)) {
5535 return;
5536 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005537 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5538 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5539 } finally {
5540 Binder.restoreCallingIdentity(identity);
5541 }
Stuart Scott54788802015-03-30 13:18:01 -07005542 }
5543
Jack Yud10cdd42020-09-28 20:28:01 -07005544 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005545 * Ask the radio to connect to the input network and change selection mode to manual.
5546 *
5547 * @param subId the id of the subscription.
5548 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5549 * the operator to attach to.
5550 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5551 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5552 * normal network selection next time.
5553 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005554 */
5555 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005556 public boolean setNetworkSelectionModeManual(
5557 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5559 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005560
5561 if (!isActiveSubscription(subId)) {
5562 return false;
5563 }
5564
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565 final long identity = Binder.clearCallingIdentity();
5566 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005567 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005568 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005569 if (DBG) {
5570 log("setNetworkSelectionModeManual: subId: " + subId
5571 + " operator: " + operatorInfo);
5572 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005573 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5574 } finally {
5575 Binder.restoreCallingIdentity(identity);
5576 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005577 }
shilu84f6e8b2019-12-19 13:58:01 -08005578 /**
5579 * Get the manual network selection
5580 *
5581 * @param subId the id of the subscription.
5582 *
5583 * @return the previously saved user selected PLMN
5584 */
5585 @Override
5586 public String getManualNetworkSelectionPlmn(int subId) {
5587 TelephonyPermissions
5588 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5589 mApp, subId, "getManualNetworkSelectionPlmn");
5590
5591 final long identity = Binder.clearCallingIdentity();
5592 try {
5593 if (!isActiveSubscription(subId)) {
5594 return "";
5595 }
5596
5597 final Phone phone = getPhone(subId);
5598 if (phone == null) {
5599 return "";
5600 }
5601 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5602 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5603 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5604 } finally {
5605 Binder.restoreCallingIdentity(identity);
5606 }
5607 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005608
5609 /**
5610 * Scans for available networks.
5611 */
5612 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005613 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5614 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5616 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005617 LocationAccessPolicy.LocationPermissionResult locationResult =
5618 LocationAccessPolicy.checkLocationPermission(mApp,
5619 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5620 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005621 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005622 .setCallingPid(Binder.getCallingPid())
5623 .setCallingUid(Binder.getCallingUid())
5624 .setMethod("getCellNetworkScanResults")
5625 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5626 .build());
5627 switch (locationResult) {
5628 case DENIED_HARD:
5629 throw new SecurityException("Not allowed to access scan results -- location");
5630 case DENIED_SOFT:
5631 return null;
5632 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633
Pengquan Menga1bb6272018-09-06 09:59:22 -07005634 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635 try {
5636 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005637 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639 } finally {
5640 Binder.restoreCallingIdentity(identity);
5641 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005642 }
5643
5644 /**
sqian80370722020-01-29 15:02:51 -08005645 * Get the call forwarding info, given the call forwarding reason.
5646 */
5647 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005648 public void getCallForwarding(int subId, int callForwardingReason,
5649 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005650 enforceReadPrivilegedPermission("getCallForwarding");
5651 long identity = Binder.clearCallingIdentity();
5652 try {
5653 if (DBG) {
5654 log("getCallForwarding: subId " + subId
5655 + " callForwardingReason" + callForwardingReason);
5656 }
Hall Liua1acea22020-09-18 19:04:59 -07005657
5658 Phone phone = getPhone(subId);
5659 if (phone == null) {
5660 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005661 callback.onError(
5662 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005663 } catch (RemoteException e) {
5664 // ignore
5665 }
5666 return;
5667 }
5668
5669 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5670 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5671 @Override
5672 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5673 try {
5674 callback.onCallForwardingInfoAvailable(info);
5675 } catch (RemoteException e) {
5676 // ignore
5677 }
5678 }
5679
5680 @Override
5681 public void onError(int error) {
5682 try {
5683 callback.onError(error);
5684 } catch (RemoteException e) {
5685 // ignore
5686 }
5687 }
5688 });
5689 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005690 } finally {
5691 Binder.restoreCallingIdentity(identity);
5692 }
5693 }
5694
5695 /**
5696 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5697 * reason, the number to forward, and the timeout before the forwarding is attempted.
5698 */
5699 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005700 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5701 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005702 enforceModifyPermission();
5703 long identity = Binder.clearCallingIdentity();
5704 try {
5705 if (DBG) {
5706 log("setCallForwarding: subId " + subId
5707 + " callForwardingInfo" + callForwardingInfo);
5708 }
Hall Liua1acea22020-09-18 19:04:59 -07005709
5710 Phone phone = getPhone(subId);
5711 if (phone == null) {
5712 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005713 callback.accept(
5714 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005715 } catch (RemoteException e) {
5716 // ignore
5717 }
5718 return;
5719 }
5720
5721 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5722 FunctionalUtils.ignoreRemoteException(callback::accept));
5723
5724 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005725 } finally {
5726 Binder.restoreCallingIdentity(identity);
5727 }
5728 }
5729
5730 /**
Hall Liua1acea22020-09-18 19:04:59 -07005731 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005732 */
5733 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005734 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005735 enforceReadPrivilegedPermission("getCallForwarding");
5736 long identity = Binder.clearCallingIdentity();
5737 try {
Hall Liua1acea22020-09-18 19:04:59 -07005738
5739 Phone phone = getPhone(subId);
5740 if (phone == null) {
5741 try {
5742 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5743 } catch (RemoteException e) {
5744 // ignore
5745 }
5746 return;
5747 }
5748
5749 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5750
sqian80370722020-01-29 15:02:51 -08005751 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005752 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005753 } finally {
5754 Binder.restoreCallingIdentity(identity);
5755 }
5756 }
5757
5758 /**
Hall Liua1acea22020-09-18 19:04:59 -07005759 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005760 */
5761 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005762 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005763 enforceModifyPermission();
5764 long identity = Binder.clearCallingIdentity();
5765 try {
Hall Liua1acea22020-09-18 19:04:59 -07005766 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5767
5768 Phone phone = getPhone(subId);
5769 if (phone == null) {
5770 try {
5771 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5772 } catch (RemoteException e) {
5773 // ignore
5774 }
5775 return;
5776 }
5777
5778 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5779 FunctionalUtils.ignoreRemoteException(callback::accept));
5780
5781 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005782 } finally {
5783 Binder.restoreCallingIdentity(identity);
5784 }
5785 }
5786
5787 /**
yinxub1bed742017-04-17 11:45:04 -07005788 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005789 *
yinxub1bed742017-04-17 11:45:04 -07005790 * @param subId id of the subscription
5791 * @param request contains the radio access networks with bands/channels to scan
5792 * @param messenger callback messenger for scan results or errors
5793 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005794 * @return the id of the requested scan which can be used to stop the scan.
5795 */
5796 @Override
5797 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005798 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5800 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005801 LocationAccessPolicy.LocationPermissionResult locationResult =
5802 LocationAccessPolicy.checkLocationPermission(mApp,
5803 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5804 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005805 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005806 .setCallingPid(Binder.getCallingPid())
5807 .setCallingUid(Binder.getCallingUid())
5808 .setMethod("requestNetworkScan")
5809 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5810 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005811 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005812 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5813 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005814 if (e != null) {
5815 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5816 throw e;
5817 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005818 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005819 return TelephonyScanManager.INVALID_SCAN_ID;
5820 }
5821 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005822 }
Hall Liu912dfd32019-04-25 14:02:26 -07005823 int callingUid = Binder.getCallingUid();
5824 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005825 final long identity = Binder.clearCallingIdentity();
5826 try {
5827 return mNetworkScanRequestTracker.startNetworkScan(
5828 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005829 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005830 } finally {
5831 Binder.restoreCallingIdentity(identity);
5832 }
yinxu504e1392017-04-12 16:03:22 -07005833 }
5834
Hall Liub2ac8ef2019-02-28 15:56:23 -08005835 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005836 NetworkScanRequest request, int subId, String callingPackage) {
5837 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005838 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5839 boolean hasNetworkScanPermission =
5840 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5841 == PERMISSION_GRANTED;
5842
5843 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5844 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5845 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005846 }
5847
5848 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5849 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005850 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5851 return new SecurityException("Specific channels must not be"
5852 + " scanned without location access.");
5853 }
5854 }
5855 }
5856
Hall Liub2ac8ef2019-02-28 15:56:23 -08005857 return null;
5858 }
5859
yinxu504e1392017-04-12 16:03:22 -07005860 /**
5861 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005862 *
5863 * @param subId id of the subscription
5864 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005865 */
5866 @Override
5867 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5869 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005870
Hall Liu912dfd32019-04-25 14:02:26 -07005871 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005872 final long identity = Binder.clearCallingIdentity();
5873 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005874 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005875 } finally {
5876 Binder.restoreCallingIdentity(identity);
5877 }
yinxu504e1392017-04-12 16:03:22 -07005878 }
5879
5880 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005881 * Get the calculated preferred network type.
5882 * Used for debugging incorrect network type.
5883 *
5884 * @return the preferred network type, defined in RILConstants.java.
5885 */
5886 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005887 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005888 final Phone defaultPhone = getDefaultPhone();
5889 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005890 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005891 return RILConstants.PREFERRED_NETWORK_MODE;
5892 }
5893
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894 final long identity = Binder.clearCallingIdentity();
5895 try {
5896 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005897 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005898 } finally {
5899 Binder.restoreCallingIdentity(identity);
5900 }
Junda Liu84d15a22014-07-02 11:21:04 -07005901 }
5902
5903 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005904 * Get the preferred network type.
5905 * Used for device configuration by some CDMA operators.
5906 *
5907 * @return the preferred network type, defined in RILConstants.java.
5908 */
5909 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005910 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005911 TelephonyPermissions
5912 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5913 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005914
5915 final long identity = Binder.clearCallingIdentity();
5916 try {
5917 if (DBG) log("getPreferredNetworkType");
5918 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5919 int networkType = (result != null ? result[0] : -1);
5920 if (DBG) log("getPreferredNetworkType: " + networkType);
5921 return networkType;
5922 } finally {
5923 Binder.restoreCallingIdentity(identity);
5924 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005925 }
5926
5927 /**
5928 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005929 *
5930 * @param networkType the preferred network type, defined in RILConstants.java.
5931 * @return true on success; false on any failure.
5932 */
5933 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005934 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5936 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005937
5938 final long identity = Binder.clearCallingIdentity();
5939 try {
calvinpan089c2a62020-03-12 14:17:55 +08005940 Boolean success = (Boolean) sendRequest(
5941 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005942
5943 if (success) {
5944 Settings.Global.putInt(mApp.getContentResolver(),
5945 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5946 }
calvinpan089c2a62020-03-12 14:17:55 +08005947 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5948 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005949 } finally {
5950 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005951 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005952 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005953
5954 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005955 * Get the allowed network types that store in the telephony provider.
5956 *
5957 * @param subId the id of the subscription.
5958 * @return allowedNetworkTypes the allowed network types.
5959 */
5960 @Override
5961 public long getAllowedNetworkTypes(int subId) {
5962 TelephonyPermissions
5963 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5964 mApp, subId, "getAllowedNetworkTypes");
5965
5966 final long identity = Binder.clearCallingIdentity();
5967 try {
5968 return SubscriptionManager.getLongSubscriptionProperty(
5969 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5970 } finally {
5971 Binder.restoreCallingIdentity(identity);
5972 }
5973 }
5974
5975 /**
5976 * Set the allowed network types.
5977 *
5978 * @param subId the id of the subscription.
5979 * @param allowedNetworkTypes the allowed network types.
5980 * @return true on success; false on any failure.
5981 */
5982 @Override
5983 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5984 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5985 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005986
calvinpan089c2a62020-03-12 14:17:55 +08005987 SubscriptionManager.setSubscriptionProperty(subId,
5988 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5989 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005990
calvinpan089c2a62020-03-12 14:17:55 +08005991 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5992 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5993 RILConstants.PREFERRED_NETWORK_MODE);
5994 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005995 }
5996
5997 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005998 * Get the allowed network types for certain reason.
5999 *
6000 * @param subId the id of the subscription.
6001 * @param reason the reason the allowed network type change is taking place
6002 * @return the allowed network types.
6003 */
6004 @Override
6005 public long getAllowedNetworkTypesForReason(int subId,
6006 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6007 TelephonyPermissions
6008 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6009 mApp, subId, "getAllowedNetworkTypesForReason");
6010 final long identity = Binder.clearCallingIdentity();
6011 try {
6012 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6013 } finally {
6014 Binder.restoreCallingIdentity(identity);
6015 }
6016 }
6017
6018 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006019 * Enable/Disable E-UTRA-NR Dual Connectivity
6020 * @param subId subscription id of the sim card
6021 * @param nrDualConnectivityState expected NR dual connectivity state
6022 * This can be passed following states
6023 * <ol>
6024 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6025 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6026 * <li>Disable NR dual connectivity and force secondary cell to be released
6027 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6028 * </ol>
6029 * @return operation result.
6030 */
6031 @Override
6032 public int setNrDualConnectivityState(int subId,
6033 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6034 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6035 mApp, subId, "enableNRDualConnectivity");
6036 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6037 final long identity = Binder.clearCallingIdentity();
6038 try {
6039 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6040 nrDualConnectivityState, subId,
6041 workSource);
6042 if (DBG) log("enableNRDualConnectivity result: " + result);
6043 return result;
6044 } finally {
6045 Binder.restoreCallingIdentity(identity);
6046 }
6047 }
6048
6049 /**
6050 * Is E-UTRA-NR Dual Connectivity enabled
6051 * @return true if dual connectivity is enabled else false
6052 */
6053 @Override
6054 public boolean isNrDualConnectivityEnabled(int subId) {
6055 TelephonyPermissions
6056 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6057 mApp, subId, "isNRDualConnectivityEnabled");
6058 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6059 final long identity = Binder.clearCallingIdentity();
6060 try {
6061 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6062 null, subId, workSource);
6063 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6064 return isEnabled;
6065 } finally {
6066 Binder.restoreCallingIdentity(identity);
6067 }
6068 }
6069
6070 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006071 * get carrier bandwidth per primary and secondary carrier
6072 * @param subId subscription id of the sim card
6073 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6074 */
6075 @Override
6076 public CarrierBandwidth getCarrierBandwidth(int subId) {
6077 TelephonyPermissions
6078 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6079 mApp, subId, "isNRDualConnectivityEnabled");
6080 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6081 final long identity = Binder.clearCallingIdentity();
6082 try {
6083 CarrierBandwidth carrierBandwidth =
6084 getPhoneFromSubId(subId).getCarrierBandwidth();
6085 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6086 return carrierBandwidth;
6087 } finally {
6088 Binder.restoreCallingIdentity(identity);
6089 }
6090 }
6091
6092 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006093 * Get the effective allowed network types on the device.
6094 * This API will return an intersection of allowed network types for all reasons,
6095 * including the configuration done through setAllowedNetworkTypes
6096 *
6097 * @param subId the id of the subscription.
6098 * @return the allowed network types
6099 */
6100 @Override
6101 public long getEffectiveAllowedNetworkTypes(int subId) {
6102 TelephonyPermissions
6103 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6104 mApp, subId, "getEffectiveAllowedNetworkTypes");
6105 final long identity = Binder.clearCallingIdentity();
6106 try {
6107 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6108 } finally {
6109 Binder.restoreCallingIdentity(identity);
6110 }
6111 }
6112
6113 /**
6114 * Set the allowed network types of the device and
6115 * provide the reason triggering the allowed network change.
6116 *
6117 * @param subId the id of the subscription.
6118 * @param reason the reason the allowed network type change is taking place
6119 * @param allowedNetworkTypes the allowed network types.
6120 * @return true on success; false on any failure.
6121 */
6122 @Override
6123 public boolean setAllowedNetworkTypesForReason(int subId,
6124 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6125 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6126 mApp, subId, "setAllowedNetworkTypesForReason");
6127 final long identity = Binder.clearCallingIdentity();
6128 try {
6129 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6130 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6131 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6132 RILConstants.PREFERRED_NETWORK_MODE);
6133 return setPreferredNetworkType(subId, preferredNetworkMode);
6134 } finally {
6135 Binder.restoreCallingIdentity(identity);
6136 }
6137 }
6138
6139 /**
Miaoa84611c2019-03-15 09:21:10 +08006140 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006141 *
Miaoa84611c2019-03-15 09:21:10 +08006142 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006143 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006144 * @hide
6145 */
6146 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006147 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006148 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006149 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006150 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006151 try {
Miaoa84611c2019-03-15 09:21:10 +08006152 if (phone != null) {
6153 return phone.hasMatchedTetherApnSetting();
6154 } else {
6155 return false;
6156 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006157 } finally {
6158 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006159 }
Junda Liu475951f2014-11-07 16:45:03 -08006160 }
6161
6162 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006163 * Enable or disable always reporting signal strength changes from radio.
6164 *
6165 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6166 */
6167 @Override
6168 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6169 enforceModifyPermission();
6170 enforceSystemCaller();
6171
6172 final long identity = Binder.clearCallingIdentity();
6173 final Phone phone = getPhone(subId);
6174 try {
6175 if (phone != null) {
6176 if (DBG) {
6177 log("setAlwaysReportSignalStrength: subId=" + subId
6178 + " isEnable=" + isEnable);
6179 }
6180 phone.setAlwaysReportSignalStrength(isEnable);
6181 } else {
6182 loge("setAlwaysReportSignalStrength: no phone found for subId="
6183 + subId);
6184 }
6185 } finally {
6186 Binder.restoreCallingIdentity(identity);
6187 }
6188 }
6189
6190 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006191 * Get the user enabled state of Mobile Data.
6192 *
6193 * TODO: remove and use isUserDataEnabled.
6194 * This can't be removed now because some vendor codes
6195 * calls through ITelephony directly while they should
6196 * use TelephonyManager.
6197 *
6198 * @return true on enabled
6199 */
6200 @Override
6201 public boolean getDataEnabled(int subId) {
6202 return isUserDataEnabled(subId);
6203 }
6204
6205 /**
6206 * Get whether mobile data is enabled per user setting.
6207 *
6208 * There are other factors deciding whether mobile data is actually enabled, but they are
6209 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006210 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006211 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006212 *
6213 * @return {@code true} if data is enabled else {@code false}
6214 */
6215 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006216 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006217 try {
6218 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6219 null);
6220 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6222 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006223 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224
6225 final long identity = Binder.clearCallingIdentity();
6226 try {
6227 int phoneId = mSubscriptionController.getPhoneId(subId);
6228 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6229 Phone phone = PhoneFactory.getPhone(phoneId);
6230 if (phone != null) {
6231 boolean retVal = phone.isUserDataEnabled();
6232 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6233 return retVal;
6234 } else {
6235 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6236 return false;
6237 }
6238 } finally {
6239 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006240 }
6241 }
6242
6243 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006244 * Checks if the device is capable of mobile data by considering whether whether the
6245 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6246 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006247 *
Shuo Qian985d1232020-01-08 14:30:06 -08006248 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006249 */
6250 @Override
6251 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006252 try {
6253 try {
6254 mApp.enforceCallingOrSelfPermission(
6255 android.Manifest.permission.ACCESS_NETWORK_STATE,
6256 null);
6257 } catch (Exception e) {
6258 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6259 "isDataEnabled");
6260 }
6261 } catch (Exception e) {
6262 enforceReadPrivilegedPermission("isDataEnabled");
6263 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006264
6265 final long identity = Binder.clearCallingIdentity();
6266 try {
6267 int phoneId = mSubscriptionController.getPhoneId(subId);
6268 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6269 Phone phone = PhoneFactory.getPhone(phoneId);
6270 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006271 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006272 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6273 return retVal;
6274 } else {
6275 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6276 return false;
6277 }
6278 } finally {
6279 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006280 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006281 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006282
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006283 /**
6284 * Check if data is enabled for a specific reason
6285 * @param subId Subscription index
6286 * @param reason the reason the data enable change is taking place
6287 * @return {@code true} if the overall data is enabled; {@code false} if not.
6288 */
6289 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006290 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006291 @TelephonyManager.DataEnabledReason int reason) {
6292 try {
6293 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6294 null);
6295 } catch (Exception e) {
6296 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006297 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006298 }
6299
6300
6301 final long identity = Binder.clearCallingIdentity();
6302 try {
6303 int phoneId = mSubscriptionController.getPhoneId(subId);
6304 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006305 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006306 + " reason=" + reason);
6307 }
6308 Phone phone = PhoneFactory.getPhone(phoneId);
6309 if (phone != null) {
6310 boolean retVal;
6311 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6312 retVal = phone.isUserDataEnabled();
6313 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006314 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006315 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006316 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006317 return retVal;
6318 } else {
6319 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006320 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006321 + subId + " retVal=false");
6322 }
6323 return false;
6324 }
6325 } finally {
6326 Binder.restoreCallingIdentity(identity);
6327 }
6328 }
6329
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006330 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006331 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006332 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6333 // Skip the check if it's one of these special uids
6334 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6335 }
6336
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006337 //load access rules from carrier configs, and check those as well: b/139133814
6338 SubscriptionController subController = SubscriptionController.getInstance();
6339 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6340 || subController == null) return privilegeFromSim;
6341
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006342 PackageManager pkgMgr = phone.getContext().getPackageManager();
6343 String[] packages = pkgMgr.getPackagesForUid(uid);
6344
6345 final long identity = Binder.clearCallingIdentity();
6346 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006347 int subId = phone.getSubId();
6348 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6349 // A test override is in place for the privileges for this subId, so don't try to
6350 // read the subscription privileges.
6351 return privilegeFromSim;
6352 }
6353 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006354 SubscriptionManager subManager = (SubscriptionManager)
6355 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6356 for (String pkg : packages) {
6357 if (subManager.canManageSubscription(subInfo, pkg)) {
6358 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6359 }
6360 }
6361 return privilegeFromSim;
6362 } finally {
6363 Binder.restoreCallingIdentity(identity);
6364 }
6365 }
6366
6367 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6368 String pkgName) {
6369 //load access rules from carrier configs, and check those as well: b/139133814
6370 SubscriptionController subController = SubscriptionController.getInstance();
6371 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6372 || subController == null) return privilegeFromSim;
6373
6374 final long identity = Binder.clearCallingIdentity();
6375 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006376 int subId = phone.getSubId();
6377 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6378 // A test override is in place for the privileges for this subId, so don't try to
6379 // read the subscription privileges.
6380 return privilegeFromSim;
6381 }
6382 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006383 SubscriptionManager subManager = (SubscriptionManager)
6384 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6385 return subManager.canManageSubscription(subInfo, pkgName)
6386 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6387 } finally {
6388 Binder.restoreCallingIdentity(identity);
6389 }
6390 }
6391
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006392 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006393 public int getCarrierPrivilegeStatus(int subId) {
6394 final Phone phone = getPhone(subId);
6395 if (phone == null) {
6396 loge("getCarrierPrivilegeStatus: Invalid subId");
6397 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6398 }
6399 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006400 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006401 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006402 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6403 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006404
6405 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6406 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006407 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006408 }
Junda Liu29340342014-07-10 15:23:27 -07006409
6410 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006411 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006412 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006413 final Phone phone = getPhone(subId);
6414 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006415 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006416 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6417 }
6418 UiccProfile profile =
6419 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6420 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006421 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006422 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6423 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006424 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006425 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006426 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006427 }
6428
6429 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006430 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6431 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006432 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006433 }
6434
6435 int phoneId = SubscriptionManager.getPhoneId(subId);
6436 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006437 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006438 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006439 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6440 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006441 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6442 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6443 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006444 }
6445
6446 @Override
6447 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006448 if (TextUtils.isEmpty(pkgName))
6449 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006450 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6451 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6452 UiccCard card = UiccController.getInstance().getUiccCard(i);
6453 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006454 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006455 continue;
6456 }
6457
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006458 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6459 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6460 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006461 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6462 break;
6463 }
6464 }
6465
6466 return result;
Junda Liu29340342014-07-10 15:23:27 -07006467 }
Derek Tan89e89d42014-07-08 17:00:10 -07006468
6469 @Override
Junda Liue64de782015-04-16 17:19:16 -07006470 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6471 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6472 loge("phoneId " + phoneId + " is not valid.");
6473 return null;
6474 }
6475 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006476 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006477 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006478 return null ;
6479 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006480 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006481 }
6482
Amith Yamasani6e118872016-02-19 12:53:51 -08006483 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006484 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006485 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006486 List<String> privilegedPackages = new ArrayList<>();
6487 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006488 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6489 // has UICC in that slot.
6490 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006491 if (card.hasCarrierPrivilegeRules()) {
6492 if (packages == null) {
6493 // Only check packages in user 0 for now
6494 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006495 PackageManager.MATCH_DISABLED_COMPONENTS
6496 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006497 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006498 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006499 }
6500 for (int p = packages.size() - 1; p >= 0; p--) {
6501 PackageInfo pkgInfo = packages.get(p);
6502 if (pkgInfo != null && pkgInfo.packageName != null
6503 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006504 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006505 privilegedPackages.add(pkgInfo.packageName);
6506 }
6507 }
6508 }
6509 }
6510 return privilegedPackages;
6511 }
6512
chen xuf7e9fe82019-05-09 19:31:02 -07006513 @Override
6514 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006515 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6516
6517 final long identity = Binder.clearCallingIdentity();
6518
chen xuf7e9fe82019-05-09 19:31:02 -07006519 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006520 try {
6521 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6522 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6523 }
6524 } finally {
6525 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006526 }
6527 return privilegedPackages;
6528 }
6529
Wink Savilleb564aae2014-10-23 10:18:09 -07006530 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006531 final Phone phone = getPhone(subId);
6532 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006533 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006534 return null;
6535 }
6536 String iccId = card.getIccId();
6537 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006538 return null;
6539 }
6540 return iccId;
6541 }
6542
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006543 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006544 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6545 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006546 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006547 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006548
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006549 final long identity = Binder.clearCallingIdentity();
6550 try {
6551 final String iccId = getIccId(subId);
6552 final Phone phone = getPhone(subId);
6553 if (phone == null) {
6554 return false;
6555 }
6556 final String subscriberId = phone.getSubscriberId();
6557
6558 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006559 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006560 + subscriberId + " to " + number);
6561 }
6562
6563 if (TextUtils.isEmpty(iccId)) {
6564 return false;
6565 }
6566
6567 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6568
6569 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6570 if (alphaTag == null) {
6571 editor.remove(alphaTagPrefKey);
6572 } else {
6573 editor.putString(alphaTagPrefKey, alphaTag);
6574 }
6575
6576 // Record both the line number and IMSI for this ICCID, since we need to
6577 // track all merged IMSIs based on line number
6578 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6579 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6580 if (number == null) {
6581 editor.remove(numberPrefKey);
6582 editor.remove(subscriberPrefKey);
6583 } else {
6584 editor.putString(numberPrefKey, number);
6585 editor.putString(subscriberPrefKey, subscriberId);
6586 }
6587
6588 editor.commit();
6589 return true;
6590 } finally {
6591 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006592 }
Derek Tan7226c842014-07-02 17:42:23 -07006593 }
6594
6595 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006596 public String getLine1NumberForDisplay(int subId, String callingPackage,
6597 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006598 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006599 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006600 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006601 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006602 return null;
6603 }
Derek Tan97ebb422014-09-05 16:55:38 -07006604
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006605 final long identity = Binder.clearCallingIdentity();
6606 try {
6607 String iccId = getIccId(subId);
6608 if (iccId != null) {
6609 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6610 if (DBG_MERGE) {
6611 log("getLine1NumberForDisplay returning "
6612 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6613 }
6614 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006615 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6617 return null;
6618 } finally {
6619 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006620 }
Derek Tan7226c842014-07-02 17:42:23 -07006621 }
6622
6623 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006624 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6625 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006626 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006627 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006628 return null;
6629 }
Derek Tan97ebb422014-09-05 16:55:38 -07006630
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006631 final long identity = Binder.clearCallingIdentity();
6632 try {
6633 String iccId = getIccId(subId);
6634 if (iccId != null) {
6635 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6636 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6637 }
6638 return null;
6639 } finally {
6640 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006641 }
Derek Tan7226c842014-07-02 17:42:23 -07006642 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006643
6644 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006645 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6646 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006647 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6648 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006649 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006650 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006651 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006652 return null;
6653 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006654
Jordan Liub49b04b2019-05-06 14:45:15 -07006655 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6656 // the process, where TelephonyManager was instantiated.
6657 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006658 final long identity = Binder.clearCallingIdentity();
6659 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006660 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006661 final TelephonyManager tele = TelephonyManager.from(context);
6662 final SubscriptionManager sub = SubscriptionManager.from(context);
6663
6664 // Figure out what subscribers are currently active
6665 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006666
Jordan Liub49b04b2019-05-06 14:45:15 -07006667 // Only consider subs which match the current subId
6668 // This logic can be simplified. See b/131189269 for progress.
6669 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006670 activeSubscriberIds.add(tele.getSubscriberId(subId));
6671 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006672
6673 // First pass, find a number override for an active subscriber
6674 String mergeNumber = null;
6675 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6676 for (String key : prefs.keySet()) {
6677 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6678 final String subscriberId = (String) prefs.get(key);
6679 if (activeSubscriberIds.contains(subscriberId)) {
6680 final String iccId = key.substring(
6681 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6682 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6683 mergeNumber = (String) prefs.get(numberKey);
6684 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006685 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006686 + " for active subscriber " + subscriberId);
6687 }
6688 if (!TextUtils.isEmpty(mergeNumber)) {
6689 break;
6690 }
6691 }
6692 }
6693 }
6694
6695 // Shortcut when no active merged subscribers
6696 if (TextUtils.isEmpty(mergeNumber)) {
6697 return null;
6698 }
6699
6700 // Second pass, find all subscribers under that line override
6701 final ArraySet<String> result = new ArraySet<>();
6702 for (String key : prefs.keySet()) {
6703 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6704 final String number = (String) prefs.get(key);
6705 if (mergeNumber.equals(number)) {
6706 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6707 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6708 final String subscriberId = (String) prefs.get(subscriberKey);
6709 if (!TextUtils.isEmpty(subscriberId)) {
6710 result.add(subscriberId);
6711 }
6712 }
6713 }
6714 }
6715
6716 final String[] resultArray = result.toArray(new String[result.size()]);
6717 Arrays.sort(resultArray);
6718 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006719 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006720 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6721 }
6722 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006723 } finally {
6724 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006725 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006726 }
6727
6728 @Override
zoey chen38003472019-12-13 17:16:31 +08006729 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6730 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006731
6732 final long identity = Binder.clearCallingIdentity();
6733 try {
6734 final TelephonyManager telephonyManager = mApp.getSystemService(
6735 TelephonyManager.class);
6736 String subscriberId = telephonyManager.getSubscriberId(subId);
6737 if (subscriberId == null) {
6738 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006739 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006740 + subId);
6741 }
6742 return null;
6743 }
6744
6745 final SubscriptionInfo info = SubscriptionController.getInstance()
6746 .getSubscriptionInfo(subId);
6747 final ParcelUuid groupUuid = info.getGroupUuid();
6748 // If it doesn't belong to any group, return just subscriberId of itself.
6749 if (groupUuid == null) {
6750 return new String[]{subscriberId};
6751 }
6752
6753 // Get all subscriberIds from the group.
6754 final List<String> mergedSubscriberIds = new ArrayList<>();
6755 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006756 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006757 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006758 for (SubscriptionInfo subInfo : groupInfos) {
6759 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6760 if (subscriberId != null) {
6761 mergedSubscriberIds.add(subscriberId);
6762 }
6763 }
6764
6765 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6766 } finally {
6767 Binder.restoreCallingIdentity(identity);
6768
6769 }
6770 }
6771
6772 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006773 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006774 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006775 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006776
6777 final long identity = Binder.clearCallingIdentity();
6778 try {
6779 final Phone phone = getPhone(subId);
6780 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6781 } finally {
6782 Binder.restoreCallingIdentity(identity);
6783 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006784 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006785
6786 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006787 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006788 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6789 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006790 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6791 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006792
6793 final long identity = Binder.clearCallingIdentity();
6794 try {
6795 final Phone phone = getPhone(subId);
6796 if (phone == null) {
6797 return false;
6798 }
6799 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6800 cdmaNonRoamingList);
6801 } finally {
6802 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006803 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006804 }
6805
6806 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006807 @Deprecated
6808 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6809 enforceModifyPermission();
6810
6811 int returnValue = 0;
6812 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006813 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006814 if(result.exception == null) {
6815 if (result.result != null) {
6816 byte[] responseData = (byte[])(result.result);
6817 if(responseData.length > oemResp.length) {
6818 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6819 responseData.length + "bytes. Buffer Size is " +
6820 oemResp.length + "bytes.");
6821 }
6822 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6823 returnValue = responseData.length;
6824 }
6825 } else {
6826 CommandException ex = (CommandException) result.exception;
6827 returnValue = ex.getCommandError().ordinal();
6828 if(returnValue > 0) returnValue *= -1;
6829 }
6830 } catch (RuntimeException e) {
6831 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6832 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6833 if(returnValue > 0) returnValue *= -1;
6834 }
6835
6836 return returnValue;
6837 }
6838
6839 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006840 public void setRadioCapability(RadioAccessFamily[] rafs) {
6841 try {
6842 ProxyController.getInstance().setRadioCapability(rafs);
6843 } catch (RuntimeException e) {
6844 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6845 }
6846 }
6847
6848 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006849 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006850 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006851 try {
6852 TelephonyPermissions
6853 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6854 mApp, phone.getSubId(), "getRadioAccessFamily");
6855 } catch (SecurityException e) {
6856 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6857 throw e;
6858 }
chen xub97461a2018-10-26 14:17:57 -07006859 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006860 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006861 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006862 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006863 final long identity = Binder.clearCallingIdentity();
6864 try {
chen xub97461a2018-10-26 14:17:57 -07006865 TelephonyPermissions
6866 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6867 mApp, phone.getSubId(), "getRadioAccessFamily");
6868 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006869 } finally {
6870 Binder.restoreCallingIdentity(identity);
6871 }
chen xub97461a2018-10-26 14:17:57 -07006872 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006873 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006874
6875 @Override
6876 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006877 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006878 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006879
6880 final long identity = Binder.clearCallingIdentity();
6881 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006882 ImsManager.getInstance(defaultPhone.getContext(),
6883 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006884 } finally {
6885 Binder.restoreCallingIdentity(identity);
6886 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006887 }
6888
6889 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006890 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006891 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6893 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006894 return false;
6895 }
Svet Ganovb320e182015-04-16 12:30:10 -07006896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006897 final long identity = Binder.clearCallingIdentity();
6898 try {
6899 // Check the user preference and the system-level IMS setting. Even if the user has
6900 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6901 // In the long run, we may instead need to check if there exists a connection service
6902 // which can support video calling.
6903 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006904 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006905 return imsManager.isVtEnabledByPlatform()
6906 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6907 && imsManager.isVtEnabledByUser();
6908 } finally {
6909 Binder.restoreCallingIdentity(identity);
6910 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006911 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006912
Andrew Leea1239f22015-03-02 17:44:07 -08006913 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006914 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6915 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006916 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006917 mApp, subId, callingPackage, callingFeatureId,
6918 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006919 return false;
6920 }
6921
6922 final long identity = Binder.clearCallingIdentity();
6923 try {
6924 CarrierConfigManager configManager =
6925 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006926 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006927 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6928 } finally {
6929 Binder.restoreCallingIdentity(identity);
6930 }
Andrew Leea1239f22015-03-02 17:44:07 -08006931 }
6932
6933 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006934 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006935 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006936 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006937 return false;
6938 }
6939
6940 final long identity = Binder.clearCallingIdentity();
6941 try {
6942 CarrierConfigManager configManager =
6943 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006944 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006945 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6946 } finally {
6947 Binder.restoreCallingIdentity(identity);
6948 }
Andrew Leea1239f22015-03-02 17:44:07 -08006949 }
6950
Andrew Lee9431b832015-03-09 18:46:45 -07006951 @Override
6952 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006953 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006954 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006955 }
6956
6957 @Override
6958 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006959 final long identity = Binder.clearCallingIdentity();
6960 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006961 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006962 } finally {
6963 Binder.restoreCallingIdentity(identity);
6964 }
Andrew Lee9431b832015-03-09 18:46:45 -07006965 }
6966
Hall Liuf6668912018-10-31 17:05:23 -07006967 /**
6968 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6969 * support for the feature and device firmware support.
6970 *
6971 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6972 */
6973 @Override
6974 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006975 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006976 final Phone phone = getPhone(subscriptionId);
6977 if (phone == null) {
6978 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6979 return false;
6980 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006981 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006982 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006983 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6984 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006985 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006986 return isCarrierSupported && isDeviceSupported;
6987 } finally {
6988 Binder.restoreCallingIdentity(identity);
6989 }
Hall Liu98187582018-01-22 19:15:32 -08006990 }
6991
Hall Liuf6668912018-10-31 17:05:23 -07006992 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006993 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6994 * RTT setting, will return true if the device and carrier both support RTT.
6995 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006996 */
6997 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006998 final long identity = Binder.clearCallingIdentity();
6999 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007000 boolean isRttSupported = isRttSupported(subscriptionId);
7001 boolean isUserRttSettingOn = Settings.Secure.getInt(
7002 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7003 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7004 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7005 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007006 } finally {
7007 Binder.restoreCallingIdentity(identity);
7008 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007009 }
7010
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007011 @Deprecated
7012 @Override
7013 public String getDeviceId(String callingPackage) {
7014 return getDeviceIdWithFeature(callingPackage, null);
7015 }
7016
Sanket Padawe7310cc72015-01-14 09:53:20 -08007017 /**
7018 * Returns the unique device ID of phone, for example, the IMEI for
7019 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7020 *
7021 * <p>Requires Permission:
7022 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7023 */
7024 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007025 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007026 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007027 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007028 return null;
7029 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007030 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007031 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007032 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007033 return null;
7034 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035
7036 final long identity = Binder.clearCallingIdentity();
7037 try {
7038 return phone.getDeviceId();
7039 } finally {
7040 Binder.restoreCallingIdentity(identity);
7041 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007042 }
7043
Ping Sunc67b7c22016-03-02 19:16:45 +08007044 /**
7045 * {@hide}
7046 * Returns the IMS Registration Status on a particular subid
7047 *
7048 * @param subId
7049 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007050 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007051 Phone phone = getPhone(subId);
7052 if (phone != null) {
7053 return phone.isImsRegistered();
7054 } else {
7055 return false;
7056 }
7057 }
7058
Santos Cordon7a1885b2015-02-03 11:15:19 -08007059 @Override
7060 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007061 final long identity = Binder.clearCallingIdentity();
7062 try {
7063 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7064 } finally {
7065 Binder.restoreCallingIdentity(identity);
7066 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007067 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007068
Tyler Gunnf70ed162019-04-03 15:28:53 -07007069 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007070 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007071 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007072 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007073 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007074 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7075 }
7076 final long identity = Binder.clearCallingIdentity();
7077 try {
7078 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7079 } finally {
7080 Binder.restoreCallingIdentity(identity);
7081 }
7082 }
7083
7084 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007085 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007086 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7087 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007088 final long identity = Binder.clearCallingIdentity();
7089 try {
7090 Phone phone = getPhone(subscriptionId);
7091 if (phone == null) {
7092 return null;
7093 }
7094 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7095 } finally {
7096 Binder.restoreCallingIdentity(identity);
7097 }
7098 }
7099
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007100 /**
7101 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007102 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007103 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007104 final long identity = Binder.clearCallingIdentity();
7105 try {
7106 Phone phone = getPhone(subId);
7107 if (phone != null) {
7108 return phone.isWifiCallingEnabled();
7109 } else {
7110 return false;
7111 }
7112 } finally {
7113 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007114 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007115 }
7116
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007117 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007118 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007119 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007120 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007121 final long identity = Binder.clearCallingIdentity();
7122 try {
7123 Phone phone = getPhone(subId);
7124 if (phone != null) {
7125 return phone.isVideoEnabled();
7126 } else {
7127 return false;
7128 }
7129 } finally {
7130 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007131 }
7132 }
7133
7134 /**
7135 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7136 * defined in {@link ImsRegistrationImplBase}.
7137 */
7138 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007139 final long identity = Binder.clearCallingIdentity();
7140 try {
7141 Phone phone = getPhone(subId);
7142 if (phone != null) {
7143 return phone.getImsRegistrationTech();
7144 } else {
7145 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7146 }
7147 } finally {
7148 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007149 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007150 }
7151
Stuart Scott8eef64f2015-04-08 15:13:54 -07007152 @Override
7153 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007154 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007155 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7156 return;
7157 }
7158
Svet Ganovcc087f82015-05-12 20:35:54 -07007159 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007160
Svet Ganovcc087f82015-05-12 20:35:54 -07007161 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007162 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7163 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007164 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007165 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007166 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007167 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007168 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7169 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007170 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007171 // There has been issues when Sms raw table somehow stores orphan
7172 // fragments. They lead to garbled message when new fragments come
7173 // in and combined with those stale ones. In case this happens again,
7174 // user can reset all network settings which will clean up this table.
7175 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007176 // Clean up IMS settings as well here.
7177 int slotId = getSlotIndex(subId);
7178 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7179 ImsManager.getInstance(mApp, slotId).factoryReset();
7180 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007181
7182 // Erase modem config if erase modem on network setting is enabled.
7183 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7184 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7185 if (configValue != null && Boolean.parseBoolean(configValue)) {
7186 sendEraseModemConfig(getDefaultPhone());
7187 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007188 } finally {
7189 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007190 }
7191 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007192
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007193 private void cleanUpSmsRawTable(Context context) {
7194 ContentResolver resolver = context.getContentResolver();
7195 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7196 resolver.delete(uri, null, null);
7197 }
7198
Narayan Kamath1c496c22015-04-16 14:40:19 +01007199 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007200 public String getSimLocaleForSubscriber(int subId) {
7201 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7202 final Phone phone = getPhone(subId);
7203 if (phone == null) {
7204 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007205 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007206 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007207 final long identity = Binder.clearCallingIdentity();
7208 try {
chen xu5d3637b2019-01-21 23:31:38 -08007209 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007210 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007211 if (info == null) {
7212 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7213 return null;
7214 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007215 // Try and fetch the locale from the carrier properties or from the SIM language
7216 // preferences (EF-PL and EF-LI)...
7217 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007218 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007219 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7220 if (localeFromDefaultSim != null) {
7221 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7222 if (DBG) log("Using locale from subId: " + subId + " locale: "
7223 + localeFromDefaultSim);
7224 return localeFromDefaultSim.toLanguageTag();
7225 } else {
7226 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007227 }
7228 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230 // The SIM language preferences only store a language (e.g. fr = French), not an
7231 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7232 // the SIM and carrier preferences does not include a country we add the country
7233 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007234 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007236 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007237 return mccLocale.toLanguageTag();
7238 }
7239
7240 if (DBG) log("No locale found - returning null");
7241 return null;
7242 } finally {
7243 Binder.restoreCallingIdentity(identity);
7244 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007245 }
7246
7247 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007248 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007249 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007250 }
7251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007252 /**
7253 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7254 */
7255 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007256 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007257 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007258 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007259
Chenjie Yu1ba97252018-01-11 18:16:20 -08007260 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007261 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007262
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007263 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007264 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7265 * representing the state of the modem.
7266 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007267 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7268 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007269 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007270 */
7271 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007272 public void requestModemActivityInfo(ResultReceiver result) {
7273 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007274 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007275
7276 final long identity = Binder.clearCallingIdentity();
7277 try {
sqian1a1be542020-03-05 11:37:28 -08007278 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007279 } finally {
7280 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007281 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007282 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007283
Siddharth Rayb8114062018-06-17 15:02:38 -07007284 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7285 // less than total activity duration.
7286 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7287 if (info == null) {
7288 return false;
7289 }
7290 int activityDurationMs =
7291 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7292 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007293 int[] txTimeMs = info.getTransmitTimeMillis();
7294 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7295 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007296 }
7297 return (info.isValid()
7298 && (info.getSleepTimeMillis() <= activityDurationMs)
7299 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007300 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007301 && (totalTxTimeMs <= activityDurationMs));
7302 }
7303
Jack Yu85bd38a2015-11-09 11:34:32 -08007304 /**
7305 * {@hide}
7306 * Returns the service state information on specified subscription.
7307 */
7308 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007309 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7310 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007312 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007313 return null;
7314 }
7315
Hall Liuf19c44f2018-11-27 14:38:17 -08007316 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7317 LocationAccessPolicy.checkLocationPermission(mApp,
7318 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7319 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007320 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007321 .setCallingPid(Binder.getCallingPid())
7322 .setCallingUid(Binder.getCallingUid())
7323 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007324 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007325 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7326 .build());
7327
7328 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7329 LocationAccessPolicy.checkLocationPermission(mApp,
7330 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7331 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007332 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007333 .setCallingPid(Binder.getCallingPid())
7334 .setCallingUid(Binder.getCallingUid())
7335 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007336 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007337 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7338 .build());
7339 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7340 boolean hasFinePermission =
7341 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7342 boolean hasCoarsePermission =
7343 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007345 final long identity = Binder.clearCallingIdentity();
7346 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007347 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7348 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7349 Rlog.d(LOG_TAG,
7350 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7351 return null;
7352 }
7353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007354 final Phone phone = getPhone(subId);
7355 if (phone == null) {
7356 return null;
7357 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007358
Hall Liuf19c44f2018-11-27 14:38:17 -08007359 ServiceState ss = phone.getServiceState();
7360
7361 // Scrub out the location info in ServiceState depending on what level of access
7362 // the caller has.
7363 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007364 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7365 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 } finally {
7367 Binder.restoreCallingIdentity(identity);
7368 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007369 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007370
7371 /**
7372 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7373 *
7374 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7375 * voicemail ringtone.
7376 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7377 * PhoneAccount.
7378 */
7379 @Override
7380 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007381 final long identity = Binder.clearCallingIdentity();
7382 try {
7383 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7384 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007385 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007386 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007387
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007388 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7389 } finally {
7390 Binder.restoreCallingIdentity(identity);
7391 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007392 }
7393
7394 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007395 * Sets the per-account voicemail ringtone.
7396 *
7397 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7398 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7399 *
7400 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7401 * voicemail ringtone.
7402 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7403 * PhoneAccount.
7404 */
7405 @Override
7406 public void setVoicemailRingtoneUri(String callingPackage,
7407 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007408 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007409 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007410 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7411 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7413 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7414 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007415 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007416
7417 final long identity = Binder.clearCallingIdentity();
7418 try {
7419 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7420 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007421 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007422 }
7423 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7424 } finally {
7425 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007426 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007427 }
7428
7429 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007430 * Returns whether vibration is set for voicemail notification in Phone settings.
7431 *
7432 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7433 * voicemail vibration setting.
7434 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7435 */
7436 @Override
7437 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438 final long identity = Binder.clearCallingIdentity();
7439 try {
7440 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7441 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007442 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007444
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7446 } finally {
7447 Binder.restoreCallingIdentity(identity);
7448 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007449 }
7450
Youhan Wange64578a2016-05-02 15:32:42 -07007451 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007452 * Sets the per-account voicemail vibration.
7453 *
7454 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7455 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7456 *
7457 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7458 * voicemail vibration setting.
7459 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7460 * specific PhoneAccount.
7461 */
7462 @Override
7463 public void setVoicemailVibrationEnabled(String callingPackage,
7464 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007465 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007466 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007467 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7468 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007469 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7470 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7471 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007472 }
7473
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007474 final long identity = Binder.clearCallingIdentity();
7475 try {
7476 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7477 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007478 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 }
7480 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7481 } finally {
7482 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007483 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007484 }
7485
7486 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007487 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7488 *
7489 * @throws SecurityException if the caller does not have the required permission
7490 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007491 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007492 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007493 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007494 }
7495
7496 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007497 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7498 * permission.
7499 *
7500 * @throws SecurityException if the caller does not have the required permission
7501 */
7502 private void enforceSendSmsPermission() {
7503 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7504 }
7505
7506 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007507 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007508 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007509 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007510 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007511 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 final long identity = Binder.clearCallingIdentity();
7513 try {
7514 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007515 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007516 if (componentName == null) {
7517 throw new SecurityException(
7518 "Caller not current active visual voicemail package[null]");
7519 }
7520 String vvmPackage = componentName.getPackageName();
7521 if (!callingPackage.equals(vvmPackage)) {
7522 throw new SecurityException("Caller not current active visual voicemail package["
7523 + vvmPackage + "]");
7524 }
7525 } finally {
7526 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007527 }
7528 }
7529
7530 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007531 * Return the application ID for the app type.
7532 *
7533 * @param subId the subscription ID that this request applies to.
7534 * @param appType the uicc app type.
7535 * @return Application ID for specificied app type, or null if no uicc.
7536 */
7537 @Override
7538 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007539 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007540 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541
7542 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007543 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 if (phone == null) {
7545 return null;
7546 }
7547 String aid = null;
7548 try {
7549 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7550 .getApplicationByType(appType).getAid();
7551 } catch (Exception e) {
7552 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7553 }
7554 return aid;
7555 } finally {
7556 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007557 }
Youhan Wange64578a2016-05-02 15:32:42 -07007558 }
7559
Youhan Wang4001d252016-05-11 10:29:41 -07007560 /**
7561 * Return the Electronic Serial Number.
7562 *
7563 * @param subId the subscription ID that this request applies to.
7564 * @return ESN or null if error.
7565 */
7566 @Override
7567 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007568 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007569 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007570
7571 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007572 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007573 if (phone == null) {
7574 return null;
7575 }
7576 String esn = null;
7577 try {
7578 esn = phone.getEsn();
7579 } catch (Exception e) {
7580 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7581 }
7582 return esn;
7583 } finally {
7584 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007585 }
Youhan Wang4001d252016-05-11 10:29:41 -07007586 }
7587
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007588 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007589 * Return the Preferred Roaming List Version.
7590 *
7591 * @param subId the subscription ID that this request applies to.
7592 * @return PRLVersion or null if error.
7593 */
7594 @Override
7595 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007596 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007597 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007598
7599 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007600 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007601 if (phone == null) {
7602 return null;
7603 }
7604 String cdmaPrlVersion = null;
7605 try {
7606 cdmaPrlVersion = phone.getCdmaPrlVersion();
7607 } catch (Exception e) {
7608 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7609 }
7610 return cdmaPrlVersion;
7611 } finally {
7612 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007613 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007614 }
7615
7616 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007617 * Get snapshot of Telephony histograms
7618 * @return List of Telephony histograms
7619 * @hide
7620 */
7621 @Override
7622 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007623 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7624 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007625
7626 final long identity = Binder.clearCallingIdentity();
7627 try {
7628 return RIL.getTelephonyRILTimingHistograms();
7629 } finally {
7630 Binder.restoreCallingIdentity(identity);
7631 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007632 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007633
7634 /**
7635 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007636 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7637 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007638 * Require system privileges. In the future we may add this to carrier APIs.
7639 *
Michele Berionne482f8202018-11-27 18:57:59 -08007640 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007641 */
7642 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007643 @TelephonyManager.SetCarrierRestrictionResult
7644 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007645 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007646 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007647
Michele Berionne482f8202018-11-27 18:57:59 -08007648 if (carrierRestrictionRules == null) {
7649 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007650 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007651
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007652 final long identity = Binder.clearCallingIdentity();
7653 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007654 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007655 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007656 } finally {
7657 Binder.restoreCallingIdentity(identity);
7658 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007659 }
7660
7661 /**
7662 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007663 * Get the allowed carrier list and the excluded carrier list, including the priority between
7664 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007665 * Require system privileges. In the future we may add this to carrier APIs.
7666 *
Michele Berionne482f8202018-11-27 18:57:59 -08007667 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007668 */
7669 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007670 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007671 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007672 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007673
7674 final long identity = Binder.clearCallingIdentity();
7675 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007676 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7677 if (response instanceof CarrierRestrictionRules) {
7678 return (CarrierRestrictionRules) response;
7679 }
7680 // Response is an Exception of some kind,
7681 // which is signalled to the user as a NULL retval
7682 return null;
7683 } catch (Exception e) {
7684 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7685 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007686 } finally {
7687 Binder.restoreCallingIdentity(identity);
7688 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007689 }
7690
fionaxu59545b42016-05-25 15:53:37 -07007691 /**
fionaxu59545b42016-05-25 15:53:37 -07007692 * Action set from carrier signalling broadcast receivers to enable/disable radio
7693 * @param subId the subscription ID that this action applies to.
7694 * @param enabled control enable or disable radio.
7695 * {@hide}
7696 */
7697 @Override
7698 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7699 enforceModifyPermission();
7700 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701
7702 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007703 if (phone == null) {
7704 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7705 return;
7706 }
7707 try {
7708 phone.carrierActionSetRadioEnabled(enabled);
7709 } catch (Exception e) {
7710 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007711 } finally {
7712 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007713 }
7714 }
7715
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007716 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007717 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7718 * network status based on which carrier apps could apply actions accordingly,
7719 * enable/disable default url handler for example.
7720 *
7721 * @param subId the subscription ID that this action applies to.
7722 * @param report control start/stop reporting the default network status.
7723 * {@hide}
7724 */
7725 @Override
7726 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7727 enforceModifyPermission();
7728 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007729
7730 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007731 if (phone == null) {
7732 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7733 return;
7734 }
7735 try {
7736 phone.carrierActionReportDefaultNetworkStatus(report);
7737 } catch (Exception e) {
7738 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007739 } finally {
7740 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007741 }
7742 }
7743
7744 /**
fionaxud9622282017-07-17 17:51:30 -07007745 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7746 * @param subId the subscription ID that this action applies to.
7747 * {@hide}
7748 */
7749 @Override
7750 public void carrierActionResetAll(int subId) {
7751 enforceModifyPermission();
7752 final Phone phone = getPhone(subId);
7753 if (phone == null) {
7754 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7755 return;
7756 }
7757 try {
7758 phone.carrierActionResetAll();
7759 } catch (Exception e) {
7760 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7761 }
7762 }
7763
7764 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007765 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7766 * bug report is being generated.
7767 */
7768 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007769 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007770 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7771 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007772 writer.println("Permission Denial: can't dump Phone from pid="
7773 + Binder.getCallingPid()
7774 + ", uid=" + Binder.getCallingUid()
7775 + "without permission "
7776 + android.Manifest.permission.DUMP);
7777 return;
7778 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007779 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007780 }
Jack Yueb89b242016-06-22 13:27:47 -07007781
Brad Ebingerdac2f002018-04-03 15:17:52 -07007782 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007783 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7784 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7785 @NonNull String[] args) {
7786 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7787 this, in.getFileDescriptor(), out.getFileDescriptor(),
7788 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007789 }
7790
Jack Yueb89b242016-06-22 13:27:47 -07007791 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007792 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007793 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007794 * @param reason the reason the data enable change is taking place
7795 * @param enabled True if enabling the data, otherwise disabling.
7796 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007797 */
7798 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007799 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007800 boolean enabled) {
7801 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7802 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7803 try {
7804 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007805 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007806 } catch (SecurityException se) {
7807 enforceModifyPermission();
7808 }
7809 } else {
7810 enforceModifyPermission();
7811 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007812
7813 final long identity = Binder.clearCallingIdentity();
7814 try {
7815 Phone phone = getPhone(subId);
7816 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007817 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7818 phone.carrierActionSetMeteredApnsEnabled(enabled);
7819 } else {
7820 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7821 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007822 }
7823 } finally {
7824 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007825 }
7826 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007827
7828 /**
7829 * Get Client request stats
7830 * @return List of Client Request Stats
7831 * @hide
7832 */
7833 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007834 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7835 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007836 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007837 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007838 return null;
7839 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007840 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007841
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007842 final long identity = Binder.clearCallingIdentity();
7843 try {
7844 if (phone != null) {
7845 return phone.getClientRequestStats();
7846 }
7847
7848 return null;
7849 } finally {
7850 Binder.restoreCallingIdentity(identity);
7851 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007852 }
7853
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007854 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007855 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007856 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007857 }
Jack Yueb4124c2017-02-16 15:32:43 -08007858
7859 /**
Grace Chen70990072017-03-24 17:21:30 -07007860 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007861 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007862 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007863 * @param state State of SIM (power down, power up, pass through)
7864 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7865 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7866 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007867 *
7868 **/
7869 @Override
Grace Chen70990072017-03-24 17:21:30 -07007870 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007871 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007872 Phone phone = PhoneFactory.getPhone(slotIndex);
7873
vagdeviaf9a5b92018-08-15 16:01:53 -07007874 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7875
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007876 final long identity = Binder.clearCallingIdentity();
7877 try {
7878 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08007879 phone.setSimPowerState(state, null, workSource);
7880 }
7881 } finally {
7882 Binder.restoreCallingIdentity(identity);
7883 }
7884 }
7885
7886 /**
7887 * Set SIM card power state.
7888 *
7889 * @param slotIndex SIM slot id.
7890 * @param state State of SIM (power down, power up, pass through)
7891 * @param callback callback to trigger after success or failure
7892 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7893 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7894 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7895 *
7896 **/
7897 @Override
7898 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7899 IIntegerConsumer callback) {
7900 enforceModifyPermission();
7901 Phone phone = PhoneFactory.getPhone(slotIndex);
7902
7903 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7904
7905 final long identity = Binder.clearCallingIdentity();
7906 try {
7907 if (phone != null) {
7908 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
7909 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007910 }
7911 } finally {
7912 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007913 }
7914 }
Shuo Qiandd210312017-04-12 22:11:33 +00007915
Tyler Gunn65d45c22017-06-05 11:22:26 -07007916 private boolean isUssdApiAllowed(int subId) {
7917 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007918 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007919 if (configManager == null) {
7920 return false;
7921 }
7922 PersistableBundle pb = configManager.getConfigForSubId(subId);
7923 if (pb == null) {
7924 return false;
7925 }
7926 return pb.getBoolean(
7927 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7928 }
7929
Shuo Qiandd210312017-04-12 22:11:33 +00007930 /**
7931 * Check if phone is in emergency callback mode
7932 * @return true if phone is in emergency callback mode
7933 * @param subId sub id
7934 */
goneil9c5f4872017-12-05 14:07:56 -08007935 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007936 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007937 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007938 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007939
7940 final long identity = Binder.clearCallingIdentity();
7941 try {
7942 if (phone != null) {
7943 return phone.isInEcm();
7944 } else {
7945 return false;
7946 }
7947 } finally {
7948 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007949 }
7950 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007951
7952 /**
7953 * Get the current signal strength information for the given subscription.
7954 * Because this information is not updated when the device is in a low power state
7955 * it should not be relied-upon to be current.
7956 * @param subId Subscription index
7957 * @return the most recent cached signal strength info from the modem
7958 */
7959 @Override
7960 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007961 final long identity = Binder.clearCallingIdentity();
7962 try {
7963 Phone p = getPhone(subId);
7964 if (p == null) {
7965 return null;
7966 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007968 return p.getSignalStrength();
7969 } finally {
7970 Binder.restoreCallingIdentity(identity);
7971 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007972 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007973
Pengquan Meng77b7f132018-08-22 14:49:57 -07007974 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007975 * Get the current modem radio state for the given slot.
7976 * @param slotIndex slot index.
7977 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007978 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007979 * @return the current radio power state from the modem
7980 */
7981 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007982 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007983 Phone phone = PhoneFactory.getPhone(slotIndex);
7984 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7986 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007987 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7988 }
7989
7990 final long identity = Binder.clearCallingIdentity();
7991 try {
7992 return phone.getRadioPowerState();
7993 } finally {
7994 Binder.restoreCallingIdentity(identity);
7995 }
7996 }
7997 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7998 }
7999
8000 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008001 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8002 *
8003 * <p>Requires one of the following permissions:
8004 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8005 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8006 * privileges.
8007 *
8008 * @param subId subscription id
8009 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8010 * {@code false}.
8011 */
8012 @Override
8013 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008014 try {
8015 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8016 null);
8017 } catch (Exception e) {
8018 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8019 mApp, subId, "isDataRoamingEnabled");
8020 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008021
Pengquan Menga1bb6272018-09-06 09:59:22 -07008022 boolean isEnabled = false;
8023 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008024 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008025 Phone phone = getPhone(subId);
8026 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008027 } finally {
8028 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008029 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008030 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008031 }
8032
8033
8034 /**
8035 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8036 *
8037 * <p> Requires permission:
8038 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8039 * privileges.
8040 *
8041 * @param subId subscription id
8042 * @param isEnabled {@code true} means enable, {@code false} means disable.
8043 */
8044 @Override
8045 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8047 mApp, subId, "setDataRoamingEnabled");
8048
Pengquan Menga1bb6272018-09-06 09:59:22 -07008049 final long identity = Binder.clearCallingIdentity();
8050 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008051 Phone phone = getPhone(subId);
8052 if (phone != null) {
8053 phone.setDataRoamingEnabled(isEnabled);
8054 }
8055 } finally {
8056 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008057 }
8058 }
8059
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008060 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008061 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008062 TelephonyPermissions
8063 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008064 mApp, subId, "isManualNetworkSelectionAllowed");
8065
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008066 boolean isAllowed = true;
8067 final long identity = Binder.clearCallingIdentity();
8068 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008069 Phone phone = getPhone(subId);
8070 if (phone != null) {
8071 isAllowed = phone.isCspPlmnEnabled();
8072 }
8073 } finally {
8074 Binder.restoreCallingIdentity(identity);
8075 }
8076 return isAllowed;
8077 }
8078
8079 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008080 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008081 // Verify that tha callingPackage belongs to the calling UID
8082 mApp.getSystemService(AppOpsManager.class)
8083 .checkPackage(Binder.getCallingUid(), callingPackage);
8084
Jordan Liu1e142fc2019-04-22 15:10:43 -07008085 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008086 try {
8087 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008088 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008089 } catch (SecurityException e) {
8090 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8091 // has carrier privileges on an active UICC
8092 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8093 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008094 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008095 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008096 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008097
8098 final long identity = Binder.clearCallingIdentity();
8099 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008100 UiccController uiccController = UiccController.getInstance();
8101 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008102 if (hasReadPermission) {
8103 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008104 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008105
8106 // Remove private info if the caller doesn't have access
8107 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8108 for (UiccCardInfo cardInfo : cardInfos) {
8109 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8110 // is available
8111 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8112 if (card == null || card.getUiccProfile() == null) {
8113 // assume no access if the card or profile is unavailable
8114 filteredInfos.add(cardInfo.getUnprivileged());
8115 continue;
8116 }
8117 UiccProfile profile = card.getUiccProfile();
8118 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8119 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8120 filteredInfos.add(cardInfo);
8121 } else {
8122 filteredInfos.add(cardInfo.getUnprivileged());
8123 }
8124 }
8125 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008126 } finally {
8127 Binder.restoreCallingIdentity(identity);
8128 }
8129 }
8130
8131 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008132 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008133 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008135 final long identity = Binder.clearCallingIdentity();
8136 try {
8137 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8138 if (slots == null) {
8139 Rlog.i(LOG_TAG, "slots is null.");
8140 return null;
8141 }
8142
8143 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8144 for (int i = 0; i < slots.length; i++) {
8145 UiccSlot slot = slots[i];
8146 if (slot == null) {
8147 continue;
8148 }
8149
Jordan Liu7be7e652019-05-06 18:55:02 +00008150 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008151 UiccCard card = slot.getUiccCard();
8152 if (card != null) {
8153 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008154 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008155 cardId = slot.getEid();
8156 if (TextUtils.isEmpty(cardId)) {
8157 cardId = slot.getIccId();
8158 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008159 }
8160
Jordan Liu857451f2019-05-09 16:35:35 -07008161 if (cardId != null) {
8162 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8163 // if cardId is an EID, it's all digits so this is fine
8164 cardId = IccUtils.stripTrailingFs(cardId);
8165 }
8166
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008167 int cardState = 0;
8168 switch (slot.getCardState()) {
8169 case CARDSTATE_ABSENT:
8170 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8171 break;
8172 case CARDSTATE_PRESENT:
8173 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8174 break;
8175 case CARDSTATE_ERROR:
8176 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8177 break;
8178 case CARDSTATE_RESTRICTED:
8179 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8180 break;
8181 default:
8182 break;
8183
8184 }
8185
8186 infos[i] = new UiccSlotInfo(
8187 slot.isActive(),
8188 slot.isEuicc(),
8189 cardId,
8190 cardState,
8191 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008192 slot.isExtendedApduSupported(),
8193 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008194 }
8195 return infos;
8196 } finally {
8197 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008198 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008199 }
8200
8201 @Override
8202 public boolean switchSlots(int[] physicalSlots) {
8203 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008204
8205 final long identity = Binder.clearCallingIdentity();
8206 try {
8207 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8208 } finally {
8209 Binder.restoreCallingIdentity(identity);
8210 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008211 }
Jack Yu4c988042018-02-27 15:30:01 -08008212
8213 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008214 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008215 final long identity = Binder.clearCallingIdentity();
8216 try {
8217 return UiccController.getInstance().getCardIdForDefaultEuicc();
8218 } finally {
8219 Binder.restoreCallingIdentity(identity);
8220 }
8221 }
8222
Pengquan Meng85728fb2018-03-12 16:31:21 -07008223 /**
goneil47ffb6e2018-04-06 15:40:58 -07008224 * A test API to reload the UICC profile.
8225 *
8226 * <p>Requires that the calling app has permission
8227 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8228 * @hide
8229 */
8230 @Override
8231 public void refreshUiccProfile(int subId) {
8232 enforceModifyPermission();
8233
8234 final long identity = Binder.clearCallingIdentity();
8235 try {
8236 Phone phone = getPhone(subId);
8237 if (phone == null) {
8238 return;
8239 }
8240 UiccCard uiccCard = phone.getUiccCard();
8241 if (uiccCard == null) {
8242 return;
8243 }
8244 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8245 if (uiccProfile == null) {
8246 return;
8247 }
8248 uiccProfile.refresh();
8249 } finally {
8250 Binder.restoreCallingIdentity(identity);
8251 }
8252 }
8253
8254 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008255 * Returns false if the mobile data is disabled by default, otherwise return true.
8256 */
8257 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008258 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008259 }
8260
8261 /**
8262 * Returns true if the data roaming is enabled by default, i.e the system property
8263 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8264 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8265 */
8266 private boolean getDefaultDataRoamingEnabled(int subId) {
8267 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008268 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008269 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008270 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8271 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8272 return isDataRoamingEnabled;
8273 }
8274
8275 /**
8276 * Returns the default network type for the given {@code subId}, if the default network type is
8277 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8278 */
8279 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008280 List<Integer> list = TelephonyProperties.default_network();
8281 int phoneId = mSubscriptionController.getPhoneId(subId);
8282 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8283 return list.get(phoneId);
8284 }
8285 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008286 }
fionaxua13278b2018-03-21 00:08:13 -07008287
8288 @Override
8289 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008290 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008291 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008292
8293 final long identity = Binder.clearCallingIdentity();
8294 try {
8295 final Phone phone = getPhone(subId);
8296 if (phone == null) {
8297 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8298 return;
8299 }
chen xueaba88a2019-03-15 13:15:10 -07008300 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8301 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008302 if (carrierPrivilegeRules == null) {
8303 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8304 } else {
8305 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8306 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008307 } finally {
8308 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008309 }
fionaxua13278b2018-03-21 00:08:13 -07008310 }
8311
8312 @Override
8313 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008314 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008315
8316 final long identity = Binder.clearCallingIdentity();
8317 try {
8318 final Phone phone = getPhone(subId);
8319 if (phone == null) {
8320 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8321 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8322 }
8323 return phone.getCarrierIdListVersion();
8324 } finally {
8325 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008326 }
fionaxua13278b2018-03-21 00:08:13 -07008327 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008328
8329 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008330 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8331 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008332 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008333 mApp, subId, callingPackage, callingFeatureId,
8334 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008335 return -1;
8336 }
8337
8338 final long identity = Binder.clearCallingIdentity();
8339 try {
8340 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8341 } finally {
8342 Binder.restoreCallingIdentity(identity);
8343 }
8344 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008345
8346 @Override
8347 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008348 TelephonyPermissions
8349 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008350 mApp, subId, "getCdmaRoamingMode");
8351
8352 final long identity = Binder.clearCallingIdentity();
8353 try {
8354 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8355 } finally {
8356 Binder.restoreCallingIdentity(identity);
8357 }
8358 }
8359
8360 @Override
8361 public boolean setCdmaRoamingMode(int subId, int mode) {
8362 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8363 mApp, subId, "setCdmaRoamingMode");
8364
8365 final long identity = Binder.clearCallingIdentity();
8366 try {
8367 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8368 } finally {
8369 Binder.restoreCallingIdentity(identity);
8370 }
8371 }
8372
8373 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008374 public int getCdmaSubscriptionMode(int subId) {
8375 TelephonyPermissions
8376 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8377 mApp, subId, "getCdmaSubscriptionMode");
8378
8379 final long identity = Binder.clearCallingIdentity();
8380 try {
8381 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8382 } finally {
8383 Binder.restoreCallingIdentity(identity);
8384 }
8385 }
8386
8387 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008388 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8390 mApp, subId, "setCdmaSubscriptionMode");
8391
8392 final long identity = Binder.clearCallingIdentity();
8393 try {
8394 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8395 } finally {
8396 Binder.restoreCallingIdentity(identity);
8397 }
8398 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008399
sqianc5eccab2018-10-19 18:46:41 -07008400 @Override
sqian8c685422019-02-22 15:55:18 -08008401 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008402 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008403 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008404 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8405 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008406 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8407 }
8408 final long identity = Binder.clearCallingIdentity();
8409 try {
sqian854d44b2018-12-12 16:48:18 -08008410 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8411 for (Phone phone: PhoneFactory.getPhones()) {
8412 if (phone.getEmergencyNumberTracker() != null
8413 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8414 emergencyNumberListInternal.put(
8415 phone.getSubId(),
8416 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8417 }
sqian11b7a0e2018-12-05 18:48:28 -08008418 }
sqian854d44b2018-12-12 16:48:18 -08008419 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008420 } finally {
8421 Binder.restoreCallingIdentity(identity);
8422 }
sqianc5eccab2018-10-19 18:46:41 -07008423 }
8424
8425 @Override
sqian8c685422019-02-22 15:55:18 -08008426 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008427 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008428 if (!exactMatch) {
8429 TelephonyPermissions
8430 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008431 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008432 }
8433 final long identity = Binder.clearCallingIdentity();
8434 try {
sqian854d44b2018-12-12 16:48:18 -08008435 for (Phone phone: PhoneFactory.getPhones()) {
8436 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008437 && phone.getEmergencyNumberTracker()
8438 .isEmergencyNumber(number, exactMatch)) {
8439 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008440 }
sqian11b7a0e2018-12-05 18:48:28 -08008441 }
8442 return false;
8443 } finally {
8444 Binder.restoreCallingIdentity(identity);
8445 }
8446 }
8447
sqianf4ca7ed2019-01-15 18:32:07 -08008448 /**
8449 * Update emergency number list for test mode.
8450 */
8451 @Override
8452 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8453 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8454 "updateEmergencyNumberListTestMode");
8455
8456 final long identity = Binder.clearCallingIdentity();
8457 try {
8458 for (Phone phone: PhoneFactory.getPhones()) {
8459 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8460 if (tracker != null) {
8461 tracker.executeEmergencyNumberTestModeCommand(action, num);
8462 }
8463 }
8464 } finally {
8465 Binder.restoreCallingIdentity(identity);
8466 }
8467 }
8468
8469 /**
8470 * Get the full emergency number list for test mode.
8471 */
8472 @Override
8473 public List<String> getEmergencyNumberListTestMode() {
8474 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8475 "getEmergencyNumberListTestMode");
8476
8477 final long identity = Binder.clearCallingIdentity();
8478 try {
8479 Set<String> emergencyNumbers = new HashSet<>();
8480 for (Phone phone: PhoneFactory.getPhones()) {
8481 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8482 if (tracker != null) {
8483 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8484 emergencyNumbers.add(num.getNumber());
8485 }
8486 }
8487 }
8488 return new ArrayList<>(emergencyNumbers);
8489 } finally {
8490 Binder.restoreCallingIdentity(identity);
8491 }
8492 }
8493
chen xud6b45bd2018-10-30 22:27:10 -07008494 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008495 public int getEmergencyNumberDbVersion(int subId) {
8496 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8497
8498 final long identity = Binder.clearCallingIdentity();
8499 try {
8500 final Phone phone = getPhone(subId);
8501 if (phone == null) {
8502 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8503 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8504 }
8505 return phone.getEmergencyNumberDbVersion();
8506 } finally {
8507 Binder.restoreCallingIdentity(identity);
8508 }
8509 }
8510
8511 @Override
8512 public void notifyOtaEmergencyNumberDbInstalled() {
8513 enforceModifyPermission();
8514
8515 final long identity = Binder.clearCallingIdentity();
8516 try {
8517 for (Phone phone: PhoneFactory.getPhones()) {
8518 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8519 if (tracker != null) {
8520 tracker.updateOtaEmergencyNumberDatabase();
8521 }
8522 }
8523 } finally {
8524 Binder.restoreCallingIdentity(identity);
8525 }
8526 }
8527
8528 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008529 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008530 enforceActiveEmergencySessionPermission();
8531
8532 final long identity = Binder.clearCallingIdentity();
8533 try {
8534 for (Phone phone: PhoneFactory.getPhones()) {
8535 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8536 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008537 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8538 }
8539 }
8540 } finally {
8541 Binder.restoreCallingIdentity(identity);
8542 }
8543 }
8544
8545 @Override
8546 public void resetOtaEmergencyNumberDbFilePath() {
8547 enforceActiveEmergencySessionPermission();
8548
8549 final long identity = Binder.clearCallingIdentity();
8550 try {
8551 for (Phone phone: PhoneFactory.getPhones()) {
8552 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8553 if (tracker != null) {
8554 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008555 }
8556 }
8557 } finally {
8558 Binder.restoreCallingIdentity(identity);
8559 }
8560 }
8561
8562 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008563 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8564 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8565 Phone phone = getPhone(subId);
8566 if (phone == null) {
8567 return null;
8568 }
8569 final long identity = Binder.clearCallingIdentity();
8570 try {
8571 UiccProfile profile = UiccController.getInstance()
8572 .getUiccProfileForPhone(phone.getPhoneId());
8573 if (profile != null) {
8574 return profile.getCertsFromCarrierPrivilegeAccessRules();
8575 }
8576 } finally {
8577 Binder.restoreCallingIdentity(identity);
8578 }
8579 return null;
8580 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008581
8582 /**
8583 * Enable or disable a modem stack.
8584 */
8585 @Override
8586 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8587 enforceModifyPermission();
8588
8589 final long identity = Binder.clearCallingIdentity();
8590 try {
8591 Phone phone = PhoneFactory.getPhone(slotIndex);
8592 if (phone == null) {
8593 return false;
8594 } else {
8595 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8596 }
8597 } finally {
8598 Binder.restoreCallingIdentity(identity);
8599 }
8600 }
Michelecea4cf22018-12-21 15:00:11 -08008601
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008602 /**
8603 * Whether a modem stack is enabled or not.
8604 */
8605 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008606 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8607 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008608 Phone phone = PhoneFactory.getPhone(slotIndex);
8609 if (phone == null) return false;
8610
8611 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008612 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8613 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008614 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8615 }
8616
8617 final long identity = Binder.clearCallingIdentity();
8618 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008619 try {
8620 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8621 } catch (NoSuchElementException ex) {
8622 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8623 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008624 } finally {
8625 Binder.restoreCallingIdentity(identity);
8626 }
8627 }
8628
Michelecea4cf22018-12-21 15:00:11 -08008629 @Override
Michele0ea7d782019-03-19 14:58:42 -07008630 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008631 enforceModifyPermission();
8632
8633 final long identity = Binder.clearCallingIdentity();
8634 try {
8635 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008636 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008637 .commit();
8638 } finally {
8639 Binder.restoreCallingIdentity(identity);
8640 }
8641 }
8642
8643 @Override
Michele0ea7d782019-03-19 14:58:42 -07008644 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008645 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008646 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008647 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8648 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008649 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008650 }
Michelecea4cf22018-12-21 15:00:11 -08008651
8652 final long identity = Binder.clearCallingIdentity();
8653 try {
Michele0ea7d782019-03-19 14:58:42 -07008654 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008655 } finally {
8656 Binder.restoreCallingIdentity(identity);
8657 }
8658 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008659
Michele0ea7d782019-03-19 14:58:42 -07008660 @TelephonyManager.IsMultiSimSupportedResult
8661 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008662 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8663 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8664 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008665 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8666 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008667 }
8668 // Check if the hardware supports multisim functionality. If usage of multisim is not
8669 // supported by the modem, indicate that it is restricted.
8670 PhoneCapability staticCapability =
8671 mPhoneConfigurationManager.getStaticPhoneCapability();
8672 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008673 loge("isMultiSimSupportedInternal: no static configuration available");
8674 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008675 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008676 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008677 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8678 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008679 }
8680 // Check if support of multiple SIMs is restricted by carrier
8681 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008682 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008683 }
8684
Michele0ea7d782019-03-19 14:58:42 -07008685 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008686 }
8687
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008688 /**
8689 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008690 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8691 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8692 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008693 * @param numOfSims number of active sims we want to switch to
8694 */
8695 @Override
8696 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008697 if (numOfSims == 1) {
8698 enforceModifyPermission();
8699 } else {
8700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8701 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8702 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008703 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008704
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008705 try {
Michele30b57b22019-03-01 12:01:14 -08008706 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008707 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008708 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8709 return;
8710 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008711 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8712 } finally {
8713 Binder.restoreCallingIdentity(identity);
8714 }
8715 }
8716
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008717 @Override
8718 public boolean isApplicationOnUicc(int subId, int appType) {
8719 enforceReadPrivilegedPermission("isApplicationOnUicc");
8720 Phone phone = getPhone(subId);
8721 if (phone == null) {
8722 return false;
8723 }
8724 final long identity = Binder.clearCallingIdentity();
8725 try {
8726 UiccCard uiccCard = phone.getUiccCard();
8727 if (uiccCard == null) {
8728 return false;
8729 }
8730 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8731 if (uiccProfile == null) {
8732 return false;
8733 }
8734 if (TelephonyManager.APPTYPE_SIM <= appType
8735 && appType <= TelephonyManager.APPTYPE_ISIM) {
8736 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8737 }
8738 return false;
8739 } finally {
8740 Binder.restoreCallingIdentity(identity);
8741 }
8742 }
8743
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008744 /**
chen xub4baa772019-04-03 10:23:41 -07008745 * Get whether making changes to modem configurations will trigger reboot.
8746 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008747 */
8748 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008749 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8750 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008751 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008752 mApp, subId, callingPackage, callingFeatureId,
8753 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008754 return false;
8755 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008756 final long identity = Binder.clearCallingIdentity();
8757 try {
8758 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8759 } finally {
8760 Binder.restoreCallingIdentity(identity);
8761 }
8762 }
8763
Nathan Harold29f5f052019-02-15 13:41:57 -08008764 private void updateModemStateMetrics() {
8765 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8766 // TODO: check the state for each modem if the api is ready.
8767 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8768 }
8769
Pengquan Meng3889a572019-01-23 11:16:29 -08008770 @Override
8771 public int[] getSlotsMapping() {
8772 enforceReadPrivilegedPermission("getSlotsMapping");
8773
8774 final long identity = Binder.clearCallingIdentity();
8775 try {
8776 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8777 // All logical slots should have a mapping to a physical slot.
8778 int[] logicalSlotsMapping = new int[phoneCount];
8779 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8780 for (int i = 0; i < slotInfos.length; i++) {
8781 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8782 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8783 }
8784 }
8785 return logicalSlotsMapping;
8786 } finally {
8787 Binder.restoreCallingIdentity(identity);
8788 }
8789 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008790
8791 /**
8792 * Get the IRadio HAL Version
8793 */
8794 @Override
8795 public int getRadioHalVersion() {
8796 Phone phone = getDefaultPhone();
8797 if (phone == null) return -1;
8798 HalVersion hv = phone.getHalVersion();
8799 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8800 return hv.major * 100 + hv.minor;
8801 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008802
8803 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008804 * Get the current calling package name.
8805 * @return the current calling package name
8806 */
8807 @Override
8808 public String getCurrentPackageName() {
8809 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8810 }
8811
8812 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008813 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8814 * corresponding network requests on a subId.
8815 *
8816 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008817 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008818 * 2) APN is un-metered for this subscription, or
8819 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008820 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008821 *
8822 * @return whether data is allowed for a apn type.
8823 *
8824 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008825 */
8826 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008827 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008828 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8829 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008830
8831 // Now that all security checks passes, perform the operation as ourselves.
8832 final long identity = Binder.clearCallingIdentity();
8833 try {
8834 Phone phone = getPhone(subId);
8835 if (phone == null) return false;
8836
Jack Yu41407ee2019-05-13 16:54:09 -07008837 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008838 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8839 } finally {
8840 Binder.restoreCallingIdentity(identity);
8841 }
8842 }
8843
8844 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008845 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008846 enforceReadPrivilegedPermission("isApnMetered");
8847
8848 // Now that all security checks passes, perform the operation as ourselves.
8849 final long identity = Binder.clearCallingIdentity();
8850 try {
8851 Phone phone = getPhone(subId);
8852 if (phone == null) return true; // By default return true.
8853
Jack Yu41407ee2019-05-13 16:54:09 -07008854 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008855 } finally {
8856 Binder.restoreCallingIdentity(identity);
8857 }
8858 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008859
8860 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008861 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8862 int subscriptionId, IBooleanConsumer resultCallback) {
8863 enforceModifyPermission();
8864 long token = Binder.clearCallingIdentity();
8865 try {
8866 Phone phone = getPhone(subscriptionId);
8867 if (phone == null) {
8868 try {
8869 if (resultCallback != null) {
8870 resultCallback.accept(false);
8871 }
8872 } catch (RemoteException e) {
8873 // ignore
8874 }
8875 return;
8876 }
8877 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8878 Pair.create(specifiers, (x) -> {
8879 try {
8880 if (resultCallback != null) {
8881 resultCallback.accept(x);
8882 }
8883 } catch (RemoteException e) {
8884 // ignore
8885 }
8886 });
8887 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8888 } finally {
8889 Binder.restoreCallingIdentity(token);
8890 }
8891 }
8892
8893 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008894 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8895 TelephonyPermissions
8896 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8897 mApp, subId, "getSystemSelectionChannels");
8898 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8899 final long identity = Binder.clearCallingIdentity();
8900 try {
8901 List<RadioAccessSpecifier> specifiers =
8902 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8903 null, subId, workSource);
8904 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8905 return specifiers;
8906 } finally {
8907 Binder.restoreCallingIdentity(identity);
8908 }
8909 }
8910
8911 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008912 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008913 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008914 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8915 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8916 if (iccRecords == null) {
8917 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8918 return false;
8919 }
8920 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8921 }
8922
8923 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008924 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8925 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008926 if (callingPackage == null) {
8927 callingPackage = getCurrentPackageName();
8928 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008929 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8930 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008931 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8932 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008933 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8934 }
8935 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8936 Intent intent = new Intent();
8937 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8938 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8939 // Bring up choose default SMS subscription dialog right now
8940 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8941 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8942 mApp.startActivity(intent);
8943 }
chen xud5ca2d52019-05-28 15:20:57 -07008944
8945 @Override
8946 public String getMmsUAProfUrl(int subId) {
8947 //TODO investigate if this API should require proper permission check in R b/133791609
8948 final long identity = Binder.clearCallingIdentity();
8949 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008950 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8951 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8952 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8953 return carrierUAProfUrl;
8954 }
chen xud5ca2d52019-05-28 15:20:57 -07008955 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8956 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8957 } finally {
8958 Binder.restoreCallingIdentity(identity);
8959 }
8960 }
8961
8962 @Override
8963 public String getMmsUserAgent(int subId) {
8964 //TODO investigate if this API should require proper permission check in R b/133791609
8965 final long identity = Binder.clearCallingIdentity();
8966 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008967 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8968 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8969 if (!TextUtils.isEmpty(carrierUserAgent)) {
8970 return carrierUserAgent;
8971 }
chen xud5ca2d52019-05-28 15:20:57 -07008972 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8973 .getString(com.android.internal.R.string.config_mms_user_agent);
8974 } finally {
8975 Binder.restoreCallingIdentity(identity);
8976 }
8977 }
Jack Yub07d4972019-05-28 16:12:25 -07008978
8979 @Override
Hall Liuc041a552020-09-25 10:42:19 -07008980 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8981 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
8982
8983 final long identity = Binder.clearCallingIdentity();
8984 try {
8985 Phone phone = getPhone(subscriptionId);
8986 if (phone == null) return false;
8987
8988 switch (policy) {
8989 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8990 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8991 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8992 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8993 default:
8994 throw new IllegalArgumentException(policy + " is not a valid policy");
8995 }
8996 } finally {
8997 Binder.restoreCallingIdentity(identity);
8998 }
8999 }
9000
9001 @Override
9002 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9003 boolean enabled) {
9004 enforceModifyPermission();
9005
9006 final long identity = Binder.clearCallingIdentity();
9007 try {
9008 Phone phone = getPhone(subscriptionId);
9009 if (phone == null) return;
9010
9011 switch (policy) {
9012 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9013 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9014 break;
9015 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9016 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9017 break;
9018 default:
9019 throw new IllegalArgumentException(policy + " is not a valid policy");
9020 }
9021 } finally {
9022 Binder.restoreCallingIdentity(identity);
9023 }
9024 }
9025
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009026 /**
Hall Liub48cf452020-09-25 11:13:49 -07009027 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009028 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9029 * otherwise.
9030 */
9031 @Override
9032 public void setCepEnabled(boolean isCepEnabled) {
9033 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9034
9035 final long identity = Binder.clearCallingIdentity();
9036 try {
9037 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9038 for (Phone phone : PhoneFactory.getPhones()) {
9039 Phone defaultPhone = phone.getImsPhone();
9040 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9041 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9042 ImsPhoneCallTracker imsPhoneCallTracker =
9043 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9044 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9045 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9046 + imsPhone.getMsisdn());
9047 }
9048 }
9049 } finally {
9050 Binder.restoreCallingIdentity(identity);
9051 }
9052 }
allenwtsu46dcc572020-01-08 18:24:03 +08009053
9054 /**
9055 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9056 *
9057 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9058 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9059 * before being read.
9060 */
9061 @Override
9062 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9063 isCompressed) {
9064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9065 mApp, subId, "notifyRcsAutoConfigurationReceived");
9066 try {
9067 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9068 if (configBinder == null) {
9069 Rlog.e(LOG_TAG, "null result for getImsConfig");
9070 } else {
9071 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
9072 }
9073 } catch (RemoteException e) {
9074 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
9075 }
9076 }
zoey chenf95ca592019-12-30 16:11:23 +08009077
9078 @Override
9079 public boolean isIccLockEnabled(int subId) {
9080 enforceReadPrivilegedPermission("isIccLockEnabled");
9081
9082 // Now that all security checks passes, perform the operation as ourselves.
9083 final long identity = Binder.clearCallingIdentity();
9084 try {
9085 Phone phone = getPhone(subId);
9086 if (phone != null && phone.getIccCard() != null) {
9087 return phone.getIccCard().getIccLockEnabled();
9088 } else {
9089 return false;
9090 }
9091 } finally {
9092 Binder.restoreCallingIdentity(identity);
9093 }
9094 }
9095
9096 /**
zoey chene02881a2019-12-30 16:11:23 +08009097 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009098 *
zoey chene02881a2019-12-30 16:11:23 +08009099 * @return an integer representing the status of IccLock enabled or disabled in the following
9100 * three cases:
9101 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9102 * successfully.
9103 * - Positive number and zero for remaining password attempts.
9104 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009105 *
9106 */
9107 @Override
9108 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9109 enforceModifyPermission();
9110
9111 Phone phone = getPhone(subId);
9112 if (phone == null) {
9113 return 0;
9114 }
9115 // Now that all security checks passes, perform the operation as ourselves.
9116 final long identity = Binder.clearCallingIdentity();
9117 try {
9118 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9119 new Pair<Boolean, String>(enabled, password), phone, null);
9120 return attemptsRemaining;
9121
9122 } catch (Exception e) {
9123 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9124 } finally {
9125 Binder.restoreCallingIdentity(identity);
9126 }
9127 return 0;
9128 }
9129
9130 /**
9131 * Change the ICC password used in ICC pin lock.
9132 *
zoey chene02881a2019-12-30 16:11:23 +08009133 * @return an integer representing the status of IccLock changed in the following three cases:
9134 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9135 * - Positive number and zero for remaining password attempts.
9136 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009137 *
9138 */
9139 @Override
9140 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9141 enforceModifyPermission();
9142
9143 Phone phone = getPhone(subId);
9144 if (phone == null) {
9145 return 0;
9146 }
9147 // Now that all security checks passes, perform the operation as ourselves.
9148 final long identity = Binder.clearCallingIdentity();
9149 try {
9150 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9151 new Pair<String, String>(oldPassword, newPassword), phone, null);
9152 return attemptsRemaining;
9153
9154 } catch (Exception e) {
9155 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9156 } finally {
9157 Binder.restoreCallingIdentity(identity);
9158 }
9159 return 0;
9160 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009161
Peter Wangdafb9ac2020-01-15 14:13:38 -08009162 /**
9163 * Request for receiving user activity notification
9164 */
9165 @Override
9166 public void requestUserActivityNotification() {
9167 if (!mNotifyUserActivity.get()
9168 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9169 mNotifyUserActivity.set(true);
9170 }
9171 }
9172
9173 /**
9174 * Called when userActivity is signalled in the power manager.
9175 * This is safe to call from any thread, with any window manager locks held or not.
9176 */
9177 @Override
9178 public void userActivity() {
9179 // ***************************************
9180 // * Inherited from PhoneWindowManager *
9181 // ***************************************
9182 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9183 // WITH ITS LOCKS HELD.
9184 //
9185 // This code must be VERY careful about the locks
9186 // it acquires.
9187 // In fact, the current code acquires way too many,
9188 // and probably has lurking deadlocks.
9189
9190 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9191 throw new SecurityException("Only the OS may call notifyUserActivity()");
9192 }
9193
9194 if (mNotifyUserActivity.getAndSet(false)) {
9195 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9196 USER_ACTIVITY_NOTIFICATION_DELAY);
9197 }
9198 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009199
Malcolm Chen884180b2020-04-13 11:59:40 -07009200 @Override
9201 public boolean canConnectTo5GInDsdsMode() {
9202 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9203 }
Jack Yud10cdd42020-09-28 20:28:01 -07009204
9205 @Override
9206 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9207 String callingFeatureId) {
9208 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9209 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9210 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9211 }
9212
9213 Phone phone = getPhone(subId);
9214 if (phone == null) {
9215 throw new RuntimeException("phone is not available");
9216 }
9217 // Now that all security checks passes, perform the operation as ourselves.
9218 final long identity = Binder.clearCallingIdentity();
9219 try {
9220 return phone.getEquivalentHomePlmns();
9221 } finally {
9222 Binder.restoreCallingIdentity(identity);
9223 }
9224 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009225
Hui Wang0866fcc2020-10-12 12:14:23 -07009226 @Override
9227 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9228 UaSecurityProtocolIdentifier securityProtocol,
9229 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9230 throws RemoteException {
9231 enforceModifyPermission();
9232 if (DBG) {
9233 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9234 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9235 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9236 }
9237
9238 if (!SubscriptionManager.isValidSubscriptionId(subId)
9239 || appType < TelephonyManager.APPTYPE_UNKNOWN
9240 || appType > TelephonyManager.APPTYPE_ISIM
9241 || nafUrl == null || securityProtocol == null || callback == null) {
9242 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9243 if (callback != null) {
9244 try {
9245 callback.onAuthenticationFailure(
9246 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9247 } catch (RemoteException exception) {
9248 log("Fail to notify onAuthenticationFailure due to " + exception);
9249 }
9250 return;
9251 }
9252 }
9253
9254 final long token = Binder.clearCallingIdentity();
9255 try {
9256 getGbaManager(subId).bootstrapAuthenticationRequest(
9257 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9258 forceBootStrapping, callback));
9259 } finally {
9260 Binder.restoreCallingIdentity(token);
9261 }
9262 }
9263
Jack Nudelman24d51a52020-11-24 12:08:04 -08009264 /**
9265 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9266 * requested radio power state will actually be set. See {@link
9267 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9268 *
9269 * @param subId the subscription ID of the phone requesting to set the radio power state.
9270 * @param enable {@code true} if trying to turn radio on.
9271 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9272 * false}.
9273 */
9274 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9275 Phone phone = getPhone(subId);
9276 if (phone != null) {
9277 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9278 return true;
9279 }
9280 return false;
9281 }
9282
9283 private int handleDataThrottlingRequest(int subId,
9284 DataThrottlingRequest dataThrottlingRequest) {
9285 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9286 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9287 if (!setRadioPowerForThermal(subId, true)) {
9288 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9289 }
9290
9291 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9292
9293 int thermalMitigationResult =
9294 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9295 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9296 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9297 }
9298 return thermalMitigationResult;
9299 }
9300
9301 /**
9302 * Thermal mitigation request to control functionalities at modem.
9303 *
9304 * @param subId the id of the subscription.
9305 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9306 *
9307 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9308 */
9309 @Override
9310 @ThermalMitigationResult
9311 public int sendThermalMitigationRequest(
9312 int subId,
9313 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9314 enforceModifyPermission();
9315
9316 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9317 final long identity = Binder.clearCallingIdentity();
9318
9319 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9320 try {
9321 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9322 switch (thermalMitigationAction) {
9323 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9324 thermalMitigationResult =
9325 handleDataThrottlingRequest(subId,
9326 thermalMitigationRequest.getDataThrottlingRequest());
9327 break;
9328 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9329 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9330 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9331 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9332 }
9333
9334 // Ensure that radio is on. If not able to power on due to phone being
9335 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9336 if (!setRadioPowerForThermal(subId, true)) {
9337 thermalMitigationResult =
9338 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9339 break;
9340 }
9341
9342 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9343 false);
9344 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9345 break;
9346 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9347 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9348 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9349 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9350 }
9351
9352 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9353 if (registry != null) {
9354 TelephonyConnectionService service =
9355 registry.getTelephonyConnectionService();
9356 Phone phone = getPhone(subId);
9357 if (phone == null) {
9358 thermalMitigationResult =
9359 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9360 break;
9361 }
9362
9363 if (PhoneConstantConversions.convertCallState(phone.getState())
9364 != TelephonyManager.CALL_STATE_IDLE
9365 || phone.isInEmergencySmsMode() || phone.isInEcm()
9366 || (service != null && service.isEmergencyCallPending())) {
9367 String errorMessage = "Phone state is not valid. call state = "
9368 + PhoneConstantConversions.convertCallState(phone.getState())
9369 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9370 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9371 errorMessage += service == null
9372 ? " TelephonyConnectionService is null"
9373 : " isEmergencyCallPending = "
9374 + service.isEmergencyCallPending();
9375 Log.e(LOG_TAG, errorMessage);
9376 thermalMitigationResult =
9377 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9378 break;
9379 }
9380 } else {
9381 thermalMitigationResult =
9382 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9383 break;
9384 }
9385
9386 // Turn radio off. If not able to power off due to phone being unavailable,
9387 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9388 if (!setRadioPowerForThermal(subId, false)) {
9389 thermalMitigationResult =
9390 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9391 break;
9392 }
9393 thermalMitigationResult =
9394 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9395 break;
9396 default:
9397 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9398 + "not exist. Requested action: " + thermalMitigationAction);
9399 }
9400 } catch (IllegalArgumentException e) {
9401 throw e;
9402 } catch (Exception e) {
9403 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9404 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9405 } finally {
9406 Binder.restoreCallingIdentity(identity);
9407 }
9408
9409 if (DBG) {
9410 log("thermalMitigationRequest returning with thermalMitigationResult: "
9411 + thermalMitigationResult);
9412 }
9413
9414 return thermalMitigationResult;
9415 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009416
9417 /**
9418 * Set the GbaService Package Name that Telephony will bind to.
9419 *
9420 * @param subId The sim that the GbaService is associated with.
9421 * @param packageName The name of the package to be replaced with.
9422 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9423 */
9424 @Override
9425 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9426 enforceModifyPermission();
9427
9428 final long identity = Binder.clearCallingIdentity();
9429 try {
9430 return getGbaManager(subId).overrideServicePackage(packageName);
9431 } finally {
9432 Binder.restoreCallingIdentity(identity);
9433 }
9434 }
9435
9436 /**
9437 * Return the package name of the currently bound GbaService.
9438 *
9439 * @param subId The sim that the GbaService is associated with.
9440 * @return the package name of the GbaService configuration, null if GBA is not supported.
9441 */
9442 @Override
9443 public String getBoundGbaService(int subId) {
9444 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9445
9446 final long identity = Binder.clearCallingIdentity();
9447 try {
9448 return getGbaManager(subId).getServicePackage();
9449 } finally {
9450 Binder.restoreCallingIdentity(identity);
9451 }
9452 }
9453
9454 /**
9455 * Set the release time for telephony to unbind GbaService.
9456 *
9457 * @param subId The sim that the GbaService is associated with.
9458 * @param interval The release time to unbind GbaService by millisecond.
9459 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9460 */
9461 @Override
9462 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9463 enforceModifyPermission();
9464
9465 final long identity = Binder.clearCallingIdentity();
9466 try {
9467 return getGbaManager(subId).overrideReleaseTime(interval);
9468 } finally {
9469 Binder.restoreCallingIdentity(identity);
9470 }
9471 }
9472
9473 /**
9474 * Return the release time for telephony to unbind GbaService.
9475 *
9476 * @param subId The sim that the GbaService is associated with.
9477 * @return The release time to unbind GbaService by millisecond.
9478 */
9479 @Override
9480 public int getGbaReleaseTime(int subId) {
9481 enforceReadPrivilegedPermission("getGbaReleaseTime");
9482
9483 final long identity = Binder.clearCallingIdentity();
9484 try {
9485 return getGbaManager(subId).getReleaseTime();
9486 } finally {
9487 Binder.restoreCallingIdentity(identity);
9488 }
9489 }
9490
9491 private GbaManager getGbaManager(int subId) {
9492 GbaManager instance = GbaManager.getInstance(subId);
9493 if (instance == null) {
9494 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9495 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9496 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9497 }
9498 return instance;
9499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009500}