blob: cee57a2d473989fce3e5071736a7ab3652220cea [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700312
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800313 // Parameters of select command.
314 private static final int SELECT_COMMAND = 0xA4;
315 private static final int SELECT_P1 = 0x04;
316 private static final int SELECT_P2 = 0;
317 private static final int SELECT_P3 = 0x10;
318
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319 /** The singleton instance. */
320 private static PhoneInterfaceManager sInstance;
321
Wink Saville3ab207e2014-11-20 13:07:20 -0800322 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800323 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800324 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700325 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800326 private AppOpsManager mAppOps;
327 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800328 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800329 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700330 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700331
Peter Wangdafb9ac2020-01-15 14:13:38 -0800332 /** User Activity */
333 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800334 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
335
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700336 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
337
Derek Tan97ebb422014-09-05 16:55:38 -0700338 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
339 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800340 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800341 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700342
Michelecea4cf22018-12-21 15:00:11 -0800343 // String to store multi SIM allowed
344 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
345
Derek Tan740e1672017-06-27 14:56:27 -0700346 // The AID of ISD-R.
347 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
348
yinxub1bed742017-04-17 11:45:04 -0700349 private NetworkScanRequestTracker mNetworkScanRequestTracker;
350
David Kelly5e06a7f2018-03-12 14:10:59 +0000351 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
352 private static final int MANUFACTURER_CODE_LENGTH = 8;
353
Jack Nudelman24d51a52020-11-24 12:08:04 -0800354 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
355
Derek Tan89e89d42014-07-08 17:00:10 -0700356 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700357 * Experiment flag to enable erase modem config on reset network, default value is false
358 */
359 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
360 "reset_network_erase_modem_config_enabled";
361
362 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700363 * A request object to use for transmitting data to an ICC.
364 */
365 private static final class IccAPDUArgument {
366 public int channel, cla, command, p1, p2, p3;
367 public String data;
368
369 public IccAPDUArgument(int channel, int cla, int command,
370 int p1, int p2, int p3, String data) {
371 this.channel = channel;
372 this.cla = cla;
373 this.command = command;
374 this.p1 = p1;
375 this.p2 = p2;
376 this.p3 = p3;
377 this.data = data;
378 }
379 }
380
381 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700382 * A request object to use for transmitting data to an ICC.
383 */
384 private static final class ManualNetworkSelectionArgument {
385 public OperatorInfo operatorInfo;
386 public boolean persistSelection;
387
388 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
389 this.operatorInfo = operatorInfo;
390 this.persistSelection = persistSelection;
391 }
392 }
393
394 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
396 * request after sending. The main thread will notify the request when it is complete.
397 */
398 private static final class MainThreadRequest {
399 /** The argument to use for the request */
400 public Object argument;
401 /** The result of the request that is run on the main thread */
402 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800403 // The subscriber id that this request applies to. Defaults to
404 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
405 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406
Nathan Harold92bed182018-10-12 18:16:49 -0700407 // In cases where subId is unavailable, the caller needs to specify the phone.
408 public Phone phone;
409
vagdeviaf9a5b92018-08-15 16:01:53 -0700410 public WorkSource workSource;
411
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700412 public MainThreadRequest(Object argument) {
413 this.argument = argument;
414 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800415
Nathan Harold92bed182018-10-12 18:16:49 -0700416 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
417 this.argument = argument;
418 if (phone != null) {
419 this.phone = phone;
420 }
421 this.workSource = workSource;
422 }
423
vagdeviaf9a5b92018-08-15 16:01:53 -0700424 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800425 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800426 if (subId != null) {
427 this.subId = subId;
428 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700429 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431 }
432
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800433 private static final class IncomingThirdPartyCallArgs {
434 public final ComponentName component;
435 public final String callId;
436 public final String callerDisplayName;
437
438 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
439 String callerDisplayName) {
440 this.component = component;
441 this.callId = callId;
442 this.callerDisplayName = callerDisplayName;
443 }
444 }
445
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446 /**
447 * A handler that processes messages on the main thread in the phone process. Since many
448 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
449 * inbound binder threads to the main thread in the phone process. The Binder thread
450 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
451 * on, which will be notified when the operation completes and will contain the result of the
452 * request.
453 *
454 * <p>If a MainThreadRequest object is provided in the msg.obj field,
455 * note that request.result must be set to something non-null for the calling thread to
456 * unblock.
457 */
458 private final class MainThreadHandler extends Handler {
459 @Override
460 public void handleMessage(Message msg) {
461 MainThreadRequest request;
462 Message onCompleted;
463 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800464 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700465 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800466 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700467
468 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700469 case CMD_HANDLE_USSD_REQUEST: {
470 request = (MainThreadRequest) msg.obj;
471 final Phone phone = getPhoneFromRequest(request);
472 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
473 String ussdRequest = ussdObject.first;
474 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700475
Pengquan Menga1bb6272018-09-06 09:59:22 -0700476 if (!isUssdApiAllowed(request.subId)) {
477 // Carrier does not support use of this API, return failure.
478 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
479 UssdResponse response = new UssdResponse(ussdRequest, null);
480 Bundle returnData = new Bundle();
481 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
482 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700483
Pengquan Menga1bb6272018-09-06 09:59:22 -0700484 request.result = true;
485 notifyRequester(request);
486 return;
487 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700488
Pengquan Menga1bb6272018-09-06 09:59:22 -0700489 try {
490 request.result = phone != null
491 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
492 } catch (CallStateException cse) {
493 request.result = false;
494 }
495 // Wake up the requesting thread
496 notifyRequester(request);
497 break;
pkanwar32d516d2016-10-14 19:37:38 -0700498 }
499
Yorke Lee716f67e2015-06-17 15:39:16 -0700500 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700501 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700502 final Phone phone = getPhoneFromRequest(request);
503 request.result = phone != null ?
504 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
505 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700506 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700507 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700508 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700509 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700510
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700511 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700512 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700513 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800514 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700515 if (uiccCard == null) {
516 loge("iccTransmitApduLogicalChannel: No UICC");
517 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700518 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700519 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700520 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
521 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700522 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 iccArgument.channel, iccArgument.cla, iccArgument.command,
524 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700525 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700526 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700527 break;
528
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700530 ar = (AsyncResult) msg.obj;
531 request = (MainThreadRequest) ar.userObj;
532 if (ar.exception == null && ar.result != null) {
533 request.result = ar.result;
534 } else {
535 request.result = new IccIoResult(0x6F, 0, (byte[])null);
536 if (ar.result == null) {
537 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800538 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700539 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800540 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700541 } else {
542 loge("iccTransmitApduLogicalChannel: Unknown exception");
543 }
544 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700545 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700546 break;
547
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700548 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
549 request = (MainThreadRequest) msg.obj;
550 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800551 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 if (uiccCard == null) {
553 loge("iccTransmitApduBasicChannel: No UICC");
554 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700555 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700556 } else {
557 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
558 request);
559 uiccCard.iccTransmitApduBasicChannel(
560 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
561 iccArgument.p3, iccArgument.data, onCompleted);
562 }
563 break;
564
565 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
566 ar = (AsyncResult) msg.obj;
567 request = (MainThreadRequest) ar.userObj;
568 if (ar.exception == null && ar.result != null) {
569 request.result = ar.result;
570 } else {
571 request.result = new IccIoResult(0x6F, 0, (byte[])null);
572 if (ar.result == null) {
573 loge("iccTransmitApduBasicChannel: Empty response");
574 } else if (ar.exception instanceof CommandException) {
575 loge("iccTransmitApduBasicChannel: CommandException: " +
576 ar.exception);
577 } else {
578 loge("iccTransmitApduBasicChannel: Unknown exception");
579 }
580 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700581 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700582 break;
583
584 case CMD_EXCHANGE_SIM_IO:
585 request = (MainThreadRequest) msg.obj;
586 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800587 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 if (uiccCard == null) {
589 loge("iccExchangeSimIO: No UICC");
590 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 } else {
593 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
594 request);
595 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
596 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
597 iccArgument.data, onCompleted);
598 }
599 break;
600
601 case EVENT_EXCHANGE_SIM_IO_DONE:
602 ar = (AsyncResult) msg.obj;
603 request = (MainThreadRequest) ar.userObj;
604 if (ar.exception == null && ar.result != null) {
605 request.result = ar.result;
606 } else {
607 request.result = new IccIoResult(0x6f, 0, (byte[])null);
608 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700609 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 break;
611
Derek Tan4d5e5c12014-02-04 11:54:58 -0800612 case CMD_SEND_ENVELOPE:
613 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800614 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700615 if (uiccCard == null) {
616 loge("sendEnvelopeWithStatus: No UICC");
617 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700618 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700619 } else {
620 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
621 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
622 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800623 break;
624
625 case EVENT_SEND_ENVELOPE_DONE:
626 ar = (AsyncResult) msg.obj;
627 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700628 if (ar.exception == null && ar.result != null) {
629 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800630 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700631 request.result = new IccIoResult(0x6F, 0, (byte[])null);
632 if (ar.result == null) {
633 loge("sendEnvelopeWithStatus: Empty response");
634 } else if (ar.exception instanceof CommandException) {
635 loge("sendEnvelopeWithStatus: CommandException: " +
636 ar.exception);
637 } else {
638 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
639 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800640 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700641 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800642 break;
643
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 case CMD_OPEN_CHANNEL:
645 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800646 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800647 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700648 if (uiccCard == null) {
649 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800650 request.result = new IccOpenLogicalChannelResponse(-1,
651 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700653 } else {
654 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800655 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
656 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700657 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 break;
659
660 case EVENT_OPEN_CHANNEL_DONE:
661 ar = (AsyncResult) msg.obj;
662 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700663 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700665 int[] result = (int[]) ar.result;
666 int channelId = result[0];
667 byte[] selectResponse = null;
668 if (result.length > 1) {
669 selectResponse = new byte[result.length - 1];
670 for (int i = 1; i < result.length; ++i) {
671 selectResponse[i - 1] = (byte) result[i];
672 }
673 }
674 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700675 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 if (ar.result == null) {
678 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700680 if (ar.exception != null) {
681 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
682 }
683
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700684 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700685 if (ar.exception instanceof CommandException) {
686 CommandException.Error error =
687 ((CommandException) (ar.exception)).getCommandError();
688 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700689 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700690 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700691 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700692 }
693 }
694 openChannelResp = new IccOpenLogicalChannelResponse(
695 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700697 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700698 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700699 break;
700
701 case CMD_CLOSE_CHANNEL:
702 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800703 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700704 if (uiccCard == null) {
705 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900706 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700707 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700708 } else {
709 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
710 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
711 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700712 break;
713
714 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800715 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
716 break;
717
718 case CMD_NV_READ_ITEM:
719 request = (MainThreadRequest) msg.obj;
720 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800721 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
722 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800723 break;
724
725 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700726 ar = (AsyncResult) msg.obj;
727 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800728 if (ar.exception == null && ar.result != null) {
729 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700730 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800731 request.result = "";
732 if (ar.result == null) {
733 loge("nvReadItem: Empty response");
734 } else if (ar.exception instanceof CommandException) {
735 loge("nvReadItem: CommandException: " +
736 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700737 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800738 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700739 }
740 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700741 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 break;
743
Jake Hambye994d462014-02-03 13:10:13 -0800744 case CMD_NV_WRITE_ITEM:
745 request = (MainThreadRequest) msg.obj;
746 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
747 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800748 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700749 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800750 break;
751
752 case EVENT_NV_WRITE_ITEM_DONE:
753 handleNullReturnEvent(msg, "nvWriteItem");
754 break;
755
756 case CMD_NV_WRITE_CDMA_PRL:
757 request = (MainThreadRequest) msg.obj;
758 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800759 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800760 break;
761
762 case EVENT_NV_WRITE_CDMA_PRL_DONE:
763 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
764 break;
765
chen xu6dac5ab2018-10-26 17:39:23 -0700766 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800767 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700768 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800769 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800770 break;
771
chen xu6dac5ab2018-10-26 17:39:23 -0700772 case EVENT_RESET_MODEM_CONFIG_DONE:
773 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800774 break;
775
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700776 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
777 request = (MainThreadRequest) msg.obj;
778 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
779 request);
780 Phone phone = getPhoneFromRequest(request);
781 if (phone != null) {
782 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
783 } else {
784 loge("isNRDualConnectivityEnabled: No phone object");
785 request.result = false;
786 notifyRequester(request);
787 }
788 break;
789 }
790
791 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
792 ar = (AsyncResult) msg.obj;
793 request = (MainThreadRequest) ar.userObj;
794 if (ar.exception == null && ar.result != null) {
795 request.result = ar.result;
796 } else {
797 // request.result must be set to something non-null
798 // for the calling thread to unblock
799 if (request.result != null) {
800 request.result = ar.result;
801 } else {
802 request.result = false;
803 }
804 if (ar.result == null) {
805 loge("isNRDualConnectivityEnabled: Empty response");
806 } else if (ar.exception instanceof CommandException) {
807 loge("isNRDualConnectivityEnabled: CommandException: "
808 + ar.exception);
809 } else {
810 loge("isNRDualConnectivityEnabled: Unknown exception");
811 }
812 }
813 notifyRequester(request);
814 break;
815
816 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
817 request = (MainThreadRequest) msg.obj;
818 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
819 Phone phone = getPhoneFromRequest(request);
820 if (phone != null) {
821 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
822 request.workSource);
823 } else {
824 loge("enableNrDualConnectivity: No phone object");
825 request.result =
826 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
827 notifyRequester(request);
828 }
829 break;
830 }
831
832 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
833 ar = (AsyncResult) msg.obj;
834 request = (MainThreadRequest) ar.userObj;
835 if (ar.exception == null) {
836 request.result =
837 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
838 } else {
839 request.result =
840 TelephonyManager
841 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
842 if (ar.exception instanceof CommandException) {
843 CommandException.Error error =
844 ((CommandException) (ar.exception)).getCommandError();
845 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
846 request.result =
847 TelephonyManager
848 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
849 }
850 loge("enableNrDualConnectivity" + ": CommandException: "
851 + ar.exception);
852 } else {
853 loge("enableNrDualConnectivity" + ": Unknown exception");
854 }
855 }
856 notifyRequester(request);
857 break;
858 }
859
Jake Hamby7c27be32014-03-03 13:25:59 -0800860 case CMD_GET_PREFERRED_NETWORK_TYPE:
861 request = (MainThreadRequest) msg.obj;
862 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700863 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800864 break;
865
866 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
867 ar = (AsyncResult) msg.obj;
868 request = (MainThreadRequest) ar.userObj;
869 if (ar.exception == null && ar.result != null) {
870 request.result = ar.result; // Integer
871 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530872 // request.result must be set to something non-null
873 // for the calling thread to unblock
874 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800875 if (ar.result == null) {
876 loge("getPreferredNetworkType: Empty response");
877 } else if (ar.exception instanceof CommandException) {
878 loge("getPreferredNetworkType: CommandException: " +
879 ar.exception);
880 } else {
881 loge("getPreferredNetworkType: Unknown exception");
882 }
883 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700884 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800885 break;
886
887 case CMD_SET_PREFERRED_NETWORK_TYPE:
888 request = (MainThreadRequest) msg.obj;
889 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
890 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700891 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800892 break;
893
894 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
895 handleNullReturnEvent(msg, "setPreferredNetworkType");
896 break;
897
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000898 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
899 request = (MainThreadRequest)msg.obj;
900 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800901 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000902 break;
903
904 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
905 ar = (AsyncResult)msg.obj;
906 request = (MainThreadRequest)ar.userObj;
907 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700908 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000909 break;
910
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800911 case CMD_SET_VOICEMAIL_NUMBER:
912 request = (MainThreadRequest) msg.obj;
913 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
914 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800915 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
916 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800917 break;
918
919 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
920 handleNullReturnEvent(msg, "setVoicemailNumber");
921 break;
922
Stuart Scott54788802015-03-30 13:18:01 -0700923 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
924 request = (MainThreadRequest) msg.obj;
925 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
926 request);
927 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
928 break;
929
930 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
931 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
932 break;
933
Shishir Agrawal302c8692015-06-19 13:49:39 -0700934 case CMD_PERFORM_NETWORK_SCAN:
935 request = (MainThreadRequest) msg.obj;
936 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
937 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
938 break;
939
Hall Liua1acea22020-09-18 19:04:59 -0700940 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800941 request = (MainThreadRequest) msg.obj;
942 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700943 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
944 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
945 request.argument;
946 int callForwardingReason = args.first;
947 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800948 break;
Hall Liua1acea22020-09-18 19:04:59 -0700949 }
950 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800951 ar = (AsyncResult) msg.obj;
952 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700953 TelephonyManager.CallForwardingInfoCallback callback =
954 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
955 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800956 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700957 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800958 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
959 for (CallForwardInfo callForwardInfo : callForwardInfos) {
960 // Service Class is a bit mask per 3gpp 27.007. Search for
961 // any service for voice call.
962 if ((callForwardInfo.serviceClass
963 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700964 callForwardingInfo = new CallForwardingInfo(true,
965 callForwardInfo.reason,
966 callForwardInfo.number,
967 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800968 break;
969 }
970 }
971 // Didn't find a call forward info for voice call.
972 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700973 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
974 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800975 }
Hall Liua1acea22020-09-18 19:04:59 -0700976 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -0800977 } else {
978 if (ar.result == null) {
979 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
980 }
981 if (ar.exception != null) {
982 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
983 }
Hall Liuae527aa2020-09-29 17:10:18 -0700984 int errorCode = TelephonyManager
985 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -0800986 if (ar.exception instanceof CommandException) {
987 CommandException.Error error =
988 ((CommandException) (ar.exception)).getCommandError();
989 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -0700990 errorCode = TelephonyManager
991 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -0800992 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -0700993 errorCode = TelephonyManager
994 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -0800995 }
996 }
Hall Liua1acea22020-09-18 19:04:59 -0700997 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -0800998 }
sqian80370722020-01-29 15:02:51 -0800999 break;
Hall Liua1acea22020-09-18 19:04:59 -07001000 }
sqian80370722020-01-29 15:02:51 -08001001
Hall Liua1acea22020-09-18 19:04:59 -07001002 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001003 request = (MainThreadRequest) msg.obj;
1004 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001005 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001006 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001007 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1008 request.argument).first;
1009 request.phone.setCallForwardingOption(
1010 callForwardingInfoToSet.isEnabled()
1011 ? CommandsInterface.CF_ACTION_ENABLE
1012 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001013 callForwardingInfoToSet.getReason(),
1014 callForwardingInfoToSet.getNumber(),
1015 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1016 break;
Hall Liua1acea22020-09-18 19:04:59 -07001017 }
sqian80370722020-01-29 15:02:51 -08001018
Hall Liua1acea22020-09-18 19:04:59 -07001019 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001020 ar = (AsyncResult) msg.obj;
1021 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001022 Consumer<Integer> callback =
1023 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1024 request.argument).second;
1025 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001026 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001027 int errorCode = TelephonyManager.CallForwardingInfoCallback
1028 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001029 if (ar.exception instanceof CommandException) {
1030 CommandException.Error error =
1031 ((CommandException) (ar.exception)).getCommandError();
1032 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001033 errorCode = TelephonyManager.CallForwardingInfoCallback
1034 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001035 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001036 errorCode = TelephonyManager.CallForwardingInfoCallback
1037 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001038 }
1039 }
1040 callback.accept(errorCode);
1041 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001042 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001043 }
sqian80370722020-01-29 15:02:51 -08001044 break;
Hall Liua1acea22020-09-18 19:04:59 -07001045 }
sqian80370722020-01-29 15:02:51 -08001046
Hall Liua1acea22020-09-18 19:04:59 -07001047 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001048 request = (MainThreadRequest) msg.obj;
1049 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1050 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1051 break;
Hall Liua1acea22020-09-18 19:04:59 -07001052 }
sqian80370722020-01-29 15:02:51 -08001053
Hall Liua1acea22020-09-18 19:04:59 -07001054 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001055 ar = (AsyncResult) msg.obj;
1056 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001057 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001058 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1059 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001060 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001061 // Service Class is a bit mask per 3gpp 27.007.
1062 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001063 if (callForwardResults.length > 1
1064 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001065 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001066 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001067 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1068 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001069 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001070 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001071 }
1072 } else {
1073 if (ar.result == null) {
1074 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1075 }
1076 if (ar.exception != null) {
1077 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1078 }
1079 if (ar.exception instanceof CommandException) {
1080 CommandException.Error error =
1081 ((CommandException) (ar.exception)).getCommandError();
1082 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1083 callForwardingStatus =
1084 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1085 }
1086 }
1087 }
Hall Liua1acea22020-09-18 19:04:59 -07001088 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001089 break;
Hall Liua1acea22020-09-18 19:04:59 -07001090 }
sqian80370722020-01-29 15:02:51 -08001091
Hall Liua1acea22020-09-18 19:04:59 -07001092 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001093 request = (MainThreadRequest) msg.obj;
1094 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001095 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1096 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001097 break;
Hall Liua1acea22020-09-18 19:04:59 -07001098 }
sqian80370722020-01-29 15:02:51 -08001099
Hall Liua1acea22020-09-18 19:04:59 -07001100 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001101 ar = (AsyncResult) msg.obj;
1102 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001103 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1104 Consumer<Integer> callback =
1105 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1106 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001107 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001108 if (ar.exception instanceof CommandException) {
1109 CommandException.Error error =
1110 ((CommandException) (ar.exception)).getCommandError();
1111 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1112 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1113 } else {
1114 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1115 }
1116 } else {
1117 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1118 }
1119 } else {
1120 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1121 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001122 }
sqian80370722020-01-29 15:02:51 -08001123 break;
Hall Liua1acea22020-09-18 19:04:59 -07001124 }
sqian80370722020-01-29 15:02:51 -08001125
Shishir Agrawal302c8692015-06-19 13:49:39 -07001126 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1127 ar = (AsyncResult) msg.obj;
1128 request = (MainThreadRequest) ar.userObj;
1129 CellNetworkScanResult cellScanResult;
1130 if (ar.exception == null && ar.result != null) {
1131 cellScanResult = new CellNetworkScanResult(
1132 CellNetworkScanResult.STATUS_SUCCESS,
1133 (List<OperatorInfo>) ar.result);
1134 } else {
1135 if (ar.result == null) {
1136 loge("getCellNetworkScanResults: Empty response");
1137 }
1138 if (ar.exception != null) {
1139 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1140 }
1141 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1142 if (ar.exception instanceof CommandException) {
1143 CommandException.Error error =
1144 ((CommandException) (ar.exception)).getCommandError();
1145 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1146 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1147 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1148 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1149 }
1150 }
1151 cellScanResult = new CellNetworkScanResult(errorCode, null);
1152 }
1153 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001154 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001155 break;
1156
1157 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1158 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001159 ManualNetworkSelectionArgument selArg =
1160 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001161 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1162 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001163 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1164 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001165 break;
1166
1167 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001168 ar = (AsyncResult) msg.obj;
1169 request = (MainThreadRequest) ar.userObj;
1170 if (ar.exception == null) {
1171 request.result = true;
1172 } else {
1173 request.result = false;
1174 loge("setNetworkSelectionModeManual " + ar.exception);
1175 }
1176 notifyRequester(request);
1177 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001178 break;
1179
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001180 case CMD_GET_MODEM_ACTIVITY_INFO:
1181 request = (MainThreadRequest) msg.obj;
1182 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001183 if (defaultPhone != null) {
1184 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001185 } else {
1186 ResultReceiver result = (ResultReceiver) request.argument;
1187 Bundle bundle = new Bundle();
1188 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1189 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1190 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001191 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001192 break;
1193
1194 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1195 ar = (AsyncResult) msg.obj;
1196 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001197 ResultReceiver result = (ResultReceiver) request.argument;
1198
1199 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001200 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001201 // Update the last modem activity info and the result of the request.
1202 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1203 if (isModemActivityInfoValid(info)) {
1204 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1205 int[] txTimeMs = info.getTransmitTimeMillis();
1206 int[] lastModemTxTimeMs = mLastModemActivityInfo
1207 .getTransmitTimeMillis();
1208 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1209 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1210 }
1211 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1212 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1213 + mLastModemActivityInfo.getSleepTimeMillis());
1214 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1215 + mLastModemActivityInfo.getIdleTimeMillis());
1216 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1217 mLastModemActivityInfo.setReceiveTimeMillis(
1218 info.getReceiveTimeMillis()
1219 + mLastModemActivityInfo.getReceiveTimeMillis());
1220 }
1221 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1222 mLastModemActivityInfo.getSleepTimeMillis(),
1223 mLastModemActivityInfo.getIdleTimeMillis(),
1224 mLastModemActivityInfo.getTransmitTimeMillis(),
1225 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001226 } else {
1227 if (ar.result == null) {
1228 loge("queryModemActivityInfo: Empty response");
1229 } else if (ar.exception instanceof CommandException) {
1230 loge("queryModemActivityInfo: CommandException: " +
1231 ar.exception);
1232 } else {
1233 loge("queryModemActivityInfo: Unknown exception");
1234 }
1235 }
sqian1a1be542020-03-05 11:37:28 -08001236 Bundle bundle = new Bundle();
1237 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1238 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001239 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001240 break;
1241
Meng Wang1a7c35a2016-05-05 20:56:15 -07001242 case CMD_SET_ALLOWED_CARRIERS:
1243 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001244 CarrierRestrictionRules argument =
1245 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001246 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001247 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001248 break;
1249
1250 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1251 ar = (AsyncResult) msg.obj;
1252 request = (MainThreadRequest) ar.userObj;
1253 if (ar.exception == null && ar.result != null) {
1254 request.result = ar.result;
1255 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001256 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1257 if (ar.exception instanceof CommandException) {
1258 loge("setAllowedCarriers: CommandException: " + ar.exception);
1259 CommandException.Error error =
1260 ((CommandException) (ar.exception)).getCommandError();
1261 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1262 request.result =
1263 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1264 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001265 } else {
1266 loge("setAllowedCarriers: Unknown exception");
1267 }
1268 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001269 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001270 break;
1271
1272 case CMD_GET_ALLOWED_CARRIERS:
1273 request = (MainThreadRequest) msg.obj;
1274 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001275 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001276 break;
1277
1278 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1279 ar = (AsyncResult) msg.obj;
1280 request = (MainThreadRequest) ar.userObj;
1281 if (ar.exception == null && ar.result != null) {
1282 request.result = ar.result;
1283 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001284 request.result = new IllegalStateException(
1285 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001286 if (ar.result == null) {
1287 loge("getAllowedCarriers: Empty response");
1288 } else if (ar.exception instanceof CommandException) {
1289 loge("getAllowedCarriers: CommandException: " +
1290 ar.exception);
1291 } else {
1292 loge("getAllowedCarriers: Unknown exception");
1293 }
1294 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001295 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001296 break;
1297
Nathan Haroldb3014052017-01-25 15:57:32 -08001298 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1299 ar = (AsyncResult) msg.obj;
1300 request = (MainThreadRequest) ar.userObj;
1301 if (ar.exception == null && ar.result != null) {
1302 request.result = ar.result;
1303 } else {
1304 request.result = new IllegalArgumentException(
1305 "Failed to retrieve Forbidden Plmns");
1306 if (ar.result == null) {
1307 loge("getForbiddenPlmns: Empty response");
1308 } else {
1309 loge("getForbiddenPlmns: Unknown exception");
1310 }
1311 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001312 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001313 break;
1314
1315 case CMD_GET_FORBIDDEN_PLMNS:
1316 request = (MainThreadRequest) msg.obj;
1317 uiccCard = getUiccCardFromRequest(request);
1318 if (uiccCard == null) {
1319 loge("getForbiddenPlmns() UiccCard is null");
1320 request.result = new IllegalArgumentException(
1321 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001322 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001323 break;
1324 }
1325 Integer appType = (Integer) request.argument;
1326 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1327 if (uiccApp == null) {
1328 loge("getForbiddenPlmns() no app with specified type -- "
1329 + appType);
1330 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001331 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001332 break;
1333 } else {
1334 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1335 + " specified type -- " + appType);
1336 }
1337 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1338 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1339 onCompleted);
1340 break;
1341
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001342 case CMD_SWITCH_SLOTS:
1343 request = (MainThreadRequest) msg.obj;
1344 int[] physicalSlots = (int[]) request.argument;
1345 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1346 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1347 break;
1348
1349 case EVENT_SWITCH_SLOTS_DONE:
1350 ar = (AsyncResult) msg.obj;
1351 request = (MainThreadRequest) ar.userObj;
1352 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001353 notifyRequester(request);
1354 break;
1355 case CMD_GET_NETWORK_SELECTION_MODE:
1356 request = (MainThreadRequest) msg.obj;
1357 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1358 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1359 break;
1360
1361 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1362 ar = (AsyncResult) msg.obj;
1363 request = (MainThreadRequest) ar.userObj;
1364 if (ar.exception != null) {
1365 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1366 } else {
1367 int mode = ((int[]) ar.result)[0];
1368 if (mode == 0) {
1369 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1370 } else {
1371 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1372 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001373 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001374 notifyRequester(request);
1375 break;
1376 case CMD_GET_CDMA_ROAMING_MODE:
1377 request = (MainThreadRequest) msg.obj;
1378 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1379 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1380 break;
1381 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1382 ar = (AsyncResult) msg.obj;
1383 request = (MainThreadRequest) ar.userObj;
1384 if (ar.exception != null) {
1385 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1386 } else {
1387 request.result = ((int[]) ar.result)[0];
1388 }
1389 notifyRequester(request);
1390 break;
1391 case CMD_SET_CDMA_ROAMING_MODE:
1392 request = (MainThreadRequest) msg.obj;
1393 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1394 int mode = (int) request.argument;
1395 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1396 break;
1397 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1398 ar = (AsyncResult) msg.obj;
1399 request = (MainThreadRequest) ar.userObj;
1400 request.result = ar.exception == null;
1401 notifyRequester(request);
1402 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001403 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1404 request = (MainThreadRequest) msg.obj;
1405 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1406 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1407 break;
1408 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1409 ar = (AsyncResult) msg.obj;
1410 request = (MainThreadRequest) ar.userObj;
1411 if (ar.exception != null) {
1412 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1413 } else {
1414 request.result = ((int[]) ar.result)[0];
1415 }
1416 notifyRequester(request);
1417 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001418 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1419 request = (MainThreadRequest) msg.obj;
1420 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1421 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001422 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1423 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001424 break;
1425 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1426 ar = (AsyncResult) msg.obj;
1427 request = (MainThreadRequest) ar.userObj;
1428 request.result = ar.exception == null;
1429 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001430 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001431 case CMD_GET_ALL_CELL_INFO:
1432 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001433 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001434 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001435 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001436 case EVENT_GET_ALL_CELL_INFO_DONE:
1437 ar = (AsyncResult) msg.obj;
1438 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001439 // If a timeout occurs, the response will be null
1440 request.result = (ar.exception == null && ar.result != null)
1441 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001442 synchronized (request) {
1443 request.notifyAll();
1444 }
1445 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001446 case CMD_REQUEST_CELL_INFO_UPDATE:
1447 request = (MainThreadRequest) msg.obj;
1448 request.phone.requestCellInfoUpdate(request.workSource,
1449 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1450 break;
1451 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1452 ar = (AsyncResult) msg.obj;
1453 request = (MainThreadRequest) ar.userObj;
1454 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1455 try {
1456 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001457 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001458 cb.onError(
1459 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1460 ar.exception.getClass().getName(),
1461 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001462 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001463 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001464 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001465 } else {
1466 // use the result as returned
1467 cb.onCellInfo((List<CellInfo>) ar.result);
1468 }
1469 } catch (RemoteException re) {
1470 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1471 }
1472 break;
Sarah Chincc055732020-11-18 13:39:35 -08001473 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001474 request = (MainThreadRequest) msg.obj;
1475 WorkSource ws = (WorkSource) request.argument;
1476 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001477 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001478 break;
Sarah Chincc055732020-11-18 13:39:35 -08001479 }
1480 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001481 ar = (AsyncResult) msg.obj;
1482 request = (MainThreadRequest) ar.userObj;
1483 if (ar.exception == null) {
1484 request.result = ar.result;
1485 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001486 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001487 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001488 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001489 }
1490
1491 synchronized (request) {
1492 request.notifyAll();
1493 }
1494 break;
Sarah Chincc055732020-11-18 13:39:35 -08001495 }
chen xu6dac5ab2018-10-26 17:39:23 -07001496 case CMD_MODEM_REBOOT:
1497 request = (MainThreadRequest) msg.obj;
1498 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001499 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001500 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001501 case EVENT_CMD_MODEM_REBOOT_DONE:
1502 handleNullReturnEvent(msg, "rebootModem");
1503 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001504 case CMD_REQUEST_ENABLE_MODEM:
1505 request = (MainThreadRequest) msg.obj;
1506 boolean enable = (boolean) request.argument;
1507 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001508 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001509 PhoneConfigurationManager.getInstance()
1510 .enablePhone(request.phone, enable, onCompleted);
1511 break;
1512 case EVENT_ENABLE_MODEM_DONE:
1513 ar = (AsyncResult) msg.obj;
1514 request = (MainThreadRequest) ar.userObj;
1515 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001516 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001517 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001518 if ((boolean) request.result) {
1519 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1520 updateModemStateMetrics();
1521 } else {
1522 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1523 + ar.exception);
1524 }
1525 notifyRequester(request);
1526 break;
1527 case CMD_GET_MODEM_STATUS:
1528 request = (MainThreadRequest) msg.obj;
1529 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1530 PhoneConfigurationManager.getInstance()
1531 .getPhoneStatusFromModem(request.phone, onCompleted);
1532 break;
1533 case EVENT_GET_MODEM_STATUS_DONE:
1534 ar = (AsyncResult) msg.obj;
1535 request = (MainThreadRequest) ar.userObj;
1536 int id = request.phone.getPhoneId();
1537 if (ar.exception == null && ar.result != null) {
1538 request.result = ar.result;
1539 //update the cache as modem status has changed
1540 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1541 (boolean) request.result);
1542 } else {
1543 // Return true if modem status cannot be retrieved. For most cases,
1544 // modem status is on. And for older version modems, GET_MODEM_STATUS
1545 // and disable modem are not supported. Modem is always on.
1546 // TODO: this should be fixed in R to support a third
1547 // status UNKNOWN b/131631629
1548 request.result = true;
1549 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1550 + ar.exception);
1551 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001552 notifyRequester(request);
1553 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001554 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1555 request = (MainThreadRequest) msg.obj;
1556 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1557 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1558 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1559 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1560 break;
1561 }
1562 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1563 ar = (AsyncResult) msg.obj;
1564 request = (MainThreadRequest) ar.userObj;
1565 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1566 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1567 args.second.accept(ar.exception == null);
1568 notifyRequester(request);
1569 break;
1570 }
Sarah Chincc055732020-11-18 13:39:35 -08001571 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1572 request = (MainThreadRequest) msg.obj;
1573 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1574 Phone phone = getPhoneFromRequest(request);
1575 if (phone != null) {
1576 phone.getSystemSelectionChannels(onCompleted);
1577 } else {
1578 loge("getSystemSelectionChannels: No phone object");
1579 request.result = new ArrayList<RadioAccessSpecifier>();
1580 notifyRequester(request);
1581 }
1582 break;
1583 }
1584 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1585 ar = (AsyncResult) msg.obj;
1586 request = (MainThreadRequest) ar.userObj;
1587 if (ar.exception == null && ar.result != null) {
1588 request.result = ar.result;
1589 } else {
1590 request.result = new IllegalArgumentException(
1591 "Failed to retrieve system selection channels");
1592 if (ar.result == null) {
1593 loge("getSystemSelectionChannels: Empty response");
1594 } else {
1595 loge("getSystemSelectionChannels: Unknown exception");
1596 }
1597 }
1598 notifyRequester(request);
1599 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001600 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1601 ar = (AsyncResult) msg.obj;
1602 request = (MainThreadRequest) ar.userObj;
1603 if (ar.exception == null && ar.result != null) {
1604 request.result = ar.result;
1605 } else {
1606 request.result = -1;
1607 loge("Failed to set Forbidden Plmns");
1608 if (ar.result == null) {
1609 loge("setForbidenPlmns: Empty response");
1610 } else if (ar.exception != null) {
1611 loge("setForbiddenPlmns: Exception: " + ar.exception);
1612 request.result = -1;
1613 } else {
1614 loge("setForbiddenPlmns: Unknown exception");
1615 }
1616 }
1617 notifyRequester(request);
1618 break;
1619 case CMD_SET_FORBIDDEN_PLMNS:
1620 request = (MainThreadRequest) msg.obj;
1621 uiccCard = getUiccCardFromRequest(request);
1622 if (uiccCard == null) {
1623 loge("setForbiddenPlmns: UiccCard is null");
1624 request.result = -1;
1625 notifyRequester(request);
1626 break;
1627 }
1628 Pair<Integer, List<String>> setFplmnsArgs =
1629 (Pair<Integer, List<String>>) request.argument;
1630 appType = setFplmnsArgs.first;
1631 List<String> fplmns = setFplmnsArgs.second;
1632 uiccApp = uiccCard.getApplicationByType(appType);
1633 if (uiccApp == null) {
1634 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1635 request.result = -1;
1636 loge("Failed to get UICC App");
1637 notifyRequester(request);
1638 } else {
1639 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1640 ((SIMRecords) uiccApp.getIccRecords())
1641 .setForbiddenPlmns(onCompleted, fplmns);
1642 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001643 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001644 case CMD_ERASE_MODEM_CONFIG:
1645 request = (MainThreadRequest) msg.obj;
1646 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1647 defaultPhone.eraseModemConfig(onCompleted);
1648 break;
1649 case EVENT_ERASE_MODEM_CONFIG_DONE:
1650 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001651 break;
zoey chenf95ca592019-12-30 16:11:23 +08001652
1653 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1654 request = (MainThreadRequest) msg.obj;
1655 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1656 Pair<String, String> changed = (Pair<String, String>) request.argument;
1657 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1658 changed.first, changed.second, onCompleted);
1659 break;
1660 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1661 ar = (AsyncResult) msg.obj;
1662 request = (MainThreadRequest) ar.userObj;
1663 if (ar.exception == null) {
1664 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1665 } else {
1666 request.result = msg.arg1;
1667 }
1668 notifyRequester(request);
1669 break;
1670
1671 case CMD_SET_ICC_LOCK_ENABLED:
1672 request = (MainThreadRequest) msg.obj;
1673 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1674 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1675 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1676 enabled.first, enabled.second, onCompleted);
1677 break;
1678 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1679 ar = (AsyncResult) msg.obj;
1680 request = (MainThreadRequest) ar.userObj;
1681 if (ar.exception == null) {
1682 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1683 } else {
1684 request.result = msg.arg1;
1685 }
1686 notifyRequester(request);
1687 break;
1688
Peter Wangdafb9ac2020-01-15 14:13:38 -08001689 case MSG_NOTIFY_USER_ACTIVITY:
1690 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001691 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001692 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1693 getDefaultPhone().getContext().sendBroadcastAsUser(
1694 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1695 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001696
1697 case CMD_SET_DATA_THROTTLING: {
1698 request = (MainThreadRequest) msg.obj;
1699 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1700 DataThrottlingRequest dataThrottlingRequest =
1701 (DataThrottlingRequest) request.argument;
1702 Phone phone = getPhoneFromRequest(request);
1703 if (phone != null) {
1704 phone.setDataThrottling(onCompleted,
1705 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1706 dataThrottlingRequest.getCompletionDurationMillis());
1707 } else {
1708 loge("setDataThrottling: No phone object");
1709 request.result =
1710 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1711 notifyRequester(request);
1712 }
1713
1714 break;
1715 }
1716 case EVENT_SET_DATA_THROTTLING_DONE:
1717 ar = (AsyncResult) msg.obj;
1718 request = (MainThreadRequest) ar.userObj;
1719
1720 if (ar.exception == null) {
1721 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1722 } else if (ar.exception instanceof CommandException) {
1723 loge("setDataThrottling: CommandException: " + ar.exception);
1724 CommandException.Error error =
1725 ((CommandException) (ar.exception)).getCommandError();
1726
1727 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1728 request.result = TelephonyManager
1729 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1730 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1731 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1732 } else {
1733 request.result =
1734 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1735 }
1736 } else {
1737 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1738 }
1739 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1740 notifyRequester(request);
1741 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742 default:
1743 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1744 break;
1745 }
1746 }
Jake Hambye994d462014-02-03 13:10:13 -08001747
Pengquan Menga1bb6272018-09-06 09:59:22 -07001748 private void notifyRequester(MainThreadRequest request) {
1749 synchronized (request) {
1750 request.notifyAll();
1751 }
1752 }
1753
Jake Hambye994d462014-02-03 13:10:13 -08001754 private void handleNullReturnEvent(Message msg, String command) {
1755 AsyncResult ar = (AsyncResult) msg.obj;
1756 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1757 if (ar.exception == null) {
1758 request.result = true;
1759 } else {
1760 request.result = false;
1761 if (ar.exception instanceof CommandException) {
1762 loge(command + ": CommandException: " + ar.exception);
1763 } else {
1764 loge(command + ": Unknown exception");
1765 }
1766 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001767 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 }
1770
1771 /**
1772 * Posts the specified command to be executed on the main thread,
1773 * waits for the request to complete, and returns the result.
1774 * @see #sendRequestAsync
1775 */
1776 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001777 return sendRequest(
1778 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001779 }
1780
1781 /**
1782 * Posts the specified command to be executed on the main thread,
1783 * waits for the request to complete, and returns the result.
1784 * @see #sendRequestAsync
1785 */
1786 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1787 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001788 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001789 }
1790
1791 /**
1792 * Posts the specified command to be executed on the main thread,
1793 * waits for the request to complete, and returns the result.
1794 * @see #sendRequestAsync
1795 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001796 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001797 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001798 }
1799
1800 /**
1801 * Posts the specified command to be executed on the main thread,
1802 * waits for the request to complete, and returns the result.
1803 * @see #sendRequestAsync
1804 */
Nathan Harold92bed182018-10-12 18:16:49 -07001805 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1806 return sendRequest(command, argument, subId, null, workSource);
1807 }
1808
1809 /**
1810 * Posts the specified command to be executed on the main thread,
1811 * waits for the request to complete, and returns the result.
1812 * @see #sendRequestAsync
1813 */
1814 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1815 return sendRequest(
1816 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1817 }
1818
1819 /**
1820 * Posts the specified command to be executed on the main thread,
1821 * waits for the request to complete, and returns the result.
1822 * @see #sendRequestAsync
1823 */
1824 private Object sendRequest(
1825 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1827 throw new RuntimeException("This method will deadlock if called from the main thread.");
1828 }
1829
Nathan Harold92bed182018-10-12 18:16:49 -07001830 MainThreadRequest request = null;
1831 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1832 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1833 } else if (phone != null) {
1834 request = new MainThreadRequest(argument, phone, workSource);
1835 } else {
1836 request = new MainThreadRequest(argument, subId, workSource);
1837 }
1838
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001839 Message msg = mMainThreadHandler.obtainMessage(command, request);
1840 msg.sendToTarget();
1841
1842 // Wait for the request to complete
1843 synchronized (request) {
1844 while (request.result == null) {
1845 try {
1846 request.wait();
1847 } catch (InterruptedException e) {
1848 // Do nothing, go back and wait until the request is complete
1849 }
1850 }
1851 }
1852 return request.result;
1853 }
1854
1855 /**
1856 * Asynchronous ("fire and forget") version of sendRequest():
1857 * Posts the specified command to be executed on the main thread, and
1858 * returns immediately.
1859 * @see #sendRequest
1860 */
1861 private void sendRequestAsync(int command) {
1862 mMainThreadHandler.sendEmptyMessage(command);
1863 }
1864
1865 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001866 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001867 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001868 */
1869 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001870 sendRequestAsync(command, argument, null, null);
1871 }
1872
1873 /**
1874 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1875 * @see {@link #sendRequest(int,Object)}
1876 */
1877 private void sendRequestAsync(
1878 int command, Object argument, Phone phone, WorkSource workSource) {
1879 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001880 Message msg = mMainThreadHandler.obtainMessage(command, request);
1881 msg.sendToTarget();
1882 }
1883
1884 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 * Initialize the singleton PhoneInterfaceManager instance.
1886 * This is only done once, at startup, from PhoneApp.onCreate().
1887 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001888 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 synchronized (PhoneInterfaceManager.class) {
1890 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001891 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 } else {
1893 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1894 }
1895 return sInstance;
1896 }
1897 }
1898
1899 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001900 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001901 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001903 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001904 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1906 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001907 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001908 mTelephonySharedPreferences =
1909 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001910 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001911 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001912 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001913
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001914 publish();
1915 }
1916
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001917 private Phone getDefaultPhone() {
1918 Phone thePhone = getPhone(getDefaultSubscription());
1919 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1920 }
1921
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001922 private void publish() {
1923 if (DBG) log("publish: " + this);
1924
Peter Wangc035ce42020-01-08 21:00:22 -08001925 TelephonyFrameworkInitializer
1926 .getTelephonyServiceManager()
1927 .getTelephonyServiceRegisterer()
1928 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 }
1930
Stuart Scott584921c2015-01-15 17:10:34 -08001931 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001932 if (request.phone != null) {
1933 return request.phone;
1934 } else {
1935 return getPhoneFromSubId(request.subId);
1936 }
1937 }
1938
1939 private Phone getPhoneFromSubId(int subId) {
1940 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1941 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001942 }
1943
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001944 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1945 Phone phone = getPhoneFromRequest(request);
1946 return phone == null ? null :
1947 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1948 }
1949
Wink Saville36469e72014-06-11 15:17:00 -07001950 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001951 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001952 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001953 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001955 private void sendEraseModemConfig(Phone phone) {
1956 if (phone != null) {
1957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1958 mApp, phone.getSubId(), "eraseModemConfig");
1959 final long identity = Binder.clearCallingIdentity();
1960 try {
1961 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1962 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1963 } finally {
1964 Binder.restoreCallingIdentity(identity);
1965 }
1966 }
1967 }
1968
Peter Wang050bb052020-01-13 23:33:09 -08001969 private boolean isImsAvailableOnDevice() {
1970 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1971 if (pm == null) {
1972 // For some reason package manger is not available.. This will fail internally anyway,
1973 // so do not throw error and allow.
1974 return true;
1975 }
1976 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1977 }
1978
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001979 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001980 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001981 }
1982
Wink Savilleb564aae2014-10-23 10:18:09 -07001983 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 if (DBG) log("dial: " + number);
1985 // No permission check needed here: This is just a wrapper around the
1986 // ACTION_DIAL intent, which is available to any app since it puts up
1987 // the UI before it does anything.
1988
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001989 final long identity = Binder.clearCallingIdentity();
1990 try {
1991 String url = createTelUrl(number);
1992 if (url == null) {
1993 return;
1994 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001996 // PENDING: should we just silently fail if phone is offhook or ringing?
1997 PhoneConstants.State state = mCM.getState(subId);
1998 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1999 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2000 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2001 mApp.startActivity(intent);
2002 }
2003 } finally {
2004 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002005 }
2006 }
2007
2008 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002009 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002010 }
2011
Wink Savilleb564aae2014-10-23 10:18:09 -07002012 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002013 if (DBG) log("call: " + number);
2014
2015 // This is just a wrapper around the ACTION_CALL intent, but we still
2016 // need to do a permission check since we're calling startActivity()
2017 // from the context of the phone app.
2018 enforceCallPermission();
2019
Jordan Liu1617b712019-07-10 15:06:26 -07002020 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002021 != AppOpsManager.MODE_ALLOWED) {
2022 return;
2023 }
2024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002025 final long identity = Binder.clearCallingIdentity();
2026 try {
2027 String url = createTelUrl(number);
2028 if (url == null) {
2029 return;
2030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002032 boolean isValid = false;
2033 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2034 if (slist != null) {
2035 for (SubscriptionInfo subInfoRecord : slist) {
2036 if (subInfoRecord.getSubscriptionId() == subId) {
2037 isValid = true;
2038 break;
2039 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002040 }
Wink Saville08874612014-08-31 19:19:58 -07002041 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002042 if (!isValid) {
2043 return;
2044 }
Wink Saville08874612014-08-31 19:19:58 -07002045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002046 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2047 intent.putExtra(SUBSCRIPTION_KEY, subId);
2048 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2049 mApp.startActivity(intent);
2050 } finally {
2051 Binder.restoreCallingIdentity(identity);
2052 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 }
2054
Wink Savilleb564aae2014-10-23 10:18:09 -07002055 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002056 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002057 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2058 }
2059
Wink Savilleb564aae2014-10-23 10:18:09 -07002060 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002061 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002062 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2063 }
2064
Wink Savilleb564aae2014-10-23 10:18:09 -07002065 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002067
2068 final long identity = Binder.clearCallingIdentity();
2069 try {
2070 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2071 checkSimPin.start();
2072 return checkSimPin.unlockSim(null, pin);
2073 } finally {
2074 Binder.restoreCallingIdentity(identity);
2075 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002076 }
2077
Wink Savilleb564aae2014-10-23 10:18:09 -07002078 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002080
2081 final long identity = Binder.clearCallingIdentity();
2082 try {
2083 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2084 checkSimPuk.start();
2085 return checkSimPuk.unlockSim(puk, pin);
2086 } finally {
2087 Binder.restoreCallingIdentity(identity);
2088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 }
2090
2091 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002092 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 * a synchronous one.
2094 */
2095 private static class UnlockSim extends Thread {
2096
2097 private final IccCard mSimCard;
2098
2099 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002100 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2101 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002102
2103 // For replies from SimCard interface
2104 private Handler mHandler;
2105
2106 // For async handler to identify request type
2107 private static final int SUPPLY_PIN_COMPLETE = 100;
2108
2109 public UnlockSim(IccCard simCard) {
2110 mSimCard = simCard;
2111 }
2112
2113 @Override
2114 public void run() {
2115 Looper.prepare();
2116 synchronized (UnlockSim.this) {
2117 mHandler = new Handler() {
2118 @Override
2119 public void handleMessage(Message msg) {
2120 AsyncResult ar = (AsyncResult) msg.obj;
2121 switch (msg.what) {
2122 case SUPPLY_PIN_COMPLETE:
2123 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2124 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002125 mRetryCount = msg.arg1;
2126 if (ar.exception != null) {
2127 if (ar.exception instanceof CommandException &&
2128 ((CommandException)(ar.exception)).getCommandError()
2129 == CommandException.Error.PASSWORD_INCORRECT) {
2130 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002131 } //When UiccCardApp dispose,handle message and return exception
2132 else if (ar.exception instanceof CommandException &&
2133 ((CommandException) (ar.exception)).getCommandError()
2134 == CommandException.Error.ABORTED) {
2135 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002136 } else {
2137 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2138 }
2139 } else {
2140 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2141 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002142 mDone = true;
2143 UnlockSim.this.notifyAll();
2144 }
2145 break;
2146 }
2147 }
2148 };
2149 UnlockSim.this.notifyAll();
2150 }
2151 Looper.loop();
2152 }
2153
2154 /*
2155 * Use PIN or PUK to unlock SIM card
2156 *
2157 * If PUK is null, unlock SIM card with PIN
2158 *
2159 * If PUK is not null, unlock SIM card with PUK and set PIN code
2160 */
Wink Saville9de0f752013-10-22 19:04:03 -07002161 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162
2163 while (mHandler == null) {
2164 try {
2165 wait();
2166 } catch (InterruptedException e) {
2167 Thread.currentThread().interrupt();
2168 }
2169 }
2170 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2171
2172 if (puk == null) {
2173 mSimCard.supplyPin(pin, callback);
2174 } else {
2175 mSimCard.supplyPuk(puk, pin, callback);
2176 }
2177
2178 while (!mDone) {
2179 try {
2180 Log.d(LOG_TAG, "wait for done");
2181 wait();
2182 } catch (InterruptedException e) {
2183 // Restore the interrupted status
2184 Thread.currentThread().interrupt();
2185 }
2186 }
2187 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002188 int[] resultArray = new int[2];
2189 resultArray[0] = mResult;
2190 resultArray[1] = mRetryCount;
2191 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 }
2193 }
2194
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002195 /**
2196 * This method has been removed due to privacy and stability concerns.
2197 */
2198 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002200 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2201 return;
Wink Saville36469e72014-06-11 15:17:00 -07002202 }
2203
Nathan Harold1f889d82020-06-04 17:05:26 -07002204 @Override
2205 public void updateServiceLocationWithPackageName(String callingPackage) {
2206 mApp.getSystemService(AppOpsManager.class)
2207 .checkPackage(Binder.getCallingUid(), callingPackage);
2208
2209 final int targetSdk = getTargetSdk(callingPackage);
2210 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2211 // Callers targeting S have no business invoking this method.
2212 return;
2213 }
2214
2215 LocationAccessPolicy.LocationPermissionResult locationResult =
2216 LocationAccessPolicy.checkLocationPermission(mApp,
2217 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2218 .setCallingPackage(callingPackage)
2219 .setCallingFeatureId(null)
2220 .setCallingPid(Binder.getCallingPid())
2221 .setCallingUid(Binder.getCallingUid())
2222 .setMethod("updateServiceLocation")
2223 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2224 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2225 .build());
2226 // Apps that lack location permission have no business calling this method;
2227 // however, because no permission was declared in the public API, denials must
2228 // all be "soft".
2229 switch (locationResult) {
2230 case DENIED_HARD: /* fall through */
2231 case DENIED_SOFT:
2232 return;
2233 }
2234
2235 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002236 final long identity = Binder.clearCallingIdentity();
2237 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002238 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002239 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002240 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002241 }
2242 } finally {
2243 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 }
2246
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002247 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002248 @Override
2249 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002250 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002251 }
2252
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002253
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002254 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002255 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2256 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2257 callingFeatureId);
2258 }
2259
2260 @Deprecated
2261 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002262 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002263 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2264 }
2265
2266 @Override
2267 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2268 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002269 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002270 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002271 return false;
2272 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002273
2274 final long identity = Binder.clearCallingIdentity();
2275 try {
2276 return isRadioOnForSubscriber(subId);
2277 } finally {
2278 Binder.restoreCallingIdentity(identity);
2279 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002280 }
2281
2282 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002283 final long identity = Binder.clearCallingIdentity();
2284 try {
2285 final Phone phone = getPhone(subId);
2286 if (phone != null) {
2287 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2288 } else {
2289 return false;
2290 }
2291 } finally {
2292 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 }
2295
2296 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002297 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 }
Wink Saville36469e72014-06-11 15:17:00 -07002299
Wink Savilleb564aae2014-10-23 10:18:09 -07002300 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002302
2303 final long identity = Binder.clearCallingIdentity();
2304 try {
2305 final Phone phone = getPhone(subId);
2306 if (phone != null) {
2307 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2308 }
2309 } finally {
2310 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002311 }
Wink Saville36469e72014-06-11 15:17:00 -07002312 }
2313
2314 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002315 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002316 }
2317
Wink Savilleb564aae2014-10-23 10:18:09 -07002318 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002319 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002320
2321 final long identity = Binder.clearCallingIdentity();
2322 try {
2323 final Phone phone = getPhone(subId);
2324 if (phone == null) {
2325 return false;
2326 }
2327 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2328 toggleRadioOnOffForSubscriber(subId);
2329 }
2330 return true;
2331 } finally {
2332 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 }
Wink Saville36469e72014-06-11 15:17:00 -07002335
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002336 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002337 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002338 /*
2339 * If any of the Radios are available, it will need to be
2340 * shutdown. So return true if any Radio is available.
2341 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002342 final long identity = Binder.clearCallingIdentity();
2343 try {
2344 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2345 Phone phone = PhoneFactory.getPhone(i);
2346 if (phone != null && phone.isRadioAvailable()) return true;
2347 }
2348 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2349 return false;
2350 } finally {
2351 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002352 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002353 }
2354
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002355 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002356 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002357 enforceModifyPermission();
2358
2359 final long identity = Binder.clearCallingIdentity();
2360 try {
2361 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2362 logv("Shutting down Phone " + i);
2363 shutdownRadioUsingPhoneId(i);
2364 }
2365 } finally {
2366 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002367 }
2368 }
2369
2370 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002371 Phone phone = PhoneFactory.getPhone(phoneId);
2372 if (phone != null && phone.isRadioAvailable()) {
2373 phone.shutdownRadio();
2374 }
2375 }
2376
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002378 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002379
2380 final long identity = Binder.clearCallingIdentity();
2381 try {
2382 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2383 if (defaultPhone != null) {
2384 defaultPhone.setRadioPower(turnOn);
2385 return true;
2386 } else {
2387 loge("There's no default phone.");
2388 return false;
2389 }
2390 } finally {
2391 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002392 }
Wink Saville36469e72014-06-11 15:17:00 -07002393 }
2394
Wink Savilleb564aae2014-10-23 10:18:09 -07002395 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002397
2398 final long identity = Binder.clearCallingIdentity();
2399 try {
2400 final Phone phone = getPhone(subId);
2401 if (phone != null) {
2402 phone.setRadioPower(turnOn);
2403 return true;
2404 } else {
2405 return false;
2406 }
2407 } finally {
2408 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002409 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 }
2411
Wink Saville36469e72014-06-11 15:17:00 -07002412 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002413 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002414 public boolean enableDataConnectivity() {
2415 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002416
2417 final long identity = Binder.clearCallingIdentity();
2418 try {
2419 int subId = mSubscriptionController.getDefaultDataSubId();
2420 final Phone phone = getPhone(subId);
2421 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002422 phone.getDataEnabledSettings().setDataEnabled(
2423 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002424 return true;
2425 } else {
2426 return false;
2427 }
2428 } finally {
2429 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 }
2432
Wink Saville36469e72014-06-11 15:17:00 -07002433 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002434 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 public boolean disableDataConnectivity() {
2436 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002437
2438 final long identity = Binder.clearCallingIdentity();
2439 try {
2440 int subId = mSubscriptionController.getDefaultDataSubId();
2441 final Phone phone = getPhone(subId);
2442 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002443 phone.getDataEnabledSettings().setDataEnabled(
2444 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002445 return true;
2446 } else {
2447 return false;
2448 }
2449 } finally {
2450 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002451 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 }
2453
Sanket Padawe356d7632015-06-22 14:03:32 -07002454 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002455 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002456 final long identity = Binder.clearCallingIdentity();
2457 try {
2458 final Phone phone = getPhone(subId);
2459 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002460 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002461 } else {
2462 return false;
2463 }
2464 } finally {
2465 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002466 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 }
2468
2469 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002470 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002471 }
2472
pkanwarae03a6b2016-11-06 20:37:09 -08002473 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002474 enforceCallPermission();
2475
2476 final long identity = Binder.clearCallingIdentity();
2477 try {
2478 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2479 return;
2480 }
2481 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2482 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2483 } finally {
2484 Binder.restoreCallingIdentity(identity);
2485 }
pkanwar32d516d2016-10-14 19:37:38 -07002486 };
2487
Wink Savilleb564aae2014-10-23 10:18:09 -07002488 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002490
2491 final long identity = Binder.clearCallingIdentity();
2492 try {
2493 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2494 return false;
2495 }
2496 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2497 } finally {
2498 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 }
2501
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002502 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002503 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002504 }
2505
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002506 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507 final long identity = Binder.clearCallingIdentity();
2508 try {
2509 Phone phone = PhoneFactory.getPhone(slotIndex);
2510 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2511 PhoneConstantConversions.convertCallState(phone.getState());
2512 } finally {
2513 Binder.restoreCallingIdentity(identity);
2514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 }
2516
Sanket Padawe356d7632015-06-22 14:03:32 -07002517 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002518 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002519 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2520 }
2521
2522 @Override
2523 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002524 final long identity = Binder.clearCallingIdentity();
2525 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002526 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002527 if (phone != null) {
2528 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2529 } else {
2530 return PhoneConstantConversions.convertDataState(
2531 PhoneConstants.DataState.DISCONNECTED);
2532 }
2533 } finally {
2534 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002536 }
2537
Sanket Padawe356d7632015-06-22 14:03:32 -07002538 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002539 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002540 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2541 }
2542
2543 @Override
2544 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002545 final long identity = Binder.clearCallingIdentity();
2546 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002547 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002548 if (phone != null) {
2549 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2550 } else {
2551 return TelephonyManager.DATA_ACTIVITY_NONE;
2552 }
2553 } finally {
2554 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002556 }
2557
2558 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002559 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002560 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002561 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002562
2563 LocationAccessPolicy.LocationPermissionResult locationResult =
2564 LocationAccessPolicy.checkLocationPermission(mApp,
2565 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2566 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002567 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002568 .setCallingPid(Binder.getCallingPid())
2569 .setCallingUid(Binder.getCallingUid())
2570 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002571 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002572 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2573 .build());
2574 switch (locationResult) {
2575 case DENIED_HARD:
2576 throw new SecurityException("Not allowed to access cell location");
2577 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002578 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2579 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002580 }
2581
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002582 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002583 final long identity = Binder.clearCallingIdentity();
2584 try {
2585 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002586 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002587 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002588 } finally {
2589 Binder.restoreCallingIdentity(identity);
2590 }
Svetoslav64fad262015-04-14 14:35:21 -07002591 }
2592
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002593 @Override
Jack Yu01425032020-02-22 19:38:58 -08002594 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002595 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2596 // registered cell info, so return a NULL country instead.
2597 final long identity = Binder.clearCallingIdentity();
2598 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002599 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2600 // Get default phone in this case.
2601 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2602 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002603 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002605 if (phone == null) return "";
2606 ServiceStateTracker sst = phone.getServiceStateTracker();
2607 if (sst == null) return "";
2608 LocaleTracker lt = sst.getLocaleTracker();
2609 if (lt == null) return "";
2610 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2611 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2612 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002613 } finally {
2614 Binder.restoreCallingIdentity(identity);
2615 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002616 }
2617
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002618 /**
2619 * This method was removed due to potential issues caused by performing partial
2620 * updates of service state, and lack of a credible use case.
2621 *
2622 * This has the ability to break the telephony implementation by disabling notification of
2623 * changes in device connectivity. DO NOT USE THIS!
2624 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002625 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002626 public void enableLocationUpdates() {
2627 mApp.enforceCallingOrSelfPermission(
2628 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002629 }
2630
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002631 /**
2632 * This method was removed due to potential issues caused by performing partial
2633 * updates of service state, and lack of a credible use case.
2634 *
2635 * This has the ability to break the telephony implementation by disabling notification of
2636 * changes in device connectivity. DO NOT USE THIS!
2637 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002638 @Override
2639 public void disableLocationUpdates() {
2640 mApp.enforceCallingOrSelfPermission(
2641 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002642 }
2643
Nathan Harold31d7ff32018-10-15 20:20:30 -07002644 /**
2645 * Returns the target SDK version number for a given package name.
2646 *
Nathan Haroldec184742019-07-10 17:04:16 -07002647 * This call MUST be invoked before clearing the calling UID.
2648 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002649 * @return target SDK if the package is found or INT_MAX.
2650 */
2651 private int getTargetSdk(String packageName) {
2652 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002653 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002654 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002655 if (ai != null) return ai.targetSdkVersion;
2656 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002657 loge("Failed to get package info for pkg="
2658 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002659 }
2660 return Integer.MAX_VALUE;
2661 }
2662
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002663 @Override
2664 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002665 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2666 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002667 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002668 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2669 throw new SecurityException(
2670 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2671 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002672
Jordan Liu1617b712019-07-10 15:06:26 -07002673 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2675 return null;
2676 }
Svetoslav64fad262015-04-14 14:35:21 -07002677
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002678 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002679
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002680 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002681 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682
Nathan Haroldf180aac2018-06-01 18:43:55 -07002683 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2684 for (CellInfo ci : info) {
2685 if (ci instanceof CellInfoGsm) {
2686 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2687 } else if (ci instanceof CellInfoWcdma) {
2688 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002690 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002691 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 }
2693
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002694 private List<CellInfo> getCachedCellInfo() {
2695 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2696 for (Phone phone : PhoneFactory.getPhones()) {
2697 List<CellInfo> info = phone.getAllCellInfo();
2698 if (info != null) cellInfos.addAll(info);
2699 }
2700 return cellInfos;
2701 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002702
2703 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002704 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002705 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002706 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002707
2708 LocationAccessPolicy.LocationPermissionResult locationResult =
2709 LocationAccessPolicy.checkLocationPermission(mApp,
2710 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2711 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002712 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002713 .setCallingPid(Binder.getCallingPid())
2714 .setCallingUid(Binder.getCallingUid())
2715 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002716 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002717 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2718 .build());
2719 switch (locationResult) {
2720 case DENIED_HARD:
2721 throw new SecurityException("Not allowed to access cell info");
2722 case DENIED_SOFT:
2723 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724 }
2725
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002726 final int targetSdk = getTargetSdk(callingPackage);
2727 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2728 return getCachedCellInfo();
2729 }
2730
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002731 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002732 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002733 final long identity = Binder.clearCallingIdentity();
2734 try {
2735 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2736 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002737 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002738 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 if (info != null) cellInfos.addAll(info);
2740 }
2741 return cellInfos;
2742 } finally {
2743 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002744 }
2745 }
2746
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002747 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002748 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2749 String callingFeatureId) {
2750 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2751 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002752 }
2753
2754 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002755 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2756 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002757 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002758 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002759 }
2760
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002761 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2762 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002763 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002764 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002765
2766 LocationAccessPolicy.LocationPermissionResult locationResult =
2767 LocationAccessPolicy.checkLocationPermission(mApp,
2768 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2769 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002770 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002771 .setCallingPid(Binder.getCallingPid())
2772 .setCallingUid(Binder.getCallingUid())
2773 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002774 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2775 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002776 .build());
2777 switch (locationResult) {
2778 case DENIED_HARD:
Hall Liuaa4283b2020-05-21 17:09:35 -07002779 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2780 // Safetynet logging for b/154934934
2781 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2782 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002783 throw new SecurityException("Not allowed to access cell info");
2784 case DENIED_SOFT:
Hall Liuaa4283b2020-05-21 17:09:35 -07002785 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2786 // Safetynet logging for b/154934934
2787 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2788 }
Nathan Harold5320c422019-05-09 10:26:08 -07002789 try {
2790 cb.onCellInfo(new ArrayList<CellInfo>());
2791 } catch (RemoteException re) {
2792 // Drop without consequences
2793 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002794 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002795 }
2796
Nathan Harolda939a962019-05-09 10:13:47 -07002797
2798 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002799 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2800
2801 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2802 }
2803
2804 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002805 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002806 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002807 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002808
2809 final long identity = Binder.clearCallingIdentity();
2810 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002811 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002812 } finally {
2813 Binder.restoreCallingIdentity(identity);
2814 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002815 }
2816
Shishir Agrawala9f32182016-04-12 12:00:16 -07002817 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002818 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002819 Phone phone = PhoneFactory.getPhone(slotIndex);
2820 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002821 return null;
2822 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002823 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002824 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002825 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002826 return null;
2827 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828
2829 final long identity = Binder.clearCallingIdentity();
2830 try {
2831 return phone.getImei();
2832 } finally {
2833 Binder.restoreCallingIdentity(identity);
2834 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002835 }
2836
2837 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002838 public String getTypeAllocationCodeForSlot(int slotIndex) {
2839 Phone phone = PhoneFactory.getPhone(slotIndex);
2840 String tac = null;
2841 if (phone != null) {
2842 String imei = phone.getImei();
2843 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2844 }
2845 return tac;
2846 }
2847
2848 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002849 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002850 Phone phone = PhoneFactory.getPhone(slotIndex);
2851 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002852 return null;
2853 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002854
Jeff Davidson913390f2018-02-23 17:11:49 -08002855 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002856 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002857 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002858 return null;
2859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002860
2861 final long identity = Binder.clearCallingIdentity();
2862 try {
2863 return phone.getMeid();
2864 } finally {
2865 Binder.restoreCallingIdentity(identity);
2866 }
Jack Yu2af8d712017-03-15 17:14:14 -07002867 }
2868
2869 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002870 public String getManufacturerCodeForSlot(int slotIndex) {
2871 Phone phone = PhoneFactory.getPhone(slotIndex);
2872 String manufacturerCode = null;
2873 if (phone != null) {
2874 String meid = phone.getMeid();
2875 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2876 }
2877 return manufacturerCode;
2878 }
2879
2880 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002881 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2882 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002883 Phone phone = PhoneFactory.getPhone(slotIndex);
2884 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002885 return null;
2886 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002887 int subId = phone.getSubId();
2888 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002889 mApp, subId, callingPackage, callingFeatureId,
2890 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002891 return null;
2892 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002893
2894 final long identity = Binder.clearCallingIdentity();
2895 try {
2896 return phone.getDeviceSvn();
2897 } finally {
2898 Binder.restoreCallingIdentity(identity);
2899 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002900 }
2901
fionaxu43304da2017-11-27 22:51:16 -08002902 @Override
2903 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002904 final long identity = Binder.clearCallingIdentity();
2905 try {
2906 final Phone phone = getPhone(subId);
2907 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2908 } finally {
2909 Binder.restoreCallingIdentity(identity);
2910 }
fionaxu43304da2017-11-27 22:51:16 -08002911 }
2912
2913 @Override
2914 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002915 final long identity = Binder.clearCallingIdentity();
2916 try {
2917 final Phone phone = getPhone(subId);
2918 return phone == null ? null : phone.getCarrierName();
2919 } finally {
2920 Binder.restoreCallingIdentity(identity);
2921 }
fionaxu43304da2017-11-27 22:51:16 -08002922 }
2923
calvinpanffe225e2018-11-01 19:43:06 +08002924 @Override
chen xu0026ca62019-03-06 15:28:50 -08002925 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002926 final long identity = Binder.clearCallingIdentity();
2927 try {
2928 final Phone phone = getPhone(subId);
2929 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002930 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002931 } finally {
2932 Binder.restoreCallingIdentity(identity);
2933 }
2934 }
2935
2936 @Override
chen xu0026ca62019-03-06 15:28:50 -08002937 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002938 final long identity = Binder.clearCallingIdentity();
2939 try {
2940 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002941 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002942 } finally {
2943 Binder.restoreCallingIdentity(identity);
2944 }
2945 }
2946
chen xu651eec72018-11-11 19:03:44 -08002947 @Override
chen xu864e11c2018-12-06 22:10:03 -08002948 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2949 if (!isSubscriptionMccMnc) {
2950 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2951 }
chen xu651eec72018-11-11 19:03:44 -08002952 final Phone phone = PhoneFactory.getPhone(slotIndex);
2953 if (phone == null) {
2954 return TelephonyManager.UNKNOWN_CARRIER_ID;
2955 }
2956 final long identity = Binder.clearCallingIdentity();
2957 try {
2958 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2959 } finally {
2960 Binder.restoreCallingIdentity(identity);
2961 }
2962 }
2963
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002964 //
2965 // Internal helper methods.
2966 //
2967
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002968 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002969 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2970 *
2971 * @throws SecurityException if the caller does not have the required permission
2972 */
2973 private void enforceModifyPermission() {
2974 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2975 }
2976
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002977 /**
2978 * Make sure the caller is system.
2979 *
2980 * @throws SecurityException if the caller is not system.
2981 */
2982 private void enforceSystemCaller() {
2983 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2984 throw new SecurityException("Caller must be system");
2985 }
2986 }
2987
Shuo Qianf2b2df42019-11-13 17:43:31 -08002988 private void enforceActiveEmergencySessionPermission() {
2989 mApp.enforceCallingOrSelfPermission(
2990 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2991 }
2992
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002993 /**
2994 * Make sure the caller has the CALL_PHONE permission.
2995 *
2996 * @throws SecurityException if the caller does not have the required permission
2997 */
2998 private void enforceCallPermission() {
2999 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3000 }
3001
paulhu423b5f22019-08-23 19:17:33 +08003002 private void enforceSettingsPermission() {
3003 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003004 }
3005
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003006 private String createTelUrl(String number) {
3007 if (TextUtils.isEmpty(number)) {
3008 return null;
3009 }
3010
Jake Hambye994d462014-02-03 13:10:13 -08003011 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003012 }
3013
Ihab Awadf9e92732013-12-05 18:02:52 -08003014 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003015 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3016 }
3017
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003018 private static void logv(String msg) {
3019 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3020 }
3021
Ihab Awadf9e92732013-12-05 18:02:52 -08003022 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003023 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3024 }
3025
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003026 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003027 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003028 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003029 }
3030
Sanket Padawe356d7632015-06-22 14:03:32 -07003031 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003032 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003033 final long identity = Binder.clearCallingIdentity();
3034 try {
3035 final Phone phone = PhoneFactory.getPhone(slotIndex);
3036 if (phone == null) {
3037 return PhoneConstants.PHONE_TYPE_NONE;
3038 } else {
3039 return phone.getPhoneType();
3040 }
3041 } finally {
3042 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003043 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003044 }
3045
3046 /**
3047 * Returns the CDMA ERI icon index to display
3048 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003049 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003050 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3051 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3052 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003053 }
3054
Sanket Padawe356d7632015-06-22 14:03:32 -07003055 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003056 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3057 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003058 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003059 mApp, subId, callingPackage, callingFeatureId,
3060 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003061 return -1;
3062 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003063
3064 final long identity = Binder.clearCallingIdentity();
3065 try {
3066 final Phone phone = getPhone(subId);
3067 if (phone != null) {
3068 return phone.getCdmaEriIconIndex();
3069 } else {
3070 return -1;
3071 }
3072 } finally {
3073 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003074 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003075 }
3076
3077 /**
3078 * Returns the CDMA ERI icon mode,
3079 * 0 - ON
3080 * 1 - FLASHING
3081 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003082 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003083 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3084 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3085 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003086 }
3087
Sanket Padawe356d7632015-06-22 14:03:32 -07003088 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003089 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3090 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003091 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003092 mApp, subId, callingPackage, callingFeatureId,
3093 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003094 return -1;
3095 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003096
3097 final long identity = Binder.clearCallingIdentity();
3098 try {
3099 final Phone phone = getPhone(subId);
3100 if (phone != null) {
3101 return phone.getCdmaEriIconMode();
3102 } else {
3103 return -1;
3104 }
3105 } finally {
3106 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003108 }
3109
3110 /**
3111 * Returns the CDMA ERI text,
3112 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003113 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003114 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3115 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3116 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003117 }
3118
Sanket Padawe356d7632015-06-22 14:03:32 -07003119 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003120 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3121 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003122 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003123 mApp, subId, callingPackage, callingFeatureId,
3124 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003125 return null;
3126 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003127
3128 final long identity = Binder.clearCallingIdentity();
3129 try {
3130 final Phone phone = getPhone(subId);
3131 if (phone != null) {
3132 return phone.getCdmaEriText();
3133 } else {
3134 return null;
3135 }
3136 } finally {
3137 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003138 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003139 }
3140
3141 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003142 * Returns the CDMA MDN.
3143 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003144 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003145 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3147 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003148
3149 final long identity = Binder.clearCallingIdentity();
3150 try {
3151 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003152 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003153 return phone.getLine1Number();
3154 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003155 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003156 return null;
3157 }
3158 } finally {
3159 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003160 }
3161 }
3162
3163 /**
3164 * Returns the CDMA MIN.
3165 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003166 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003167 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003168 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3169 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003170
3171 final long identity = Binder.clearCallingIdentity();
3172 try {
3173 final Phone phone = getPhone(subId);
3174 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3175 return phone.getCdmaMin();
3176 } else {
3177 return null;
3178 }
3179 } finally {
3180 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003181 }
3182 }
3183
Hall Liud892bec2018-11-30 14:51:45 -08003184 @Override
3185 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3186 INumberVerificationCallback callback, String callingPackage) {
3187 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3188 != PERMISSION_GRANTED) {
3189 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3190 }
3191 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3192
3193 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3194 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3195 throw new SecurityException("Calling package must be configured in the device config");
3196 }
3197
3198 if (range == null) {
3199 throw new NullPointerException("Range must be non-null");
3200 }
3201
3202 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003203 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003204
3205 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3206 }
3207
Junda Liuca05d5d2014-08-14 22:36:34 -07003208 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003209 * Returns true if CDMA provisioning needs to run.
3210 */
3211 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212 final long identity = Binder.clearCallingIdentity();
3213 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003214 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003215 } finally {
3216 Binder.restoreCallingIdentity(identity);
3217 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003218 }
3219
3220 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003221 * Sets the voice mail number of a given subId.
3222 */
3223 @Override
3224 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003225 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3226 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003227
3228 final long identity = Binder.clearCallingIdentity();
3229 try {
3230 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3231 new Pair<String, String>(alphaTag, number), new Integer(subId));
3232 return success;
3233 } finally {
3234 Binder.restoreCallingIdentity(identity);
3235 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003236 }
3237
Ta-wei Yen87c49842016-05-13 21:19:52 -07003238 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003239 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3240 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003241 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3242 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003243 if (!TextUtils.equals(callingPackage, systemDialer)) {
3244 throw new SecurityException("caller must be system dialer");
3245 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003246
3247 final long identity = Binder.clearCallingIdentity();
3248 try {
3249 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3250 if (phoneAccountHandle == null) {
3251 return null;
3252 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003253 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003254 } finally {
3255 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003256 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003257 }
3258
3259 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003260 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3261 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003262 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003263 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003264 mApp, subId, callingPackage, callingFeatureId,
3265 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003266 return null;
3267 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003268
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003269 final long identity = Binder.clearCallingIdentity();
3270 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003271 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003272 } finally {
3273 Binder.restoreCallingIdentity(identity);
3274 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003275 }
3276
3277 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003278 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3279 VisualVoicemailSmsFilterSettings settings) {
3280 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003281
3282 final long identity = Binder.clearCallingIdentity();
3283 try {
3284 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003285 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003286 } finally {
3287 Binder.restoreCallingIdentity(identity);
3288 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003289 }
3290
3291 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003292 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3293 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003294
3295 final long identity = Binder.clearCallingIdentity();
3296 try {
3297 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003298 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003299 } finally {
3300 Binder.restoreCallingIdentity(identity);
3301 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003302 }
3303
3304 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003305 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3306 String callingPackage, int subId) {
3307 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003308
3309 final long identity = Binder.clearCallingIdentity();
3310 try {
3311 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003312 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003313 } finally {
3314 Binder.restoreCallingIdentity(identity);
3315 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003316 }
3317
3318 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003319 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003320 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003321
3322 final long identity = Binder.clearCallingIdentity();
3323 try {
3324 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003325 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003326 } finally {
3327 Binder.restoreCallingIdentity(identity);
3328 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003329 }
3330
3331 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003332 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3333 String callingAttributionTag, int subId, String number, int port, String text,
3334 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003335 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003336 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003337 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003338 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003339 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3340 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003341 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003342
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003343 /**
fionaxu0152e512016-11-14 13:36:14 -08003344 * Sets the voice activation state of a given subId.
3345 */
3346 @Override
3347 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3349 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003350
3351 final long identity = Binder.clearCallingIdentity();
3352 try {
3353 final Phone phone = getPhone(subId);
3354 if (phone != null) {
3355 phone.setVoiceActivationState(activationState);
3356 } else {
3357 loge("setVoiceActivationState fails with invalid subId: " + subId);
3358 }
3359 } finally {
3360 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003361 }
3362 }
3363
3364 /**
3365 * Sets the data activation state of a given subId.
3366 */
3367 @Override
3368 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3370 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003371
3372 final long identity = Binder.clearCallingIdentity();
3373 try {
3374 final Phone phone = getPhone(subId);
3375 if (phone != null) {
3376 phone.setDataActivationState(activationState);
3377 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003378 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003379 }
3380 } finally {
3381 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003382 }
3383 }
3384
3385 /**
3386 * Returns the voice activation state of a given subId.
3387 */
3388 @Override
3389 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003390 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003391
fionaxu0152e512016-11-14 13:36:14 -08003392 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003393 final long identity = Binder.clearCallingIdentity();
3394 try {
3395 if (phone != null) {
3396 return phone.getVoiceActivationState();
3397 } else {
3398 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3399 }
3400 } finally {
3401 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003402 }
3403 }
3404
3405 /**
3406 * Returns the data activation state of a given subId.
3407 */
3408 @Override
3409 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003410 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003411
fionaxu0152e512016-11-14 13:36:14 -08003412 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003413 final long identity = Binder.clearCallingIdentity();
3414 try {
3415 if (phone != null) {
3416 return phone.getDataActivationState();
3417 } else {
3418 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3419 }
3420 } finally {
3421 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003422 }
3423 }
3424
3425 /**
Wink Saville36469e72014-06-11 15:17:00 -07003426 * Returns the unread count of voicemails for a subId
3427 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003428 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003429 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3430 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003431 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003432 mApp, subId, callingPackage, callingFeatureId,
3433 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003434 return 0;
3435 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003436 final long identity = Binder.clearCallingIdentity();
3437 try {
3438 final Phone phone = getPhone(subId);
3439 if (phone != null) {
3440 return phone.getVoiceMessageCount();
3441 } else {
3442 return 0;
3443 }
3444 } finally {
3445 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003446 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003447 }
3448
3449 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003450 * returns true, if the device is in a state where both voice and data
3451 * are supported simultaneously. This can change based on location or network condition.
3452 */
3453 @Override
3454 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003455 final long identity = Binder.clearCallingIdentity();
3456 try {
3457 final Phone phone = getPhone(subId);
3458 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3459 } finally {
3460 Binder.restoreCallingIdentity(identity);
3461 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003462 }
3463
3464 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003465 * Send the dialer code if called from the current default dialer or the caller has
3466 * carrier privilege.
3467 * @param inputCode The dialer code to send
3468 */
3469 @Override
3470 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003471 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003472 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003473 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3474 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003475 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003476 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003477 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003478 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003479
3480 final long identity = Binder.clearCallingIdentity();
3481 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003482 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003483 } finally {
3484 Binder.restoreCallingIdentity(identity);
3485 }
fionaxu235cc5e2017-03-06 22:25:57 -08003486 }
3487
Pengquan Menga1bb6272018-09-06 09:59:22 -07003488 @Override
3489 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003490 TelephonyPermissions
3491 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3492 mApp, subId, "getNetworkSelectionMode");
3493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 if (!isActiveSubscription(subId)) {
3496 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3497 }
3498 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3499 } finally {
3500 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003501 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003502 }
3503
Brad Ebinger35c841c2018-10-01 10:40:55 -07003504 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003505 public boolean isInEmergencySmsMode() {
3506 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3507 final long identity = Binder.clearCallingIdentity();
3508 try {
3509 for (Phone phone : PhoneFactory.getPhones()) {
3510 if (phone.isInEmergencySmsMode()) {
3511 return true;
3512 }
3513 }
3514 } finally {
3515 Binder.restoreCallingIdentity(identity);
3516 }
3517 return false;
3518 }
3519
shilu366312e2019-12-17 09:28:10 -08003520 /**
3521 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3522 * @param subId The subscription to use to check the configuration.
3523 * @param c The callback that will be used to send the result.
3524 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003525 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003526 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3527 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003528 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3529 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003530
Brad Ebinger77b832e2019-10-17 17:03:22 -07003531 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3532 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3533 "IMS not available on device.");
3534 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003535 final long token = Binder.clearCallingIdentity();
3536 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003537 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003538 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003539 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003540 } catch (ImsException e) {
3541 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003542 } finally {
3543 Binder.restoreCallingIdentity(token);
3544 }
3545 }
3546
shilu366312e2019-12-17 09:28:10 -08003547 /**
3548 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3549 * @param subId The subscription to use to check the configuration.
3550 * @param c The callback that will be used to send the result.
3551 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003552 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003553 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003554 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3555 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003556 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3557 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3558 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003559 final long token = Binder.clearCallingIdentity();
3560 try {
3561 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3562 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3563 .removeRegistrationCallbackForSubscription(c, subId);
3564 } catch (ImsException e) {
3565 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3566 + "is inactive, ignoring unregister.");
3567 // If the subscription is no longer active, just return, since the callback
3568 // will already have been removed internally.
3569 } finally {
3570 Binder.restoreCallingIdentity(token);
3571 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003572 }
3573
Brad Ebinger774ba362019-10-22 17:36:18 -07003574 /**
3575 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3576 */
3577 @Override
3578 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3579 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3580 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3581 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3582 "IMS not available on device.");
3583 }
3584 final long token = Binder.clearCallingIdentity();
3585 try {
3586 Phone phone = getPhone(subId);
3587 if (phone == null) {
3588 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3589 + subId + "'");
3590 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3591 }
3592 phone.getImsRegistrationState(regState -> {
3593 try {
3594 consumer.accept((regState == null)
3595 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3596 } catch (RemoteException e) {
3597 // Ignore if the remote process is no longer available to call back.
3598 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3599 }
3600 });
3601 } finally {
3602 Binder.restoreCallingIdentity(token);
3603 }
3604 }
3605
3606 /**
3607 * Get the transport type for the IMS service registration state.
3608 */
3609 @Override
3610 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003611 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3612 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003613 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3614 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3615 "IMS not available on device.");
3616 }
3617 final long token = Binder.clearCallingIdentity();
3618 try {
3619 Phone phone = getPhone(subId);
3620 if (phone == null) {
3621 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3622 + subId + "'");
3623 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3624 }
3625 phone.getImsRegistrationTech(regTech -> {
3626 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3627 int regTechConverted = (regTech == null)
3628 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3629 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3630 regTechConverted);
3631 try {
3632 consumer.accept(regTechConverted);
3633 } catch (RemoteException e) {
3634 // Ignore if the remote process is no longer available to call back.
3635 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3636 }
3637 });
3638 } finally {
3639 Binder.restoreCallingIdentity(token);
3640 }
3641 }
3642
shilu366312e2019-12-17 09:28:10 -08003643 /**
3644 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3645 * @param subId The subscription to use to check the configuration.
3646 * @param c The callback that will be used to send the result.
3647 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003648 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003649 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3650 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003651 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3652 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003653 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3654 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3655 "IMS not available on device.");
3656 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003657 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3658 final long token = Binder.clearCallingIdentity();
3659 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003660 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003661 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003662 } catch (ImsException e) {
3663 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003664 } finally {
3665 Binder.restoreCallingIdentity(token);
3666 }
3667 }
3668
shilu366312e2019-12-17 09:28:10 -08003669 /**
3670 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3671 * @param subId The subscription to use to check the configuration.
3672 * @param c The callback that will be used to send the result.
3673 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003674 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003675 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003676 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3677 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003678 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3679 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3680 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003681
3682 final long token = Binder.clearCallingIdentity();
3683 try {
3684 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3685 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003686 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003687 } catch (ImsException e) {
3688 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3689 + "is inactive, ignoring unregister.");
3690 // If the subscription is no longer active, just return, since the callback
3691 // will already have been removed internally.
3692 } finally {
3693 Binder.restoreCallingIdentity(token);
3694 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003695 }
3696
3697 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003698 public boolean isCapable(int subId, int capability, int regTech) {
3699 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003700 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3701 final long token = Binder.clearCallingIdentity();
3702 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003703 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003704 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003705 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003706 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3707 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003708 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003709 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3710 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003711 } finally {
3712 Binder.restoreCallingIdentity(token);
3713 }
3714 }
3715
3716 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003717 public boolean isAvailable(int subId, int capability, int regTech) {
3718 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003719 final long token = Binder.clearCallingIdentity();
3720 try {
3721 Phone phone = getPhone(subId);
3722 if (phone == null) return false;
3723 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003724 } catch (com.android.ims.ImsException e) {
3725 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3726 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003727 } finally {
3728 Binder.restoreCallingIdentity(token);
3729 }
3730 }
3731
Brad Ebinger77b832e2019-10-17 17:03:22 -07003732 /**
3733 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3734 * subscription.
3735 * @param subId The subscription to use to check the configuration.
3736 * @param callback The callback that will be used to send the result.
3737 * @param capability The MmTelFeature capability that will be used to send the result.
3738 * @param transportType The transport type of the MmTelFeature capability.
3739 */
3740 @Override
3741 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3742 int transportType) {
3743 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3744 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3745 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3746 "IMS not available on device.");
3747 }
3748 final long token = Binder.clearCallingIdentity();
3749 try {
3750 int slotId = getSlotIndex(subId);
3751 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3752 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3753 + subId + "'");
3754 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3755 }
3756 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3757 transportType, aBoolean -> {
3758 try {
3759 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3760 } catch (RemoteException e) {
3761 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3762 + "running. Ignore");
3763 }
3764 });
3765 } finally {
3766 Binder.restoreCallingIdentity(token);
3767 }
3768 }
3769
shilu366312e2019-12-17 09:28:10 -08003770 /**
3771 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3772 * @param subId The subscription to use to check the configuration.
3773 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003774 @Override
3775 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003776 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3777 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003778
Brad Ebinger35c841c2018-10-01 10:40:55 -07003779 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3780 final long token = Binder.clearCallingIdentity();
3781 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003782 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003783 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003784 } catch (ImsException e) {
3785 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003786 } finally {
3787 Binder.restoreCallingIdentity(token);
3788 }
3789 }
3790
3791 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003792 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003793 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003794 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003795 final long identity = Binder.clearCallingIdentity();
3796 try {
3797 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003798 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003799 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003800 } catch (ImsException e) {
3801 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003802 } finally {
3803 Binder.restoreCallingIdentity(identity);
3804 }
3805 }
3806
shilu366312e2019-12-17 09:28:10 -08003807 /**
3808 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3809 * @param subId The subscription to use to check the configuration.
3810 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003811 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003812 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003813 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3814 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003815 final long identity = Binder.clearCallingIdentity();
3816 try {
3817 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003818 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3819 } catch (ImsException e) {
3820 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003821 } finally {
3822 Binder.restoreCallingIdentity(identity);
3823 }
3824 }
3825
3826 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003827 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003829 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003830 final long identity = Binder.clearCallingIdentity();
3831 try {
3832 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003833 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003834 } catch (ImsException e) {
3835 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003836 } finally {
3837 Binder.restoreCallingIdentity(identity);
3838 }
3839 }
3840
shilu366312e2019-12-17 09:28:10 -08003841 /**
3842 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3843 * @param subId The subscription to use to check the configuration.
3844 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003845 @Override
3846 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003847 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3848 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003849 final long identity = Binder.clearCallingIdentity();
3850 try {
3851 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003852 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003853 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003854 } catch (ImsException e) {
3855 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003856 } finally {
3857 Binder.restoreCallingIdentity(identity);
3858 }
3859 }
3860
3861 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003862 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003864 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003865 final long identity = Binder.clearCallingIdentity();
3866 try {
3867 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003868 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003869 } catch (ImsException e) {
3870 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003871 } finally {
3872 Binder.restoreCallingIdentity(identity);
3873 }
3874 }
3875
shilu366312e2019-12-17 09:28:10 -08003876 /**
3877 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3878 * @param subId The subscription to use to check the configuration.
3879 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003880 @Override
3881 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003882 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3883 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003884 final long identity = Binder.clearCallingIdentity();
3885 try {
3886 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003887 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003888 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003889 } catch (ImsException e) {
3890 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003891 } finally {
3892 Binder.restoreCallingIdentity(identity);
3893 }
3894 }
3895
3896 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003897 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003899 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003900 final long identity = Binder.clearCallingIdentity();
3901 try {
3902 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003903 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003904 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003905 } catch (ImsException e) {
3906 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003907 } finally {
3908 Binder.restoreCallingIdentity(identity);
3909 }
3910 }
3911
3912 @Override
3913 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3915 "setVoWiFiNonPersistent");
3916 final long identity = Binder.clearCallingIdentity();
3917 try {
3918 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003919 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003920 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
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 int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003934 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3935 mApp, subId, "getVoWiFiModeSetting");
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)).getWfcMode(false /*isRoaming*/);
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
3949 public void setVoWiFiModeSetting(int subId, int mode) {
3950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3951 "setVoWiFiModeSetting");
3952 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)).setWfcMode(mode, false /*isRoaming*/);
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 int getVoWiFiRoamingModeSetting(int subId) {
3966 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3967 final long identity = Binder.clearCallingIdentity();
3968 try {
3969 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003970 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003971 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003972 } catch (ImsException e) {
3973 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003974 } finally {
3975 Binder.restoreCallingIdentity(identity);
3976 }
3977 }
3978
3979 @Override
3980 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3982 "setVoWiFiRoamingModeSetting");
3983 final long identity = Binder.clearCallingIdentity();
3984 try {
3985 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003986 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003987 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003988 } catch (ImsException e) {
3989 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003990 } finally {
3991 Binder.restoreCallingIdentity(identity);
3992 }
3993 }
3994
3995 @Override
3996 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3997 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3998 "setRttCapabilityEnabled");
3999 final long identity = Binder.clearCallingIdentity();
4000 try {
4001 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004002 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4003 } catch (ImsException e) {
4004 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004005 } finally {
4006 Binder.restoreCallingIdentity(identity);
4007 }
4008 }
4009
shilu366312e2019-12-17 09:28:10 -08004010 /**
4011 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4012 * @param subId The subscription to use to check the configuration.
4013 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004014 @Override
4015 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004016 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4017 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004018 final long identity = Binder.clearCallingIdentity();
4019 try {
4020 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004021 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004022 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004023 } catch (ImsException e) {
4024 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004025 } finally {
4026 Binder.restoreCallingIdentity(identity);
4027 }
4028 }
4029
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004030 @Override
4031 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4032 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4033 final long identity = Binder.clearCallingIdentity();
4034 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004035 if (!isImsAvailableOnDevice()) {
4036 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4037 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004038 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004039 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004040 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004041 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004042 } catch (ImsException e) {
4043 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004044 } finally {
4045 Binder.restoreCallingIdentity(identity);
4046 }
4047 }
4048
4049 @Override
4050 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4051 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4052 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004053 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4054 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4055 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004056 try {
4057 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004058 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004059 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004060 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004061 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4062 + "is inactive, ignoring unregister.");
4063 // If the subscription is no longer active, just return, since the callback will already
4064 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004065 } finally {
4066 Binder.restoreCallingIdentity(identity);
4067 }
4068 }
4069
allenwtsu99c623b2020-01-03 18:24:23 +08004070
4071 private void checkModifyPhoneStatePermission(int subId, String message) {
4072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4073 message);
4074 }
4075
4076 private boolean isImsProvisioningRequired(int subId, int capability,
4077 boolean isMmtelCapability) {
4078 Phone phone = getPhone(subId);
4079 if (phone == null) {
4080 loge("phone instance null for subid " + subId);
4081 return false;
4082 }
4083 if (isMmtelCapability) {
4084 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4085 return false;
4086 }
4087 } else {
4088 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4089 return false;
4090 }
4091 }
4092 return true;
4093 }
4094
4095 @Override
4096 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4097 boolean isProvisioned) {
4098 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4099
4100 final long identity = Binder.clearCallingIdentity();
4101 try {
4102 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4103 if (!isImsProvisioningRequired(subId, capability, false)) {
4104 return;
4105 }
4106
4107 // this capability requires provisioning, route to the correct API.
4108 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4109 switch (capability) {
4110 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4111 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4112 ims.setEabProvisioned(isProvisioned);
4113 break;
4114 default: {
4115 throw new IllegalArgumentException("Tried to set provisioning for "
4116 + "rcs capability '" + capability + "', which does not require "
4117 + "provisioning.");
4118 }
4119 }
4120 } finally {
4121 Binder.restoreCallingIdentity(identity);
4122 }
4123
4124 }
4125
4126
4127 @Override
4128 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4129 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4130 final long identity = Binder.clearCallingIdentity();
4131 try {
4132 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4133 if (!isImsProvisioningRequired(subId, capability, false)) {
4134 return true;
4135 }
4136
4137 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4138 switch (capability) {
4139 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4140 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4141 return ims.isEabProvisionedOnDevice();
4142
4143 default: {
4144 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4145 + "capability '" + capability + "', which does not require "
4146 + "provisioning.");
4147 }
4148 }
4149
4150 } finally {
4151 Binder.restoreCallingIdentity(identity);
4152 }
4153 }
4154
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004155 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004156 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4157 boolean isProvisioned) {
4158 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4159 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4160 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4161 }
allenwtsu99c623b2020-01-03 18:24:23 +08004162 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004163 final long identity = Binder.clearCallingIdentity();
4164 try {
4165 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004166 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004167 return;
4168 }
4169
4170 // this capability requires provisioning, route to the correct API.
4171 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4172 switch (capability) {
4173 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4174 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4175 ims.setVolteProvisioned(isProvisioned);
4176 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4177 ims.setWfcProvisioned(isProvisioned);
4178 }
4179 break;
4180 }
4181 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4182 // There is currently no difference in VT provisioning type.
4183 ims.setVtProvisioned(isProvisioned);
4184 break;
4185 }
4186 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4187 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4188 // change the capability of the feature instead if needed.
4189 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4190 == isProvisioned) {
4191 // No change in provisioning.
4192 return;
4193 }
4194 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4195 try {
4196 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004197 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004198 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4199 + ", Exception" + e.getMessage());
4200 }
4201 break;
4202 }
4203 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004204 throw new IllegalArgumentException("Tried to set provisioning for "
4205 + "MmTel capability '" + capability + "', which does not require "
4206 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004207 }
4208 }
4209
4210 } finally {
4211 Binder.restoreCallingIdentity(identity);
4212 }
4213 }
4214
4215 @Override
4216 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4217 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4218 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4219 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4220 }
4221 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4222 final long identity = Binder.clearCallingIdentity();
4223 try {
4224 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004225 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004226 return true;
4227 }
4228
4229 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4230 switch (capability) {
4231 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4232 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4233 return ims.isVolteProvisionedOnDevice();
4234 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4235 return ims.isWfcProvisionedOnDevice();
4236 }
4237 // This should never happen, since we are checking tech above to make sure it
4238 // is either LTE or IWLAN.
4239 throw new IllegalArgumentException("Invalid radio technology for voice "
4240 + "capability.");
4241 }
4242 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4243 // There is currently no difference in VT provisioning type.
4244 return ims.isVtProvisionedOnDevice();
4245 }
4246 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4247 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4248 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4249 }
4250 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004251 throw new IllegalArgumentException(
4252 "Tried to get provisioning for MmTel capability '" + capability
4253 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004254 }
4255 }
4256
4257 } finally {
4258 Binder.restoreCallingIdentity(identity);
4259 }
4260 }
4261
4262 @Override
4263 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4264 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4265 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4266 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4267 }
4268 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4269 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4270 return (provisionedBits & capability) > 0;
4271 }
4272
4273 @Override
4274 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4275 boolean isProvisioned) {
4276 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4277 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4278 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4279 }
4280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4281 "setProvisioningStatusForCapability");
4282 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4283 // If the current provisioning status for capability already matches isProvisioned,
4284 // do nothing.
4285 if (((provisionedBits & capability) > 0) == isProvisioned) {
4286 return;
4287 }
4288 if (isProvisioned) {
4289 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4290 } else {
4291 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4292 }
4293 }
4294
4295 /**
4296 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4297 * technology. The bitfield should mirror the bitfield defined by
4298 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4299 */
4300 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4301 String key = getMmTelProvisioningKey(subId, tech);
4302 // Default is no capabilities are provisioned.
4303 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4304 }
4305
4306 /**
4307 * Sets the MmTel capability provisioning bitfield (defined by
4308 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4309 * technology specified.
4310 *
4311 * Note: This is a synchronous command and should not be called on UI thread.
4312 */
4313 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4314 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4315 String key = getMmTelProvisioningKey(subId, tech);
4316 editor.putInt(key, newField);
4317 editor.commit();
4318 }
4319
4320 private static String getMmTelProvisioningKey(int subId, int tech) {
4321 // resulting key is provision_ims_mmtel_{subId}_{tech}
4322 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4323 }
4324
4325 /**
4326 * Query CarrierConfig to see if the specified capability requires provisioning for the
4327 * carrier associated with the subscription id.
4328 */
4329 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4330 int capability) {
4331 CarrierConfigManager configManager = new CarrierConfigManager(context);
4332 PersistableBundle c = configManager.getConfigForSubId(subId);
4333 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004334 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004335 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4336 false);
4337 boolean requireVoiceVtProvisioning = c.getBoolean(
4338 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4339
4340 // First check to make sure that the capability requires provisioning.
4341 switch (capability) {
4342 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4343 // intentional fallthrough
4344 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4345 if (requireVoiceVtProvisioning) {
4346 // Voice and Video requires provisioning
4347 return true;
4348 }
4349 break;
4350 }
4351 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4352 if (requireUtProvisioning) {
4353 // UT requires provisioning
4354 return true;
4355 }
4356 break;
4357 }
4358 }
4359 return false;
4360 }
4361
allenwtsu99c623b2020-01-03 18:24:23 +08004362 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4363 int capability) {
4364 CarrierConfigManager configManager = new CarrierConfigManager(context);
4365 PersistableBundle c = configManager.getConfigForSubId(subId);
4366
4367 boolean requireRcsProvisioning = c.getBoolean(
4368 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4369
4370 // First check to make sure that the capability requires provisioning.
4371 switch (capability) {
4372 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4373 // intentional fallthrough
4374 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4375 if (requireRcsProvisioning) {
4376 // OPTION or PRESENCE requires provisioning
4377 return true;
4378 }
4379 break;
4380 }
4381 }
4382 return false;
4383 }
4384
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004385 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004386 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004387 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4388 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4389 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004390 enforceReadPrivilegedPermission("getImsProvisioningInt");
4391 final long identity = Binder.clearCallingIdentity();
4392 try {
4393 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004394 int slotId = getSlotIndex(subId);
4395 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4396 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4397 + subId + "' for key:" + key);
4398 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4399 }
4400 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004401 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004402 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4403 + subId + "' for key:" + key);
4404 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004405 } finally {
4406 Binder.restoreCallingIdentity(identity);
4407 }
4408 }
4409
4410 @Override
4411 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004412 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4413 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4414 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004415 enforceReadPrivilegedPermission("getImsProvisioningString");
4416 final long identity = Binder.clearCallingIdentity();
4417 try {
4418 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004419 int slotId = getSlotIndex(subId);
4420 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4421 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4422 + subId + "' for key:" + key);
4423 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4424 }
4425 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004426 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004427 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4428 + subId + "' for key:" + key);
4429 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004430 } finally {
4431 Binder.restoreCallingIdentity(identity);
4432 }
4433 }
4434
4435 @Override
4436 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004437 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4438 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4439 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004440 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4441 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004442 final long identity = Binder.clearCallingIdentity();
4443 try {
4444 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004445 int slotId = getSlotIndex(subId);
4446 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4447 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4448 + subId + "' for key:" + key);
4449 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4450 }
4451 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004452 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004453 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4454 + "' for key:" + key);
4455 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004456 } finally {
4457 Binder.restoreCallingIdentity(identity);
4458 }
4459 }
4460
4461 @Override
4462 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004463 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4464 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4465 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4467 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004468 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, "setImsProvisioningString: called with an inactive subscription id '"
4474 + subId + "' for key:" + key);
4475 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4476 }
4477 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
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, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4480 + "' for key:" + key);
4481 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004482 } finally {
4483 Binder.restoreCallingIdentity(identity);
4484 }
4485 }
4486
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004487 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004488 int slotId = SubscriptionManager.getSlotIndex(subId);
4489 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004490 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4491 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004492 }
4493 return slotId;
4494 }
4495
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004496 private int getSlotIndex(int subId) {
4497 int slotId = SubscriptionManager.getSlotIndex(subId);
4498 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4499 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4500 }
4501 return slotId;
4502 }
4503
Wink Saville36469e72014-06-11 15:17:00 -07004504 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004505 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004506 */
4507 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004508 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4509 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004510 final int targetSdk = getTargetSdk(callingPackage);
4511 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004512 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004513 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004514 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004515 mApp, subId, callingPackage, callingFeatureId,
4516 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004517 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4518 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004519
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004520 final long identity = Binder.clearCallingIdentity();
4521 try {
4522 final Phone phone = getPhone(subId);
4523 if (phone != null) {
4524 return phone.getServiceState().getDataNetworkType();
4525 } else {
4526 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4527 }
4528 } finally {
4529 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004531 }
4532
4533 /**
4534 * Returns the data network type
4535 */
4536 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004537 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4538 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4539 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004540 }
4541
4542 /**
4543 * Returns the data network type for a subId
4544 */
4545 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004546 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4547 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004548 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004549 mApp, subId, callingPackage, callingFeatureId,
4550 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004551 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4552 }
4553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004554 final long identity = Binder.clearCallingIdentity();
4555 try {
4556 final Phone phone = getPhone(subId);
4557 if (phone != null) {
4558 return phone.getServiceState().getDataNetworkType();
4559 } else {
4560 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4561 }
4562 } finally {
4563 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004565 }
4566
4567 /**
Wink Saville36469e72014-06-11 15:17:00 -07004568 * Returns the Voice network type for a subId
4569 */
4570 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004571 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4572 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004573 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004574 mApp, subId, callingPackage, callingFeatureId,
4575 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004576 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4577 }
4578
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004579 final long identity = Binder.clearCallingIdentity();
4580 try {
4581 final Phone phone = getPhone(subId);
4582 if (phone != null) {
4583 return phone.getServiceState().getVoiceNetworkType();
4584 } else {
4585 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4586 }
4587 } finally {
4588 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004589 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004590 }
4591
4592 /**
4593 * @return true if a ICC card is present
4594 */
4595 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004596 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004597 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4598 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004599 }
4600
4601 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004602 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004603 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004604 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004605 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004606 final long identity = Binder.clearCallingIdentity();
4607 try {
4608 final Phone phone = PhoneFactory.getPhone(slotIndex);
4609 if (phone != null) {
4610 return phone.getIccCard().hasIccCard();
4611 } else {
4612 return false;
4613 }
4614 } finally {
4615 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004616 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004617 }
4618
4619 /**
4620 * Return if the current radio is LTE on CDMA. This
4621 * is a tri-state return value as for a period of time
4622 * the mode may be unknown.
4623 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004624 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004625 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004626 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004627 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004628 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004629 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4630 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4631 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004632 }
4633
Sanket Padawe356d7632015-06-22 14:03:32 -07004634 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004635 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4636 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004637 try {
4638 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4639 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004640 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4641 }
4642
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004643 final long identity = Binder.clearCallingIdentity();
4644 try {
4645 final Phone phone = getPhone(subId);
4646 if (phone == null) {
4647 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4648 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004649 return TelephonyProperties.lte_on_cdma_device()
4650 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004651 }
4652 } finally {
4653 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004654 }
Wink Saville36469e72014-06-11 15:17:00 -07004655 }
4656
Wink Saville36469e72014-06-11 15:17:00 -07004657 /**
4658 * {@hide}
4659 * Returns Default subId, 0 in the case of single standby.
4660 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004661 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004662 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004663 }
4664
Shishir Agrawala9f32182016-04-12 12:00:16 -07004665 private int getSlotForDefaultSubscription() {
4666 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4667 }
4668
Wink Savilleb564aae2014-10-23 10:18:09 -07004669 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004670 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004671 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004672
Pengquan Menge92a50d2018-09-21 15:54:48 -07004673 private boolean isActiveSubscription(int subId) {
4674 return mSubscriptionController.isActiveSubId(subId);
4675 }
4676
Ihab Awadf2177b72013-11-25 13:33:23 -08004677 /**
4678 * @see android.telephony.TelephonyManager.WifiCallingChoices
4679 */
4680 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004681 final long identity = Binder.clearCallingIdentity();
4682 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004683 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004684 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4685 getWhenToMakeWifiCallsDefaultPreference());
4686 } finally {
4687 Binder.restoreCallingIdentity(identity);
4688 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004689 }
4690
4691 /**
4692 * @see android.telephony.TelephonyManager.WifiCallingChoices
4693 */
4694 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004695 final long identity = Binder.clearCallingIdentity();
4696 try {
4697 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004698 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004699 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4700 } finally {
4701 Binder.restoreCallingIdentity(identity);
4702 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004703 }
4704
Sailesh Nepald1e68152013-12-12 19:08:02 -08004705 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004706 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004707 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004708 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004709
Jordan Liu4c733742019-02-28 12:03:40 -08004710 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4711 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4712 if (phoneId == -1) {
4713 throw new IllegalArgumentException("Given slot index: " + slotIndex
4714 + " does not correspond to an active phone");
4715 }
4716 return PhoneFactory.getPhone(phoneId);
4717 }
4718
Shishir Agrawal566b7612013-10-28 14:41:00 -07004719 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004720 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4721 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4723 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004724 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004725 if (DBG) {
4726 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4727 }
4728 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4729 p2);
4730 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004731
Jordan Liu4c733742019-02-28 12:03:40 -08004732
4733 @Override
4734 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4735 int slotIndex, String callingPackage, String aid, int p2) {
4736 enforceModifyPermission();
4737 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4738 if (DBG) {
4739 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4740 }
4741 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4742 callingPackage, aid, p2);
4743 }
4744
4745 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4746 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004747 final long identity = Binder.clearCallingIdentity();
4748 try {
4749 if (TextUtils.equals(ISDR_AID, aid)) {
4750 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004751 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4752 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004753 if (bestComponent == null
4754 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4755 loge("The calling package is not allowed to access ISD-R.");
4756 throw new SecurityException(
4757 "The calling package is not allowed to access ISD-R.");
4758 }
Derek Tan740e1672017-06-27 14:56:27 -07004759 }
Derek Tan740e1672017-06-27 14:56:27 -07004760
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004761 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004762 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4763 null /* workSource */);
4764 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004765 return response;
4766 } finally {
4767 Binder.restoreCallingIdentity(identity);
4768 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004769 }
4770
4771 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004772 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4774 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004775 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4776 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4777 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004778
Jordan Liu4c733742019-02-28 12:03:40 -08004779 @Override
4780 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4781 enforceModifyPermission();
4782 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4783 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4784 channel);
4785 }
4786
4787 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004788 final long identity = Binder.clearCallingIdentity();
4789 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004790 if (channel < 0) {
4791 return false;
4792 }
Jordan Liu4c733742019-02-28 12:03:40 -08004793 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4794 null /* workSource */);
4795 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004796 return success;
4797 } finally {
4798 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004799 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004800 }
4801
4802 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004803 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004804 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004805 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4806 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004807 if (DBG) {
4808 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4809 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4810 + p3 + " data=" + data);
4811 }
4812 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4813 command, p1, p2, p3, data);
4814 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004815
Jordan Liu4c733742019-02-28 12:03:40 -08004816 @Override
4817 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4818 int command, int p1, int p2, int p3, String data) {
4819 enforceModifyPermission();
4820 if (DBG) {
4821 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4822 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4823 + p3 + " data=" + data);
4824 }
4825 return iccTransmitApduLogicalChannelWithPermission(
4826 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4827 data);
4828 }
4829
4830 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4831 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004832 final long identity = Binder.clearCallingIdentity();
4833 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004834 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004835 return "";
4836 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004837
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004838 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004839 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4840 null /* workSource */);
4841 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004842
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004843 // Append the returned status code to the end of the response payload.
4844 String s = Integer.toHexString(
4845 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4846 if (response.payload != null) {
4847 s = IccUtils.bytesToHexString(response.payload) + s;
4848 }
4849 return s;
4850 } finally {
4851 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004852 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004853 }
Jake Hambye994d462014-02-03 13:10:13 -08004854
Evan Charltonc66da362014-05-16 14:06:40 -07004855 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004856 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4857 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4859 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004860 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004861 if (DBG) {
4862 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4863 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4864 }
4865 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4866 cla, command, p1, p2, p3, data);
4867 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004868
Jordan Liu4c733742019-02-28 12:03:40 -08004869 @Override
4870 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4871 int command, int p1, int p2, int p3, String data) {
4872 enforceModifyPermission();
4873 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4874 if (DBG) {
4875 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4876 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4877 + " data=" + data);
4878 }
4879
4880 return iccTransmitApduBasicChannelWithPermission(
4881 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4882 p2, p3, data);
4883 }
4884
4885 // open APDU basic channel assuming the caller has sufficient permissions
4886 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4887 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004888 final long identity = Binder.clearCallingIdentity();
4889 try {
4890 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4891 && TextUtils.equals(ISDR_AID, data)) {
4892 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004893 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4894 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004895 if (bestComponent == null
4896 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4897 loge("The calling package is not allowed to select ISD-R.");
4898 throw new SecurityException(
4899 "The calling package is not allowed to select ISD-R.");
4900 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004901 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004903 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004904 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4905 null /* workSource */);
4906 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004907
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004908 // Append the returned status code to the end of the response payload.
4909 String s = Integer.toHexString(
4910 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4911 if (response.payload != null) {
4912 s = IccUtils.bytesToHexString(response.payload) + s;
4913 }
4914 return s;
4915 } finally {
4916 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004917 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004918 }
4919
4920 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004921 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004922 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4924 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004925
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004926 final long identity = Binder.clearCallingIdentity();
4927 try {
4928 if (DBG) {
4929 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4930 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4931 }
4932
4933 IccIoResult response =
4934 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4935 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4936 subId);
4937
4938 if (DBG) {
4939 log("Exchange SIM_IO [R]" + response);
4940 }
4941
4942 byte[] result = null;
4943 int length = 2;
4944 if (response.payload != null) {
4945 length = 2 + response.payload.length;
4946 result = new byte[length];
4947 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4948 } else {
4949 result = new byte[length];
4950 }
4951
4952 result[length - 1] = (byte) response.sw2;
4953 result[length - 2] = (byte) response.sw1;
4954 return result;
4955 } finally {
4956 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004957 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004958 }
4959
Nathan Haroldb3014052017-01-25 15:57:32 -08004960 /**
4961 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4962 * on a particular subscription
4963 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004964 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4965 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004966 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004967 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004968 return null;
4969 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970
4971 final long identity = Binder.clearCallingIdentity();
4972 try {
4973 if (appType != TelephonyManager.APPTYPE_USIM
4974 && appType != TelephonyManager.APPTYPE_SIM) {
4975 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4976 return null;
4977 }
4978 Object response = sendRequest(
4979 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4980 if (response instanceof String[]) {
4981 return (String[]) response;
4982 }
yincheng zhaod698b842019-09-06 17:06:54 -07004983 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004984 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004985 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004986 } finally {
4987 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004988 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004989 }
4990
yincheng zhaod698b842019-09-06 17:06:54 -07004991 /**
4992 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4993 * subscription.
4994 *
4995 * @param subId the id of the subscription.
4996 * @param appType the uicc app type, must be USIM or SIM.
4997 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4998 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004999 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005000 * @return number of fplmns that is successfully written to the SIM.
5001 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005002 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5003 String callingFeatureId) {
5004 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5005 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005006 if (DBG) logv("no permissions for setForbiddenplmns");
5007 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5008 }
5009 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5010 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5011 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5012 }
5013 if (fplmns == null) {
5014 throw new IllegalArgumentException("Fplmn List provided is null");
5015 }
5016 for (String fplmn : fplmns) {
5017 if (!CellIdentity.isValidPlmn(fplmn)) {
5018 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5019 }
5020 }
5021 final long identity = Binder.clearCallingIdentity();
5022 try {
5023 Object response = sendRequest(
5024 CMD_SET_FORBIDDEN_PLMNS,
5025 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5026 subId);
5027 return (int) response;
5028 } finally {
5029 Binder.restoreCallingIdentity(identity);
5030 }
5031 }
5032
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005033 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005034 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5036 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005037
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038 final long identity = Binder.clearCallingIdentity();
5039 try {
5040 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5041 if (response.payload == null) {
5042 return "";
5043 }
Evan Charltonc66da362014-05-16 14:06:40 -07005044
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005045 // Append the returned status code to the end of the response payload.
5046 String s = Integer.toHexString(
5047 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5048 s = IccUtils.bytesToHexString(response.payload) + s;
5049 return s;
5050 } finally {
5051 Binder.restoreCallingIdentity(identity);
5052 }
Evan Charltonc66da362014-05-16 14:06:40 -07005053 }
5054
Jake Hambye994d462014-02-03 13:10:13 -08005055 /**
5056 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5057 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5058 *
5059 * @param itemID the ID of the item to read
5060 * @return the NV item as a String, or null on error.
5061 */
5062 @Override
5063 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005064 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5066 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005067
5068 final long identity = Binder.clearCallingIdentity();
5069 try {
5070 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005071 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005072 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5073 return value;
5074 } finally {
5075 Binder.restoreCallingIdentity(identity);
5076 }
Jake Hambye994d462014-02-03 13:10:13 -08005077 }
5078
5079 /**
5080 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5081 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5082 *
5083 * @param itemID the ID of the item to read
5084 * @param itemValue the value to write, as a String
5085 * @return true on success; false on any failure
5086 */
5087 @Override
5088 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005089 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005090 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5091 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005092
5093 final long identity = Binder.clearCallingIdentity();
5094 try {
5095 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5096 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005097 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005098 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5099 return success;
5100 } finally {
5101 Binder.restoreCallingIdentity(identity);
5102 }
Jake Hambye994d462014-02-03 13:10:13 -08005103 }
5104
5105 /**
5106 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5107 * Used for device configuration by some CDMA operators.
5108 *
5109 * @param preferredRoamingList byte array containing the new PRL
5110 * @return true on success; false on any failure
5111 */
5112 @Override
5113 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005114 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5115 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005116
5117 final long identity = Binder.clearCallingIdentity();
5118 try {
5119 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5120 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5121 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5122 return success;
5123 } finally {
5124 Binder.restoreCallingIdentity(identity);
5125 }
Jake Hambye994d462014-02-03 13:10:13 -08005126 }
5127
5128 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005129 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005130 * Used for device configuration by some CDMA operators.
5131 *
chen xu6dac5ab2018-10-26 17:39:23 -07005132 * @param slotIndex - device slot.
5133 *
Jake Hambye994d462014-02-03 13:10:13 -08005134 * @return true on success; false on any failure
5135 */
5136 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005137 public boolean resetModemConfig(int slotIndex) {
5138 Phone phone = PhoneFactory.getPhone(slotIndex);
5139 if (phone != null) {
5140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5141 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005142
chen xu6dac5ab2018-10-26 17:39:23 -07005143 final long identity = Binder.clearCallingIdentity();
5144 try {
5145 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5146 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5147 return success;
5148 } finally {
5149 Binder.restoreCallingIdentity(identity);
5150 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005151 }
chen xu6dac5ab2018-10-26 17:39:23 -07005152 return false;
5153 }
5154
5155 /**
5156 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5157 *
5158 * @param slotIndex - device slot.
5159 *
5160 * @return true on success; false on any failure
5161 */
5162 @Override
5163 public boolean rebootModem(int slotIndex) {
5164 Phone phone = PhoneFactory.getPhone(slotIndex);
5165 if (phone != null) {
5166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5167 mApp, phone.getSubId(), "rebootModem");
5168
5169 final long identity = Binder.clearCallingIdentity();
5170 try {
5171 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5172 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5173 return success;
5174 } finally {
5175 Binder.restoreCallingIdentity(identity);
5176 }
5177 }
5178 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005179 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005180
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005181 public String[] getPcscfAddress(String apnType, String callingPackage,
5182 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005183 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5185 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005186 return new String[0];
5187 }
5188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005189 final long identity = Binder.clearCallingIdentity();
5190 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005191 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 } finally {
5193 Binder.restoreCallingIdentity(identity);
5194 }
Wink Saville36469e72014-06-11 15:17:00 -07005195 }
5196
Brad Ebinger51f743a2017-01-23 13:50:20 -08005197 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005198 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5199 * {@link #disableIms(int)}.
5200 * @param slotIndex device slot.
5201 */
5202 public void resetIms(int slotIndex) {
5203 enforceModifyPermission();
5204
5205 final long identity = Binder.clearCallingIdentity();
5206 try {
5207 if (mImsResolver == null) {
5208 // may happen if the does not support IMS.
5209 return;
5210 }
5211 mImsResolver.disableIms(slotIndex);
5212 mImsResolver.enableIms(slotIndex);
5213 } finally {
5214 Binder.restoreCallingIdentity(identity);
5215 }
5216 }
5217
5218 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005219 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5220 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005221 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005222 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005223 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224
5225 final long identity = Binder.clearCallingIdentity();
5226 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005227 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005228 // may happen if the device does not support IMS.
5229 return;
5230 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005231 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005232 } finally {
5233 Binder.restoreCallingIdentity(identity);
5234 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005235 }
5236
5237 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005238 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5239 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005240 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005241 public void disableIms(int slotId) {
5242 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243
5244 final long identity = Binder.clearCallingIdentity();
5245 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005246 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005247 // may happen if the device does not support IMS.
5248 return;
5249 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005250 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005251 } finally {
5252 Binder.restoreCallingIdentity(identity);
5253 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005254 }
5255
5256 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005257 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5258 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005259 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005260 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005261 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005262 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263
5264 final long identity = Binder.clearCallingIdentity();
5265 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005266 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005267 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5268 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005269 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005270 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005271 } finally {
5272 Binder.restoreCallingIdentity(identity);
5273 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005274 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005275 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005276 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5277 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005278 @Override
5279 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005280 enforceModifyPermission();
5281
5282 final long identity = Binder.clearCallingIdentity();
5283 try {
5284 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005285 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005286 } finally {
5287 Binder.restoreCallingIdentity(identity);
5288 }
5289 }
5290
5291 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005292 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005293 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005294 */
5295 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5296 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005297
5298 final long identity = Binder.clearCallingIdentity();
5299 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005300 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005301 // may happen if the device does not support IMS.
5302 return null;
5303 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005304 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005305 } finally {
5306 Binder.restoreCallingIdentity(identity);
5307 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005308 }
5309
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005310 /**
5311 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005312 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005313 */
5314 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5315 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005316
5317 final long identity = Binder.clearCallingIdentity();
5318 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005319 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005320 // may happen if the device does not support IMS.
5321 return null;
5322 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005323 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324 } finally {
5325 Binder.restoreCallingIdentity(identity);
5326 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005327 }
5328
Brad Ebinger884c07b2018-02-15 16:17:40 -08005329 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005330 * Sets the ImsService Package Name that Telephony will bind to.
5331 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005332 * @param slotIndex the slot ID that the ImsService should bind for.
5333 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005334 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005335 * @param featureTypes An integer array of feature types associated with a packageName.
5336 * @param packageName The name of the package that the current configuration will be replaced
5337 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005338 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005339 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005340 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5341 int[] featureTypes, String packageName) {
5342 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5343 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5345 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005346 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005347
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005348 final long identity = Binder.clearCallingIdentity();
5349 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005350 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005351 // may happen if the device does not support IMS.
5352 return false;
5353 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005354 Map<Integer, String> featureConfig = new HashMap<>();
5355 for (int featureType : featureTypes) {
5356 featureConfig.put(featureType, packageName);
5357 }
5358 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5359 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005360 } finally {
5361 Binder.restoreCallingIdentity(identity);
5362 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005363 }
5364
5365 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005366 * Clears any carrier ImsService overrides for the slot index specified that were previously
5367 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5368 *
5369 * This should only be used for testing.
5370 *
5371 * @param slotIndex the slot ID that the ImsService should bind for.
5372 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5373 */
5374 @Override
5375 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5376 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5377 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5378 "clearCarrierImsServiceOverride");
5379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5380 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5381 "clearCarrierImsServiceOverride");
5382
5383 final long identity = Binder.clearCallingIdentity();
5384 try {
5385 if (mImsResolver == null) {
5386 // may happen if the device does not support IMS.
5387 return false;
5388 }
5389 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5390 } finally {
5391 Binder.restoreCallingIdentity(identity);
5392 }
5393 }
5394
5395 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005396 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005397 *
5398 * @param slotId The slot that the ImsService is associated with.
5399 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5400 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005401 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005402 * @return the package name of the ImsService configuration.
5403 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005404 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5405 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005406 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005407 TelephonyPermissions
5408 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5409 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5410 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005411
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005412 final long identity = Binder.clearCallingIdentity();
5413 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005414 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005415 // may happen if the device does not support IMS.
5416 return "";
5417 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005418 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005419 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5420 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 } finally {
5422 Binder.restoreCallingIdentity(identity);
5423 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005424 }
5425
Brad Ebinger77b832e2019-10-17 17:03:22 -07005426 /**
5427 * Get the MmTelFeature state associated with the requested subscription id.
5428 * @param subId The subscription that the MmTelFeature is associated with.
5429 * @param callback A callback with an integer containing the
5430 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5431 */
5432 @Override
5433 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5434 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5435 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5436 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5437 "IMS not available on device.");
5438 }
5439 final long token = Binder.clearCallingIdentity();
5440 try {
5441 int slotId = getSlotIndex(subId);
5442 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5443 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5444 + subId + "'");
5445 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5446 }
5447 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5448 try {
5449 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5450 } catch (RemoteException e) {
5451 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5452 + "Ignore");
5453 }
5454 });
5455 } finally {
5456 Binder.restoreCallingIdentity(token);
5457 }
5458 }
5459
Wink Saville36469e72014-06-11 15:17:00 -07005460 public void setImsRegistrationState(boolean registered) {
5461 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005462
5463 final long identity = Binder.clearCallingIdentity();
5464 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005465 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466 } finally {
5467 Binder.restoreCallingIdentity(identity);
5468 }
Wink Saville36469e72014-06-11 15:17:00 -07005469 }
5470
5471 /**
Stuart Scott54788802015-03-30 13:18:01 -07005472 * Set the network selection mode to automatic.
5473 *
5474 */
5475 @Override
5476 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5478 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005479
5480 final long identity = Binder.clearCallingIdentity();
5481 try {
shilufc958392020-01-20 11:36:01 -08005482 if (!isActiveSubscription(subId)) {
5483 return;
5484 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5486 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5487 } finally {
5488 Binder.restoreCallingIdentity(identity);
5489 }
Stuart Scott54788802015-03-30 13:18:01 -07005490 }
5491
Jack Yud10cdd42020-09-28 20:28:01 -07005492 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005493 * Ask the radio to connect to the input network and change selection mode to manual.
5494 *
5495 * @param subId the id of the subscription.
5496 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5497 * the operator to attach to.
5498 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5499 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5500 * normal network selection next time.
5501 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005502 */
5503 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005504 public boolean setNetworkSelectionModeManual(
5505 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005506 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5507 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005508
5509 if (!isActiveSubscription(subId)) {
5510 return false;
5511 }
5512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005513 final long identity = Binder.clearCallingIdentity();
5514 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005515 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005516 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005517 if (DBG) {
5518 log("setNetworkSelectionModeManual: subId: " + subId
5519 + " operator: " + operatorInfo);
5520 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5522 } finally {
5523 Binder.restoreCallingIdentity(identity);
5524 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005525 }
shilu84f6e8b2019-12-19 13:58:01 -08005526 /**
5527 * Get the manual network selection
5528 *
5529 * @param subId the id of the subscription.
5530 *
5531 * @return the previously saved user selected PLMN
5532 */
5533 @Override
5534 public String getManualNetworkSelectionPlmn(int subId) {
5535 TelephonyPermissions
5536 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5537 mApp, subId, "getManualNetworkSelectionPlmn");
5538
5539 final long identity = Binder.clearCallingIdentity();
5540 try {
5541 if (!isActiveSubscription(subId)) {
5542 return "";
5543 }
5544
5545 final Phone phone = getPhone(subId);
5546 if (phone == null) {
5547 return "";
5548 }
5549 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5550 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5551 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5552 } finally {
5553 Binder.restoreCallingIdentity(identity);
5554 }
5555 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005556
5557 /**
5558 * Scans for available networks.
5559 */
5560 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005561 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5562 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5564 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005565 LocationAccessPolicy.LocationPermissionResult locationResult =
5566 LocationAccessPolicy.checkLocationPermission(mApp,
5567 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5568 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005569 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005570 .setCallingPid(Binder.getCallingPid())
5571 .setCallingUid(Binder.getCallingUid())
5572 .setMethod("getCellNetworkScanResults")
5573 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5574 .build());
5575 switch (locationResult) {
5576 case DENIED_HARD:
5577 throw new SecurityException("Not allowed to access scan results -- location");
5578 case DENIED_SOFT:
5579 return null;
5580 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581
Pengquan Menga1bb6272018-09-06 09:59:22 -07005582 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583 try {
5584 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005585 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587 } finally {
5588 Binder.restoreCallingIdentity(identity);
5589 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005590 }
5591
5592 /**
sqian80370722020-01-29 15:02:51 -08005593 * Get the call forwarding info, given the call forwarding reason.
5594 */
5595 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005596 public void getCallForwarding(int subId, int callForwardingReason,
5597 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005598 enforceReadPrivilegedPermission("getCallForwarding");
5599 long identity = Binder.clearCallingIdentity();
5600 try {
5601 if (DBG) {
5602 log("getCallForwarding: subId " + subId
5603 + " callForwardingReason" + callForwardingReason);
5604 }
Hall Liua1acea22020-09-18 19:04:59 -07005605
5606 Phone phone = getPhone(subId);
5607 if (phone == null) {
5608 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005609 callback.onError(
5610 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005611 } catch (RemoteException e) {
5612 // ignore
5613 }
5614 return;
5615 }
5616
5617 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5618 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5619 @Override
5620 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5621 try {
5622 callback.onCallForwardingInfoAvailable(info);
5623 } catch (RemoteException e) {
5624 // ignore
5625 }
5626 }
5627
5628 @Override
5629 public void onError(int error) {
5630 try {
5631 callback.onError(error);
5632 } catch (RemoteException e) {
5633 // ignore
5634 }
5635 }
5636 });
5637 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005638 } finally {
5639 Binder.restoreCallingIdentity(identity);
5640 }
5641 }
5642
5643 /**
5644 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5645 * reason, the number to forward, and the timeout before the forwarding is attempted.
5646 */
5647 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005648 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5649 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005650 enforceModifyPermission();
5651 long identity = Binder.clearCallingIdentity();
5652 try {
5653 if (DBG) {
5654 log("setCallForwarding: subId " + subId
5655 + " callForwardingInfo" + callForwardingInfo);
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.accept(
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<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5670 FunctionalUtils.ignoreRemoteException(callback::accept));
5671
5672 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005673 } finally {
5674 Binder.restoreCallingIdentity(identity);
5675 }
5676 }
5677
5678 /**
Hall Liua1acea22020-09-18 19:04:59 -07005679 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005680 */
5681 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005682 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005683 enforceReadPrivilegedPermission("getCallForwarding");
5684 long identity = Binder.clearCallingIdentity();
5685 try {
Hall Liua1acea22020-09-18 19:04:59 -07005686
5687 Phone phone = getPhone(subId);
5688 if (phone == null) {
5689 try {
5690 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5691 } catch (RemoteException e) {
5692 // ignore
5693 }
5694 return;
5695 }
5696
5697 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5698
sqian80370722020-01-29 15:02:51 -08005699 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005700 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005701 } finally {
5702 Binder.restoreCallingIdentity(identity);
5703 }
5704 }
5705
5706 /**
Hall Liua1acea22020-09-18 19:04:59 -07005707 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005708 */
5709 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005710 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005711 enforceModifyPermission();
5712 long identity = Binder.clearCallingIdentity();
5713 try {
Hall Liua1acea22020-09-18 19:04:59 -07005714 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5715
5716 Phone phone = getPhone(subId);
5717 if (phone == null) {
5718 try {
5719 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5720 } catch (RemoteException e) {
5721 // ignore
5722 }
5723 return;
5724 }
5725
5726 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5727 FunctionalUtils.ignoreRemoteException(callback::accept));
5728
5729 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005730 } finally {
5731 Binder.restoreCallingIdentity(identity);
5732 }
5733 }
5734
5735 /**
yinxub1bed742017-04-17 11:45:04 -07005736 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005737 *
yinxub1bed742017-04-17 11:45:04 -07005738 * @param subId id of the subscription
5739 * @param request contains the radio access networks with bands/channels to scan
5740 * @param messenger callback messenger for scan results or errors
5741 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005742 * @return the id of the requested scan which can be used to stop the scan.
5743 */
5744 @Override
5745 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005746 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5748 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005749 LocationAccessPolicy.LocationPermissionResult locationResult =
5750 LocationAccessPolicy.checkLocationPermission(mApp,
5751 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5752 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005753 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005754 .setCallingPid(Binder.getCallingPid())
5755 .setCallingUid(Binder.getCallingUid())
5756 .setMethod("requestNetworkScan")
5757 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5758 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005759 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005760 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5761 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005762 if (e != null) {
5763 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5764 throw e;
5765 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005766 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005767 return TelephonyScanManager.INVALID_SCAN_ID;
5768 }
5769 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770 }
Hall Liu912dfd32019-04-25 14:02:26 -07005771 int callingUid = Binder.getCallingUid();
5772 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005773 final long identity = Binder.clearCallingIdentity();
5774 try {
5775 return mNetworkScanRequestTracker.startNetworkScan(
5776 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005777 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005778 } finally {
5779 Binder.restoreCallingIdentity(identity);
5780 }
yinxu504e1392017-04-12 16:03:22 -07005781 }
5782
Hall Liub2ac8ef2019-02-28 15:56:23 -08005783 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005784 NetworkScanRequest request, int subId, String callingPackage) {
5785 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005786 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5787 boolean hasNetworkScanPermission =
5788 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5789 == PERMISSION_GRANTED;
5790
5791 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5792 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5793 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005794 }
5795
5796 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5797 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005798 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5799 return new SecurityException("Specific channels must not be"
5800 + " scanned without location access.");
5801 }
5802 }
5803 }
5804
Hall Liub2ac8ef2019-02-28 15:56:23 -08005805 return null;
5806 }
5807
yinxu504e1392017-04-12 16:03:22 -07005808 /**
5809 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005810 *
5811 * @param subId id of the subscription
5812 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005813 */
5814 @Override
5815 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5817 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818
Hall Liu912dfd32019-04-25 14:02:26 -07005819 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005820 final long identity = Binder.clearCallingIdentity();
5821 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005822 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005823 } finally {
5824 Binder.restoreCallingIdentity(identity);
5825 }
yinxu504e1392017-04-12 16:03:22 -07005826 }
5827
5828 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005829 * Get the calculated preferred network type.
5830 * Used for debugging incorrect network type.
5831 *
5832 * @return the preferred network type, defined in RILConstants.java.
5833 */
5834 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005835 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005836 final Phone defaultPhone = getDefaultPhone();
5837 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005838 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005839 return RILConstants.PREFERRED_NETWORK_MODE;
5840 }
5841
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842 final long identity = Binder.clearCallingIdentity();
5843 try {
5844 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005845 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005846 } finally {
5847 Binder.restoreCallingIdentity(identity);
5848 }
Junda Liu84d15a22014-07-02 11:21:04 -07005849 }
5850
5851 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005852 * Get the preferred network type.
5853 * Used for device configuration by some CDMA operators.
5854 *
5855 * @return the preferred network type, defined in RILConstants.java.
5856 */
5857 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005858 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005859 TelephonyPermissions
5860 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5861 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005862
5863 final long identity = Binder.clearCallingIdentity();
5864 try {
5865 if (DBG) log("getPreferredNetworkType");
5866 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5867 int networkType = (result != null ? result[0] : -1);
5868 if (DBG) log("getPreferredNetworkType: " + networkType);
5869 return networkType;
5870 } finally {
5871 Binder.restoreCallingIdentity(identity);
5872 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005873 }
5874
5875 /**
5876 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005877 *
5878 * @param networkType the preferred network type, defined in RILConstants.java.
5879 * @return true on success; false on any failure.
5880 */
5881 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005882 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005883 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5884 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005885
5886 final long identity = Binder.clearCallingIdentity();
5887 try {
calvinpan089c2a62020-03-12 14:17:55 +08005888 Boolean success = (Boolean) sendRequest(
5889 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005890
5891 if (success) {
5892 Settings.Global.putInt(mApp.getContentResolver(),
5893 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5894 }
calvinpan089c2a62020-03-12 14:17:55 +08005895 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5896 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897 } finally {
5898 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005899 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005900 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005901
5902 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005903 * Get the allowed network types that store in the telephony provider.
5904 *
5905 * @param subId the id of the subscription.
5906 * @return allowedNetworkTypes the allowed network types.
5907 */
5908 @Override
5909 public long getAllowedNetworkTypes(int subId) {
5910 TelephonyPermissions
5911 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5912 mApp, subId, "getAllowedNetworkTypes");
5913
5914 final long identity = Binder.clearCallingIdentity();
5915 try {
5916 return SubscriptionManager.getLongSubscriptionProperty(
5917 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5918 } finally {
5919 Binder.restoreCallingIdentity(identity);
5920 }
5921 }
5922
5923 /**
5924 * Set the allowed network types.
5925 *
5926 * @param subId the id of the subscription.
5927 * @param allowedNetworkTypes the allowed network types.
5928 * @return true on success; false on any failure.
5929 */
5930 @Override
5931 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5933 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005934
calvinpan089c2a62020-03-12 14:17:55 +08005935 SubscriptionManager.setSubscriptionProperty(subId,
5936 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5937 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005938
calvinpan089c2a62020-03-12 14:17:55 +08005939 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5940 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5941 RILConstants.PREFERRED_NETWORK_MODE);
5942 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005943 }
5944
5945 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005946 * Get the allowed network types for certain reason.
5947 *
5948 * @param subId the id of the subscription.
5949 * @param reason the reason the allowed network type change is taking place
5950 * @return the allowed network types.
5951 */
5952 @Override
5953 public long getAllowedNetworkTypesForReason(int subId,
5954 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5955 TelephonyPermissions
5956 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5957 mApp, subId, "getAllowedNetworkTypesForReason");
5958 final long identity = Binder.clearCallingIdentity();
5959 try {
5960 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5961 } finally {
5962 Binder.restoreCallingIdentity(identity);
5963 }
5964 }
5965
5966 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07005967 * Enable/Disable E-UTRA-NR Dual Connectivity
5968 * @param subId subscription id of the sim card
5969 * @param nrDualConnectivityState expected NR dual connectivity state
5970 * This can be passed following states
5971 * <ol>
5972 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
5973 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
5974 * <li>Disable NR dual connectivity and force secondary cell to be released
5975 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
5976 * </ol>
5977 * @return operation result.
5978 */
5979 @Override
5980 public int setNrDualConnectivityState(int subId,
5981 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
5982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5983 mApp, subId, "enableNRDualConnectivity");
5984 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5985 final long identity = Binder.clearCallingIdentity();
5986 try {
5987 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
5988 nrDualConnectivityState, subId,
5989 workSource);
5990 if (DBG) log("enableNRDualConnectivity result: " + result);
5991 return result;
5992 } finally {
5993 Binder.restoreCallingIdentity(identity);
5994 }
5995 }
5996
5997 /**
5998 * Is E-UTRA-NR Dual Connectivity enabled
5999 * @return true if dual connectivity is enabled else false
6000 */
6001 @Override
6002 public boolean isNrDualConnectivityEnabled(int subId) {
6003 TelephonyPermissions
6004 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6005 mApp, subId, "isNRDualConnectivityEnabled");
6006 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6007 final long identity = Binder.clearCallingIdentity();
6008 try {
6009 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6010 null, subId, workSource);
6011 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6012 return isEnabled;
6013 } finally {
6014 Binder.restoreCallingIdentity(identity);
6015 }
6016 }
6017
6018 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006019 * get carrier bandwidth per primary and secondary carrier
6020 * @param subId subscription id of the sim card
6021 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6022 */
6023 @Override
6024 public CarrierBandwidth getCarrierBandwidth(int subId) {
6025 TelephonyPermissions
6026 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6027 mApp, subId, "isNRDualConnectivityEnabled");
6028 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6029 final long identity = Binder.clearCallingIdentity();
6030 try {
6031 CarrierBandwidth carrierBandwidth =
6032 getPhoneFromSubId(subId).getCarrierBandwidth();
6033 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6034 return carrierBandwidth;
6035 } finally {
6036 Binder.restoreCallingIdentity(identity);
6037 }
6038 }
6039
6040 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006041 * Get the effective allowed network types on the device.
6042 * This API will return an intersection of allowed network types for all reasons,
6043 * including the configuration done through setAllowedNetworkTypes
6044 *
6045 * @param subId the id of the subscription.
6046 * @return the allowed network types
6047 */
6048 @Override
6049 public long getEffectiveAllowedNetworkTypes(int subId) {
6050 TelephonyPermissions
6051 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6052 mApp, subId, "getEffectiveAllowedNetworkTypes");
6053 final long identity = Binder.clearCallingIdentity();
6054 try {
6055 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6056 } finally {
6057 Binder.restoreCallingIdentity(identity);
6058 }
6059 }
6060
6061 /**
6062 * Set the allowed network types of the device and
6063 * provide the reason triggering the allowed network change.
6064 *
6065 * @param subId the id of the subscription.
6066 * @param reason the reason the allowed network type change is taking place
6067 * @param allowedNetworkTypes the allowed network types.
6068 * @return true on success; false on any failure.
6069 */
6070 @Override
6071 public boolean setAllowedNetworkTypesForReason(int subId,
6072 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6074 mApp, subId, "setAllowedNetworkTypesForReason");
6075 final long identity = Binder.clearCallingIdentity();
6076 try {
6077 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6078 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6079 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6080 RILConstants.PREFERRED_NETWORK_MODE);
6081 return setPreferredNetworkType(subId, preferredNetworkMode);
6082 } finally {
6083 Binder.restoreCallingIdentity(identity);
6084 }
6085 }
6086
6087 /**
Miaoa84611c2019-03-15 09:21:10 +08006088 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006089 *
Miaoa84611c2019-03-15 09:21:10 +08006090 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006091 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006092 * @hide
6093 */
6094 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006095 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006096 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006097 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006098 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006099 try {
Miaoa84611c2019-03-15 09:21:10 +08006100 if (phone != null) {
6101 return phone.hasMatchedTetherApnSetting();
6102 } else {
6103 return false;
6104 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006105 } finally {
6106 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006107 }
Junda Liu475951f2014-11-07 16:45:03 -08006108 }
6109
6110 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006111 * Enable or disable always reporting signal strength changes from radio.
6112 *
6113 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6114 */
6115 @Override
6116 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6117 enforceModifyPermission();
6118 enforceSystemCaller();
6119
6120 final long identity = Binder.clearCallingIdentity();
6121 final Phone phone = getPhone(subId);
6122 try {
6123 if (phone != null) {
6124 if (DBG) {
6125 log("setAlwaysReportSignalStrength: subId=" + subId
6126 + " isEnable=" + isEnable);
6127 }
6128 phone.setAlwaysReportSignalStrength(isEnable);
6129 } else {
6130 loge("setAlwaysReportSignalStrength: no phone found for subId="
6131 + subId);
6132 }
6133 } finally {
6134 Binder.restoreCallingIdentity(identity);
6135 }
6136 }
6137
6138 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006139 * Get the user enabled state of Mobile Data.
6140 *
6141 * TODO: remove and use isUserDataEnabled.
6142 * This can't be removed now because some vendor codes
6143 * calls through ITelephony directly while they should
6144 * use TelephonyManager.
6145 *
6146 * @return true on enabled
6147 */
6148 @Override
6149 public boolean getDataEnabled(int subId) {
6150 return isUserDataEnabled(subId);
6151 }
6152
6153 /**
6154 * Get whether mobile data is enabled per user setting.
6155 *
6156 * There are other factors deciding whether mobile data is actually enabled, but they are
6157 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006158 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006159 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006160 *
6161 * @return {@code true} if data is enabled else {@code false}
6162 */
6163 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006164 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006165 try {
6166 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6167 null);
6168 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006169 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6170 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006171 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006172
6173 final long identity = Binder.clearCallingIdentity();
6174 try {
6175 int phoneId = mSubscriptionController.getPhoneId(subId);
6176 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6177 Phone phone = PhoneFactory.getPhone(phoneId);
6178 if (phone != null) {
6179 boolean retVal = phone.isUserDataEnabled();
6180 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6181 return retVal;
6182 } else {
6183 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6184 return false;
6185 }
6186 } finally {
6187 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006188 }
6189 }
6190
6191 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006192 * Checks if the device is capable of mobile data by considering whether whether the
6193 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6194 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006195 *
Shuo Qian985d1232020-01-08 14:30:06 -08006196 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006197 */
6198 @Override
6199 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006200 try {
6201 try {
6202 mApp.enforceCallingOrSelfPermission(
6203 android.Manifest.permission.ACCESS_NETWORK_STATE,
6204 null);
6205 } catch (Exception e) {
6206 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6207 "isDataEnabled");
6208 }
6209 } catch (Exception e) {
6210 enforceReadPrivilegedPermission("isDataEnabled");
6211 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006212
6213 final long identity = Binder.clearCallingIdentity();
6214 try {
6215 int phoneId = mSubscriptionController.getPhoneId(subId);
6216 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6217 Phone phone = PhoneFactory.getPhone(phoneId);
6218 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006219 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006220 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6221 return retVal;
6222 } else {
6223 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6224 return false;
6225 }
6226 } finally {
6227 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006228 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006229 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006230
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006231 /**
6232 * Check if data is enabled for a specific reason
6233 * @param subId Subscription index
6234 * @param reason the reason the data enable change is taking place
6235 * @return {@code true} if the overall data is enabled; {@code false} if not.
6236 */
6237 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006238 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006239 @TelephonyManager.DataEnabledReason int reason) {
6240 try {
6241 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6242 null);
6243 } catch (Exception e) {
6244 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006245 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006246 }
6247
6248
6249 final long identity = Binder.clearCallingIdentity();
6250 try {
6251 int phoneId = mSubscriptionController.getPhoneId(subId);
6252 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006253 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006254 + " reason=" + reason);
6255 }
6256 Phone phone = PhoneFactory.getPhone(phoneId);
6257 if (phone != null) {
6258 boolean retVal;
6259 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6260 retVal = phone.isUserDataEnabled();
6261 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006262 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006263 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006264 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006265 return retVal;
6266 } else {
6267 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006268 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006269 + subId + " retVal=false");
6270 }
6271 return false;
6272 }
6273 } finally {
6274 Binder.restoreCallingIdentity(identity);
6275 }
6276 }
6277
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006278 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006279 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006280 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6281 // Skip the check if it's one of these special uids
6282 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6283 }
6284
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006285 //load access rules from carrier configs, and check those as well: b/139133814
6286 SubscriptionController subController = SubscriptionController.getInstance();
6287 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6288 || subController == null) return privilegeFromSim;
6289
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006290 PackageManager pkgMgr = phone.getContext().getPackageManager();
6291 String[] packages = pkgMgr.getPackagesForUid(uid);
6292
6293 final long identity = Binder.clearCallingIdentity();
6294 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006295 int subId = phone.getSubId();
6296 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6297 // A test override is in place for the privileges for this subId, so don't try to
6298 // read the subscription privileges.
6299 return privilegeFromSim;
6300 }
6301 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006302 SubscriptionManager subManager = (SubscriptionManager)
6303 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6304 for (String pkg : packages) {
6305 if (subManager.canManageSubscription(subInfo, pkg)) {
6306 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6307 }
6308 }
6309 return privilegeFromSim;
6310 } finally {
6311 Binder.restoreCallingIdentity(identity);
6312 }
6313 }
6314
6315 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6316 String pkgName) {
6317 //load access rules from carrier configs, and check those as well: b/139133814
6318 SubscriptionController subController = SubscriptionController.getInstance();
6319 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6320 || subController == null) return privilegeFromSim;
6321
6322 final long identity = Binder.clearCallingIdentity();
6323 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006324 int subId = phone.getSubId();
6325 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6326 // A test override is in place for the privileges for this subId, so don't try to
6327 // read the subscription privileges.
6328 return privilegeFromSim;
6329 }
6330 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006331 SubscriptionManager subManager = (SubscriptionManager)
6332 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6333 return subManager.canManageSubscription(subInfo, pkgName)
6334 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6335 } finally {
6336 Binder.restoreCallingIdentity(identity);
6337 }
6338 }
6339
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006340 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006341 public int getCarrierPrivilegeStatus(int subId) {
6342 final Phone phone = getPhone(subId);
6343 if (phone == null) {
6344 loge("getCarrierPrivilegeStatus: Invalid subId");
6345 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6346 }
6347 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006348 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006349 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006350 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6351 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006352
6353 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6354 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006355 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006356 }
Junda Liu29340342014-07-10 15:23:27 -07006357
6358 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006359 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006360 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006361 final Phone phone = getPhone(subId);
6362 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006363 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006364 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6365 }
6366 UiccProfile profile =
6367 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6368 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006369 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006370 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6371 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006372 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006373 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006374 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006375 }
6376
6377 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006378 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6379 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006380 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006381 }
6382
6383 int phoneId = SubscriptionManager.getPhoneId(subId);
6384 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006385 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006386 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006387 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6388 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006389 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6390 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6391 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006392 }
6393
6394 @Override
6395 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006396 if (TextUtils.isEmpty(pkgName))
6397 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006398 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6399 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6400 UiccCard card = UiccController.getInstance().getUiccCard(i);
6401 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006402 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006403 continue;
6404 }
6405
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006406 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6407 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6408 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006409 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6410 break;
6411 }
6412 }
6413
6414 return result;
Junda Liu29340342014-07-10 15:23:27 -07006415 }
Derek Tan89e89d42014-07-08 17:00:10 -07006416
6417 @Override
Junda Liue64de782015-04-16 17:19:16 -07006418 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6419 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6420 loge("phoneId " + phoneId + " is not valid.");
6421 return null;
6422 }
6423 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006424 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006425 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006426 return null ;
6427 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006428 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006429 }
6430
Amith Yamasani6e118872016-02-19 12:53:51 -08006431 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006432 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006433 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006434 List<String> privilegedPackages = new ArrayList<>();
6435 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006436 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6437 // has UICC in that slot.
6438 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006439 if (card.hasCarrierPrivilegeRules()) {
6440 if (packages == null) {
6441 // Only check packages in user 0 for now
6442 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006443 PackageManager.MATCH_DISABLED_COMPONENTS
6444 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006445 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006446 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006447 }
6448 for (int p = packages.size() - 1; p >= 0; p--) {
6449 PackageInfo pkgInfo = packages.get(p);
6450 if (pkgInfo != null && pkgInfo.packageName != null
6451 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006452 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006453 privilegedPackages.add(pkgInfo.packageName);
6454 }
6455 }
6456 }
6457 }
6458 return privilegedPackages;
6459 }
6460
chen xuf7e9fe82019-05-09 19:31:02 -07006461 @Override
6462 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006463 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6464
6465 final long identity = Binder.clearCallingIdentity();
6466
chen xuf7e9fe82019-05-09 19:31:02 -07006467 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006468 try {
6469 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6470 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6471 }
6472 } finally {
6473 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006474 }
6475 return privilegedPackages;
6476 }
6477
Wink Savilleb564aae2014-10-23 10:18:09 -07006478 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006479 final Phone phone = getPhone(subId);
6480 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006481 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006482 return null;
6483 }
6484 String iccId = card.getIccId();
6485 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006486 return null;
6487 }
6488 return iccId;
6489 }
6490
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006491 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006492 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6493 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006494 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006495 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006496
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006497 final long identity = Binder.clearCallingIdentity();
6498 try {
6499 final String iccId = getIccId(subId);
6500 final Phone phone = getPhone(subId);
6501 if (phone == null) {
6502 return false;
6503 }
6504 final String subscriberId = phone.getSubscriberId();
6505
6506 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006507 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006508 + subscriberId + " to " + number);
6509 }
6510
6511 if (TextUtils.isEmpty(iccId)) {
6512 return false;
6513 }
6514
6515 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6516
6517 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6518 if (alphaTag == null) {
6519 editor.remove(alphaTagPrefKey);
6520 } else {
6521 editor.putString(alphaTagPrefKey, alphaTag);
6522 }
6523
6524 // Record both the line number and IMSI for this ICCID, since we need to
6525 // track all merged IMSIs based on line number
6526 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6527 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6528 if (number == null) {
6529 editor.remove(numberPrefKey);
6530 editor.remove(subscriberPrefKey);
6531 } else {
6532 editor.putString(numberPrefKey, number);
6533 editor.putString(subscriberPrefKey, subscriberId);
6534 }
6535
6536 editor.commit();
6537 return true;
6538 } finally {
6539 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006540 }
Derek Tan7226c842014-07-02 17:42:23 -07006541 }
6542
6543 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006544 public String getLine1NumberForDisplay(int subId, String callingPackage,
6545 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006546 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006547 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006548 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006549 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006550 return null;
6551 }
Derek Tan97ebb422014-09-05 16:55:38 -07006552
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006553 final long identity = Binder.clearCallingIdentity();
6554 try {
6555 String iccId = getIccId(subId);
6556 if (iccId != null) {
6557 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6558 if (DBG_MERGE) {
6559 log("getLine1NumberForDisplay returning "
6560 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6561 }
6562 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006563 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006564 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6565 return null;
6566 } finally {
6567 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006568 }
Derek Tan7226c842014-07-02 17:42:23 -07006569 }
6570
6571 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006572 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6573 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006574 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006575 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006576 return null;
6577 }
Derek Tan97ebb422014-09-05 16:55:38 -07006578
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006579 final long identity = Binder.clearCallingIdentity();
6580 try {
6581 String iccId = getIccId(subId);
6582 if (iccId != null) {
6583 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6584 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6585 }
6586 return null;
6587 } finally {
6588 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006589 }
Derek Tan7226c842014-07-02 17:42:23 -07006590 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006591
6592 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006593 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6594 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006595 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6596 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006597 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006598 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006599 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006600 return null;
6601 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006602
Jordan Liub49b04b2019-05-06 14:45:15 -07006603 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6604 // the process, where TelephonyManager was instantiated.
6605 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006606 final long identity = Binder.clearCallingIdentity();
6607 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006608 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006609 final TelephonyManager tele = TelephonyManager.from(context);
6610 final SubscriptionManager sub = SubscriptionManager.from(context);
6611
6612 // Figure out what subscribers are currently active
6613 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006614
Jordan Liub49b04b2019-05-06 14:45:15 -07006615 // Only consider subs which match the current subId
6616 // This logic can be simplified. See b/131189269 for progress.
6617 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006618 activeSubscriberIds.add(tele.getSubscriberId(subId));
6619 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006620
6621 // First pass, find a number override for an active subscriber
6622 String mergeNumber = null;
6623 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6624 for (String key : prefs.keySet()) {
6625 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6626 final String subscriberId = (String) prefs.get(key);
6627 if (activeSubscriberIds.contains(subscriberId)) {
6628 final String iccId = key.substring(
6629 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6630 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6631 mergeNumber = (String) prefs.get(numberKey);
6632 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006633 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006634 + " for active subscriber " + subscriberId);
6635 }
6636 if (!TextUtils.isEmpty(mergeNumber)) {
6637 break;
6638 }
6639 }
6640 }
6641 }
6642
6643 // Shortcut when no active merged subscribers
6644 if (TextUtils.isEmpty(mergeNumber)) {
6645 return null;
6646 }
6647
6648 // Second pass, find all subscribers under that line override
6649 final ArraySet<String> result = new ArraySet<>();
6650 for (String key : prefs.keySet()) {
6651 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6652 final String number = (String) prefs.get(key);
6653 if (mergeNumber.equals(number)) {
6654 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6655 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6656 final String subscriberId = (String) prefs.get(subscriberKey);
6657 if (!TextUtils.isEmpty(subscriberId)) {
6658 result.add(subscriberId);
6659 }
6660 }
6661 }
6662 }
6663
6664 final String[] resultArray = result.toArray(new String[result.size()]);
6665 Arrays.sort(resultArray);
6666 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006667 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006668 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6669 }
6670 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006671 } finally {
6672 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006673 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006674 }
6675
6676 @Override
zoey chen38003472019-12-13 17:16:31 +08006677 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6678 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006679
6680 final long identity = Binder.clearCallingIdentity();
6681 try {
6682 final TelephonyManager telephonyManager = mApp.getSystemService(
6683 TelephonyManager.class);
6684 String subscriberId = telephonyManager.getSubscriberId(subId);
6685 if (subscriberId == null) {
6686 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006687 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006688 + subId);
6689 }
6690 return null;
6691 }
6692
6693 final SubscriptionInfo info = SubscriptionController.getInstance()
6694 .getSubscriptionInfo(subId);
6695 final ParcelUuid groupUuid = info.getGroupUuid();
6696 // If it doesn't belong to any group, return just subscriberId of itself.
6697 if (groupUuid == null) {
6698 return new String[]{subscriberId};
6699 }
6700
6701 // Get all subscriberIds from the group.
6702 final List<String> mergedSubscriberIds = new ArrayList<>();
6703 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006704 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006705 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006706 for (SubscriptionInfo subInfo : groupInfos) {
6707 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6708 if (subscriberId != null) {
6709 mergedSubscriberIds.add(subscriberId);
6710 }
6711 }
6712
6713 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6714 } finally {
6715 Binder.restoreCallingIdentity(identity);
6716
6717 }
6718 }
6719
6720 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006721 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006722 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006723 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006724
6725 final long identity = Binder.clearCallingIdentity();
6726 try {
6727 final Phone phone = getPhone(subId);
6728 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6729 } finally {
6730 Binder.restoreCallingIdentity(identity);
6731 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006732 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006733
6734 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006735 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006736 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6737 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006738 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6739 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006740
6741 final long identity = Binder.clearCallingIdentity();
6742 try {
6743 final Phone phone = getPhone(subId);
6744 if (phone == null) {
6745 return false;
6746 }
6747 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6748 cdmaNonRoamingList);
6749 } finally {
6750 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006751 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006752 }
6753
6754 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006755 @Deprecated
6756 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6757 enforceModifyPermission();
6758
6759 int returnValue = 0;
6760 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006761 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006762 if(result.exception == null) {
6763 if (result.result != null) {
6764 byte[] responseData = (byte[])(result.result);
6765 if(responseData.length > oemResp.length) {
6766 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6767 responseData.length + "bytes. Buffer Size is " +
6768 oemResp.length + "bytes.");
6769 }
6770 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6771 returnValue = responseData.length;
6772 }
6773 } else {
6774 CommandException ex = (CommandException) result.exception;
6775 returnValue = ex.getCommandError().ordinal();
6776 if(returnValue > 0) returnValue *= -1;
6777 }
6778 } catch (RuntimeException e) {
6779 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6780 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6781 if(returnValue > 0) returnValue *= -1;
6782 }
6783
6784 return returnValue;
6785 }
6786
6787 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006788 public void setRadioCapability(RadioAccessFamily[] rafs) {
6789 try {
6790 ProxyController.getInstance().setRadioCapability(rafs);
6791 } catch (RuntimeException e) {
6792 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6793 }
6794 }
6795
6796 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006797 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006798 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006799 try {
6800 TelephonyPermissions
6801 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6802 mApp, phone.getSubId(), "getRadioAccessFamily");
6803 } catch (SecurityException e) {
6804 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6805 throw e;
6806 }
chen xub97461a2018-10-26 14:17:57 -07006807 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006808 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006809 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006810 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006811 final long identity = Binder.clearCallingIdentity();
6812 try {
chen xub97461a2018-10-26 14:17:57 -07006813 TelephonyPermissions
6814 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6815 mApp, phone.getSubId(), "getRadioAccessFamily");
6816 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006817 } finally {
6818 Binder.restoreCallingIdentity(identity);
6819 }
chen xub97461a2018-10-26 14:17:57 -07006820 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006821 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006822
6823 @Override
6824 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006825 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006826 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006827
6828 final long identity = Binder.clearCallingIdentity();
6829 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006830 ImsManager.getInstance(defaultPhone.getContext(),
6831 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006832 } finally {
6833 Binder.restoreCallingIdentity(identity);
6834 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006835 }
6836
6837 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006838 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006839 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006840 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6841 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006842 return false;
6843 }
Svet Ganovb320e182015-04-16 12:30:10 -07006844
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006845 final long identity = Binder.clearCallingIdentity();
6846 try {
6847 // Check the user preference and the system-level IMS setting. Even if the user has
6848 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6849 // In the long run, we may instead need to check if there exists a connection service
6850 // which can support video calling.
6851 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006852 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006853 return imsManager.isVtEnabledByPlatform()
6854 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6855 && imsManager.isVtEnabledByUser();
6856 } finally {
6857 Binder.restoreCallingIdentity(identity);
6858 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006859 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006860
Andrew Leea1239f22015-03-02 17:44:07 -08006861 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006862 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6863 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006864 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006865 mApp, subId, callingPackage, callingFeatureId,
6866 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006867 return false;
6868 }
6869
6870 final long identity = Binder.clearCallingIdentity();
6871 try {
6872 CarrierConfigManager configManager =
6873 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006874 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006875 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6876 } finally {
6877 Binder.restoreCallingIdentity(identity);
6878 }
Andrew Leea1239f22015-03-02 17:44:07 -08006879 }
6880
6881 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006882 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006883 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006884 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006885 return false;
6886 }
6887
6888 final long identity = Binder.clearCallingIdentity();
6889 try {
6890 CarrierConfigManager configManager =
6891 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006892 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006893 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6894 } finally {
6895 Binder.restoreCallingIdentity(identity);
6896 }
Andrew Leea1239f22015-03-02 17:44:07 -08006897 }
6898
Andrew Lee9431b832015-03-09 18:46:45 -07006899 @Override
6900 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006901 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006902 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006903 }
6904
6905 @Override
6906 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006907 final long identity = Binder.clearCallingIdentity();
6908 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006909 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006910 } finally {
6911 Binder.restoreCallingIdentity(identity);
6912 }
Andrew Lee9431b832015-03-09 18:46:45 -07006913 }
6914
Hall Liuf6668912018-10-31 17:05:23 -07006915 /**
6916 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6917 * support for the feature and device firmware support.
6918 *
6919 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6920 */
6921 @Override
6922 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006923 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006924 final Phone phone = getPhone(subscriptionId);
6925 if (phone == null) {
6926 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6927 return false;
6928 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006929 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006930 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006931 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6932 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006933 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006934 return isCarrierSupported && isDeviceSupported;
6935 } finally {
6936 Binder.restoreCallingIdentity(identity);
6937 }
Hall Liu98187582018-01-22 19:15:32 -08006938 }
6939
Hall Liuf6668912018-10-31 17:05:23 -07006940 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006941 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6942 * RTT setting, will return true if the device and carrier both support RTT.
6943 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006944 */
6945 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006946 final long identity = Binder.clearCallingIdentity();
6947 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006948 boolean isRttSupported = isRttSupported(subscriptionId);
6949 boolean isUserRttSettingOn = Settings.Secure.getInt(
6950 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6951 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6952 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6953 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006954 } finally {
6955 Binder.restoreCallingIdentity(identity);
6956 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006957 }
6958
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006959 @Deprecated
6960 @Override
6961 public String getDeviceId(String callingPackage) {
6962 return getDeviceIdWithFeature(callingPackage, null);
6963 }
6964
Sanket Padawe7310cc72015-01-14 09:53:20 -08006965 /**
6966 * Returns the unique device ID of phone, for example, the IMEI for
6967 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6968 *
6969 * <p>Requires Permission:
6970 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6971 */
6972 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006973 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006974 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006975 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006976 return null;
6977 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006978 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006979 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006980 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006981 return null;
6982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006983
6984 final long identity = Binder.clearCallingIdentity();
6985 try {
6986 return phone.getDeviceId();
6987 } finally {
6988 Binder.restoreCallingIdentity(identity);
6989 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006990 }
6991
Ping Sunc67b7c22016-03-02 19:16:45 +08006992 /**
6993 * {@hide}
6994 * Returns the IMS Registration Status on a particular subid
6995 *
6996 * @param subId
6997 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006998 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006999 Phone phone = getPhone(subId);
7000 if (phone != null) {
7001 return phone.isImsRegistered();
7002 } else {
7003 return false;
7004 }
7005 }
7006
Santos Cordon7a1885b2015-02-03 11:15:19 -08007007 @Override
7008 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007009 final long identity = Binder.clearCallingIdentity();
7010 try {
7011 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7012 } finally {
7013 Binder.restoreCallingIdentity(identity);
7014 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007015 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007016
Tyler Gunnf70ed162019-04-03 15:28:53 -07007017 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007018 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007019 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007020 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007021 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007022 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7023 }
7024 final long identity = Binder.clearCallingIdentity();
7025 try {
7026 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7027 } finally {
7028 Binder.restoreCallingIdentity(identity);
7029 }
7030 }
7031
7032 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007033 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007034 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7035 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007036 final long identity = Binder.clearCallingIdentity();
7037 try {
7038 Phone phone = getPhone(subscriptionId);
7039 if (phone == null) {
7040 return null;
7041 }
7042 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7043 } finally {
7044 Binder.restoreCallingIdentity(identity);
7045 }
7046 }
7047
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007048 /**
7049 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007050 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007051 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007052 final long identity = Binder.clearCallingIdentity();
7053 try {
7054 Phone phone = getPhone(subId);
7055 if (phone != null) {
7056 return phone.isWifiCallingEnabled();
7057 } else {
7058 return false;
7059 }
7060 } finally {
7061 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007062 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007063 }
7064
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007065 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007066 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007067 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007068 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007069 final long identity = Binder.clearCallingIdentity();
7070 try {
7071 Phone phone = getPhone(subId);
7072 if (phone != null) {
7073 return phone.isVideoEnabled();
7074 } else {
7075 return false;
7076 }
7077 } finally {
7078 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007079 }
7080 }
7081
7082 /**
7083 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7084 * defined in {@link ImsRegistrationImplBase}.
7085 */
7086 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007087 final long identity = Binder.clearCallingIdentity();
7088 try {
7089 Phone phone = getPhone(subId);
7090 if (phone != null) {
7091 return phone.getImsRegistrationTech();
7092 } else {
7093 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7094 }
7095 } finally {
7096 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007097 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007098 }
7099
Stuart Scott8eef64f2015-04-08 15:13:54 -07007100 @Override
7101 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007102 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007103 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7104 return;
7105 }
7106
Svet Ganovcc087f82015-05-12 20:35:54 -07007107 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007108
Svet Ganovcc087f82015-05-12 20:35:54 -07007109 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007110 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7111 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007112 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007113 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007114 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007115 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007116 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7117 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007118 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007119 // There has been issues when Sms raw table somehow stores orphan
7120 // fragments. They lead to garbled message when new fragments come
7121 // in and combined with those stale ones. In case this happens again,
7122 // user can reset all network settings which will clean up this table.
7123 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007124 // Clean up IMS settings as well here.
7125 int slotId = getSlotIndex(subId);
7126 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7127 ImsManager.getInstance(mApp, slotId).factoryReset();
7128 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007129
7130 // Erase modem config if erase modem on network setting is enabled.
7131 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7132 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7133 if (configValue != null && Boolean.parseBoolean(configValue)) {
7134 sendEraseModemConfig(getDefaultPhone());
7135 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007136 } finally {
7137 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007138 }
7139 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007140
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007141 private void cleanUpSmsRawTable(Context context) {
7142 ContentResolver resolver = context.getContentResolver();
7143 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7144 resolver.delete(uri, null, null);
7145 }
7146
Narayan Kamath1c496c22015-04-16 14:40:19 +01007147 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007148 public String getSimLocaleForSubscriber(int subId) {
7149 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7150 final Phone phone = getPhone(subId);
7151 if (phone == null) {
7152 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007153 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007154 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007155 final long identity = Binder.clearCallingIdentity();
7156 try {
chen xu5d3637b2019-01-21 23:31:38 -08007157 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007158 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007159 if (info == null) {
7160 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7161 return null;
7162 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007163 // Try and fetch the locale from the carrier properties or from the SIM language
7164 // preferences (EF-PL and EF-LI)...
7165 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007166 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007167 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7168 if (localeFromDefaultSim != null) {
7169 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7170 if (DBG) log("Using locale from subId: " + subId + " locale: "
7171 + localeFromDefaultSim);
7172 return localeFromDefaultSim.toLanguageTag();
7173 } else {
7174 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007175 }
7176 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007177
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007178 // The SIM language preferences only store a language (e.g. fr = French), not an
7179 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7180 // the SIM and carrier preferences does not include a country we add the country
7181 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007182 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007183 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007184 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007185 return mccLocale.toLanguageTag();
7186 }
7187
7188 if (DBG) log("No locale found - returning null");
7189 return null;
7190 } finally {
7191 Binder.restoreCallingIdentity(identity);
7192 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007193 }
7194
7195 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007196 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007197 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007198 }
7199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007200 /**
7201 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7202 */
7203 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007204 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007205 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007206 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007207
Chenjie Yu1ba97252018-01-11 18:16:20 -08007208 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007209 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007210
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007211 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007212 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7213 * representing the state of the modem.
7214 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007215 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7216 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007217 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007218 */
7219 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007220 public void requestModemActivityInfo(ResultReceiver result) {
7221 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007222 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007223
7224 final long identity = Binder.clearCallingIdentity();
7225 try {
sqian1a1be542020-03-05 11:37:28 -08007226 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007227 } finally {
7228 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007229 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007230 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007231
Siddharth Rayb8114062018-06-17 15:02:38 -07007232 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7233 // less than total activity duration.
7234 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7235 if (info == null) {
7236 return false;
7237 }
7238 int activityDurationMs =
7239 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7240 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007241 int[] txTimeMs = info.getTransmitTimeMillis();
7242 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7243 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007244 }
7245 return (info.isValid()
7246 && (info.getSleepTimeMillis() <= activityDurationMs)
7247 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007248 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007249 && (totalTxTimeMs <= activityDurationMs));
7250 }
7251
Jack Yu85bd38a2015-11-09 11:34:32 -08007252 /**
7253 * {@hide}
7254 * Returns the service state information on specified subscription.
7255 */
7256 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007257 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7258 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007259 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007260 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007261 return null;
7262 }
7263
Hall Liuf19c44f2018-11-27 14:38:17 -08007264 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7265 LocationAccessPolicy.checkLocationPermission(mApp,
7266 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7267 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007268 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007269 .setCallingPid(Binder.getCallingPid())
7270 .setCallingUid(Binder.getCallingUid())
7271 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007272 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007273 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7274 .build());
7275
7276 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7277 LocationAccessPolicy.checkLocationPermission(mApp,
7278 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7279 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007280 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007281 .setCallingPid(Binder.getCallingPid())
7282 .setCallingUid(Binder.getCallingUid())
7283 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007284 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007285 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7286 .build());
7287 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7288 boolean hasFinePermission =
7289 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7290 boolean hasCoarsePermission =
7291 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007293 final long identity = Binder.clearCallingIdentity();
7294 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007295 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7296 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7297 Rlog.d(LOG_TAG,
7298 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7299 return null;
7300 }
7301
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007302 final Phone phone = getPhone(subId);
7303 if (phone == null) {
7304 return null;
7305 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007306
Hall Liuf19c44f2018-11-27 14:38:17 -08007307 ServiceState ss = phone.getServiceState();
7308
7309 // Scrub out the location info in ServiceState depending on what level of access
7310 // the caller has.
7311 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007312 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7313 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007314 } finally {
7315 Binder.restoreCallingIdentity(identity);
7316 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007317 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007318
7319 /**
7320 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7321 *
7322 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7323 * voicemail ringtone.
7324 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7325 * PhoneAccount.
7326 */
7327 @Override
7328 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007329 final long identity = Binder.clearCallingIdentity();
7330 try {
7331 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7332 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007333 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007334 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007335
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007336 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7337 } finally {
7338 Binder.restoreCallingIdentity(identity);
7339 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007340 }
7341
7342 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007343 * Sets the per-account voicemail ringtone.
7344 *
7345 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7346 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7347 *
7348 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7349 * voicemail ringtone.
7350 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7351 * PhoneAccount.
7352 */
7353 @Override
7354 public void setVoicemailRingtoneUri(String callingPackage,
7355 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007356 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007357 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007358 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7359 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7361 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7362 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007363 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007364
7365 final long identity = Binder.clearCallingIdentity();
7366 try {
7367 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7368 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007369 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007370 }
7371 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7372 } finally {
7373 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007374 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007375 }
7376
7377 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007378 * Returns whether vibration is set for voicemail notification in Phone settings.
7379 *
7380 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7381 * voicemail vibration setting.
7382 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7383 */
7384 @Override
7385 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007386 final long identity = Binder.clearCallingIdentity();
7387 try {
7388 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7389 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007390 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007391 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007392
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007393 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7394 } finally {
7395 Binder.restoreCallingIdentity(identity);
7396 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007397 }
7398
Youhan Wange64578a2016-05-02 15:32:42 -07007399 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007400 * Sets the per-account voicemail vibration.
7401 *
7402 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7403 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7404 *
7405 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7406 * voicemail vibration setting.
7407 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7408 * specific PhoneAccount.
7409 */
7410 @Override
7411 public void setVoicemailVibrationEnabled(String callingPackage,
7412 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007413 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007414 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007415 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7416 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7418 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7419 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007420 }
7421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007422 final long identity = Binder.clearCallingIdentity();
7423 try {
7424 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7425 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007426 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007427 }
7428 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7429 } finally {
7430 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007431 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007432 }
7433
7434 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007435 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7436 *
7437 * @throws SecurityException if the caller does not have the required permission
7438 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007439 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007440 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007441 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007442 }
7443
7444 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007445 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7446 * permission.
7447 *
7448 * @throws SecurityException if the caller does not have the required permission
7449 */
7450 private void enforceSendSmsPermission() {
7451 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7452 }
7453
7454 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007455 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007456 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007457 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007458 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007459 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007460 final long identity = Binder.clearCallingIdentity();
7461 try {
7462 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007463 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 if (componentName == null) {
7465 throw new SecurityException(
7466 "Caller not current active visual voicemail package[null]");
7467 }
7468 String vvmPackage = componentName.getPackageName();
7469 if (!callingPackage.equals(vvmPackage)) {
7470 throw new SecurityException("Caller not current active visual voicemail package["
7471 + vvmPackage + "]");
7472 }
7473 } finally {
7474 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007475 }
7476 }
7477
7478 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007479 * Return the application ID for the app type.
7480 *
7481 * @param subId the subscription ID that this request applies to.
7482 * @param appType the uicc app type.
7483 * @return Application ID for specificied app type, or null if no uicc.
7484 */
7485 @Override
7486 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007487 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007488 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489
7490 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007491 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007492 if (phone == null) {
7493 return null;
7494 }
7495 String aid = null;
7496 try {
7497 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7498 .getApplicationByType(appType).getAid();
7499 } catch (Exception e) {
7500 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7501 }
7502 return aid;
7503 } finally {
7504 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007505 }
Youhan Wange64578a2016-05-02 15:32:42 -07007506 }
7507
Youhan Wang4001d252016-05-11 10:29:41 -07007508 /**
7509 * Return the Electronic Serial Number.
7510 *
7511 * @param subId the subscription ID that this request applies to.
7512 * @return ESN or null if error.
7513 */
7514 @Override
7515 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007516 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007517 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518
7519 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007520 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521 if (phone == null) {
7522 return null;
7523 }
7524 String esn = null;
7525 try {
7526 esn = phone.getEsn();
7527 } catch (Exception e) {
7528 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7529 }
7530 return esn;
7531 } finally {
7532 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007533 }
Youhan Wang4001d252016-05-11 10:29:41 -07007534 }
7535
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007536 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007537 * Return the Preferred Roaming List Version.
7538 *
7539 * @param subId the subscription ID that this request applies to.
7540 * @return PRLVersion or null if error.
7541 */
7542 @Override
7543 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007544 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007545 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007546
7547 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007548 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007549 if (phone == null) {
7550 return null;
7551 }
7552 String cdmaPrlVersion = null;
7553 try {
7554 cdmaPrlVersion = phone.getCdmaPrlVersion();
7555 } catch (Exception e) {
7556 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7557 }
7558 return cdmaPrlVersion;
7559 } finally {
7560 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007561 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007562 }
7563
7564 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007565 * Get snapshot of Telephony histograms
7566 * @return List of Telephony histograms
7567 * @hide
7568 */
7569 @Override
7570 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7572 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007573
7574 final long identity = Binder.clearCallingIdentity();
7575 try {
7576 return RIL.getTelephonyRILTimingHistograms();
7577 } finally {
7578 Binder.restoreCallingIdentity(identity);
7579 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007580 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007581
7582 /**
7583 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007584 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7585 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007586 * Require system privileges. In the future we may add this to carrier APIs.
7587 *
Michele Berionne482f8202018-11-27 18:57:59 -08007588 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007589 */
7590 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007591 @TelephonyManager.SetCarrierRestrictionResult
7592 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007593 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007594 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007595
Michele Berionne482f8202018-11-27 18:57:59 -08007596 if (carrierRestrictionRules == null) {
7597 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007598 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007599
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600 final long identity = Binder.clearCallingIdentity();
7601 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007602 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007603 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007604 } finally {
7605 Binder.restoreCallingIdentity(identity);
7606 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007607 }
7608
7609 /**
7610 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007611 * Get the allowed carrier list and the excluded carrier list, including the priority between
7612 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007613 * Require system privileges. In the future we may add this to carrier APIs.
7614 *
Michele Berionne482f8202018-11-27 18:57:59 -08007615 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007616 */
7617 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007618 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007619 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007620 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007621
7622 final long identity = Binder.clearCallingIdentity();
7623 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007624 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7625 if (response instanceof CarrierRestrictionRules) {
7626 return (CarrierRestrictionRules) response;
7627 }
7628 // Response is an Exception of some kind,
7629 // which is signalled to the user as a NULL retval
7630 return null;
7631 } catch (Exception e) {
7632 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7633 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007634 } finally {
7635 Binder.restoreCallingIdentity(identity);
7636 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007637 }
7638
fionaxu59545b42016-05-25 15:53:37 -07007639 /**
fionaxu59545b42016-05-25 15:53:37 -07007640 * Action set from carrier signalling broadcast receivers to enable/disable radio
7641 * @param subId the subscription ID that this action applies to.
7642 * @param enabled control enable or disable radio.
7643 * {@hide}
7644 */
7645 @Override
7646 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7647 enforceModifyPermission();
7648 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007649
7650 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007651 if (phone == null) {
7652 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7653 return;
7654 }
7655 try {
7656 phone.carrierActionSetRadioEnabled(enabled);
7657 } catch (Exception e) {
7658 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007659 } finally {
7660 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007661 }
7662 }
7663
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007664 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007665 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7666 * network status based on which carrier apps could apply actions accordingly,
7667 * enable/disable default url handler for example.
7668 *
7669 * @param subId the subscription ID that this action applies to.
7670 * @param report control start/stop reporting the default network status.
7671 * {@hide}
7672 */
7673 @Override
7674 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7675 enforceModifyPermission();
7676 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007677
7678 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007679 if (phone == null) {
7680 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7681 return;
7682 }
7683 try {
7684 phone.carrierActionReportDefaultNetworkStatus(report);
7685 } catch (Exception e) {
7686 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007687 } finally {
7688 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007689 }
7690 }
7691
7692 /**
fionaxud9622282017-07-17 17:51:30 -07007693 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7694 * @param subId the subscription ID that this action applies to.
7695 * {@hide}
7696 */
7697 @Override
7698 public void carrierActionResetAll(int subId) {
7699 enforceModifyPermission();
7700 final Phone phone = getPhone(subId);
7701 if (phone == null) {
7702 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7703 return;
7704 }
7705 try {
7706 phone.carrierActionResetAll();
7707 } catch (Exception e) {
7708 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7709 }
7710 }
7711
7712 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007713 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7714 * bug report is being generated.
7715 */
7716 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007717 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007718 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7719 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007720 writer.println("Permission Denial: can't dump Phone from pid="
7721 + Binder.getCallingPid()
7722 + ", uid=" + Binder.getCallingUid()
7723 + "without permission "
7724 + android.Manifest.permission.DUMP);
7725 return;
7726 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007727 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007728 }
Jack Yueb89b242016-06-22 13:27:47 -07007729
Brad Ebingerdac2f002018-04-03 15:17:52 -07007730 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007731 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7732 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7733 @NonNull String[] args) {
7734 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7735 this, in.getFileDescriptor(), out.getFileDescriptor(),
7736 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007737 }
7738
Jack Yueb89b242016-06-22 13:27:47 -07007739 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007740 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007741 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007742 * @param reason the reason the data enable change is taking place
7743 * @param enabled True if enabling the data, otherwise disabling.
7744 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007745 */
7746 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007747 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007748 boolean enabled) {
7749 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7750 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7751 try {
7752 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007753 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007754 } catch (SecurityException se) {
7755 enforceModifyPermission();
7756 }
7757 } else {
7758 enforceModifyPermission();
7759 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007760
7761 final long identity = Binder.clearCallingIdentity();
7762 try {
7763 Phone phone = getPhone(subId);
7764 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007765 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7766 phone.carrierActionSetMeteredApnsEnabled(enabled);
7767 } else {
7768 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7769 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007770 }
7771 } finally {
7772 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007773 }
7774 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007775
7776 /**
7777 * Get Client request stats
7778 * @return List of Client Request Stats
7779 * @hide
7780 */
7781 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007782 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7783 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007784 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007785 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007786 return null;
7787 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007788 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007789
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007790 final long identity = Binder.clearCallingIdentity();
7791 try {
7792 if (phone != null) {
7793 return phone.getClientRequestStats();
7794 }
7795
7796 return null;
7797 } finally {
7798 Binder.restoreCallingIdentity(identity);
7799 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007800 }
7801
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007802 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007803 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007804 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007805 }
Jack Yueb4124c2017-02-16 15:32:43 -08007806
7807 /**
Grace Chen70990072017-03-24 17:21:30 -07007808 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007809 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007810 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007811 * @param state State of SIM (power down, power up, pass through)
7812 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7813 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7814 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007815 *
7816 **/
7817 @Override
Grace Chen70990072017-03-24 17:21:30 -07007818 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007819 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007820 Phone phone = PhoneFactory.getPhone(slotIndex);
7821
vagdeviaf9a5b92018-08-15 16:01:53 -07007822 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7823
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007824 final long identity = Binder.clearCallingIdentity();
7825 try {
7826 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007827 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007828 }
7829 } finally {
7830 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007831 }
7832 }
Shuo Qiandd210312017-04-12 22:11:33 +00007833
Tyler Gunn65d45c22017-06-05 11:22:26 -07007834 private boolean isUssdApiAllowed(int subId) {
7835 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007836 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007837 if (configManager == null) {
7838 return false;
7839 }
7840 PersistableBundle pb = configManager.getConfigForSubId(subId);
7841 if (pb == null) {
7842 return false;
7843 }
7844 return pb.getBoolean(
7845 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7846 }
7847
Shuo Qiandd210312017-04-12 22:11:33 +00007848 /**
7849 * Check if phone is in emergency callback mode
7850 * @return true if phone is in emergency callback mode
7851 * @param subId sub id
7852 */
goneil9c5f4872017-12-05 14:07:56 -08007853 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007854 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007855 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007856 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007857
7858 final long identity = Binder.clearCallingIdentity();
7859 try {
7860 if (phone != null) {
7861 return phone.isInEcm();
7862 } else {
7863 return false;
7864 }
7865 } finally {
7866 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007867 }
7868 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007869
7870 /**
7871 * Get the current signal strength information for the given subscription.
7872 * Because this information is not updated when the device is in a low power state
7873 * it should not be relied-upon to be current.
7874 * @param subId Subscription index
7875 * @return the most recent cached signal strength info from the modem
7876 */
7877 @Override
7878 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007879 final long identity = Binder.clearCallingIdentity();
7880 try {
7881 Phone p = getPhone(subId);
7882 if (p == null) {
7883 return null;
7884 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007885
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007886 return p.getSignalStrength();
7887 } finally {
7888 Binder.restoreCallingIdentity(identity);
7889 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007890 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007891
Pengquan Meng77b7f132018-08-22 14:49:57 -07007892 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007893 * Get the current modem radio state for the given slot.
7894 * @param slotIndex slot index.
7895 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007896 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007897 * @return the current radio power state from the modem
7898 */
7899 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007900 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007901 Phone phone = PhoneFactory.getPhone(slotIndex);
7902 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007903 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7904 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007905 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7906 }
7907
7908 final long identity = Binder.clearCallingIdentity();
7909 try {
7910 return phone.getRadioPowerState();
7911 } finally {
7912 Binder.restoreCallingIdentity(identity);
7913 }
7914 }
7915 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7916 }
7917
7918 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007919 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7920 *
7921 * <p>Requires one of the following permissions:
7922 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7923 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7924 * privileges.
7925 *
7926 * @param subId subscription id
7927 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7928 * {@code false}.
7929 */
7930 @Override
7931 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07007932 try {
7933 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7934 null);
7935 } catch (Exception e) {
7936 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7937 mApp, subId, "isDataRoamingEnabled");
7938 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007939
Pengquan Menga1bb6272018-09-06 09:59:22 -07007940 boolean isEnabled = false;
7941 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007942 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007943 Phone phone = getPhone(subId);
7944 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007945 } finally {
7946 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007947 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007948 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007949 }
7950
7951
7952 /**
7953 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7954 *
7955 * <p> Requires permission:
7956 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7957 * privileges.
7958 *
7959 * @param subId subscription id
7960 * @param isEnabled {@code true} means enable, {@code false} means disable.
7961 */
7962 @Override
7963 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007964 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7965 mApp, subId, "setDataRoamingEnabled");
7966
Pengquan Menga1bb6272018-09-06 09:59:22 -07007967 final long identity = Binder.clearCallingIdentity();
7968 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007969 Phone phone = getPhone(subId);
7970 if (phone != null) {
7971 phone.setDataRoamingEnabled(isEnabled);
7972 }
7973 } finally {
7974 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007975 }
7976 }
7977
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007978 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007979 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007980 TelephonyPermissions
7981 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007982 mApp, subId, "isManualNetworkSelectionAllowed");
7983
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007984 boolean isAllowed = true;
7985 final long identity = Binder.clearCallingIdentity();
7986 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007987 Phone phone = getPhone(subId);
7988 if (phone != null) {
7989 isAllowed = phone.isCspPlmnEnabled();
7990 }
7991 } finally {
7992 Binder.restoreCallingIdentity(identity);
7993 }
7994 return isAllowed;
7995 }
7996
7997 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007998 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07007999 // Verify that tha callingPackage belongs to the calling UID
8000 mApp.getSystemService(AppOpsManager.class)
8001 .checkPackage(Binder.getCallingUid(), callingPackage);
8002
Jordan Liu1e142fc2019-04-22 15:10:43 -07008003 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008004 try {
8005 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008006 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008007 } catch (SecurityException e) {
8008 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8009 // has carrier privileges on an active UICC
8010 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8011 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008012 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008013 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008014 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008015
8016 final long identity = Binder.clearCallingIdentity();
8017 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008018 UiccController uiccController = UiccController.getInstance();
8019 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008020 if (hasReadPermission) {
8021 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008022 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008023
8024 // Remove private info if the caller doesn't have access
8025 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8026 for (UiccCardInfo cardInfo : cardInfos) {
8027 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8028 // is available
8029 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8030 if (card == null || card.getUiccProfile() == null) {
8031 // assume no access if the card or profile is unavailable
8032 filteredInfos.add(cardInfo.getUnprivileged());
8033 continue;
8034 }
8035 UiccProfile profile = card.getUiccProfile();
8036 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8037 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8038 filteredInfos.add(cardInfo);
8039 } else {
8040 filteredInfos.add(cardInfo.getUnprivileged());
8041 }
8042 }
8043 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008044 } finally {
8045 Binder.restoreCallingIdentity(identity);
8046 }
8047 }
8048
8049 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008050 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008051 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008053 final long identity = Binder.clearCallingIdentity();
8054 try {
8055 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8056 if (slots == null) {
8057 Rlog.i(LOG_TAG, "slots is null.");
8058 return null;
8059 }
8060
8061 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8062 for (int i = 0; i < slots.length; i++) {
8063 UiccSlot slot = slots[i];
8064 if (slot == null) {
8065 continue;
8066 }
8067
Jordan Liu7be7e652019-05-06 18:55:02 +00008068 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008069 UiccCard card = slot.getUiccCard();
8070 if (card != null) {
8071 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008072 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008073 cardId = slot.getEid();
8074 if (TextUtils.isEmpty(cardId)) {
8075 cardId = slot.getIccId();
8076 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008077 }
8078
Jordan Liu857451f2019-05-09 16:35:35 -07008079 if (cardId != null) {
8080 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8081 // if cardId is an EID, it's all digits so this is fine
8082 cardId = IccUtils.stripTrailingFs(cardId);
8083 }
8084
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008085 int cardState = 0;
8086 switch (slot.getCardState()) {
8087 case CARDSTATE_ABSENT:
8088 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8089 break;
8090 case CARDSTATE_PRESENT:
8091 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8092 break;
8093 case CARDSTATE_ERROR:
8094 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8095 break;
8096 case CARDSTATE_RESTRICTED:
8097 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8098 break;
8099 default:
8100 break;
8101
8102 }
8103
8104 infos[i] = new UiccSlotInfo(
8105 slot.isActive(),
8106 slot.isEuicc(),
8107 cardId,
8108 cardState,
8109 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008110 slot.isExtendedApduSupported(),
8111 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008112 }
8113 return infos;
8114 } finally {
8115 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008116 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008117 }
8118
8119 @Override
8120 public boolean switchSlots(int[] physicalSlots) {
8121 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008122
8123 final long identity = Binder.clearCallingIdentity();
8124 try {
8125 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8126 } finally {
8127 Binder.restoreCallingIdentity(identity);
8128 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008129 }
Jack Yu4c988042018-02-27 15:30:01 -08008130
8131 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008132 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008133 final long identity = Binder.clearCallingIdentity();
8134 try {
8135 return UiccController.getInstance().getCardIdForDefaultEuicc();
8136 } finally {
8137 Binder.restoreCallingIdentity(identity);
8138 }
8139 }
8140
Pengquan Meng85728fb2018-03-12 16:31:21 -07008141 /**
goneil47ffb6e2018-04-06 15:40:58 -07008142 * A test API to reload the UICC profile.
8143 *
8144 * <p>Requires that the calling app has permission
8145 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8146 * @hide
8147 */
8148 @Override
8149 public void refreshUiccProfile(int subId) {
8150 enforceModifyPermission();
8151
8152 final long identity = Binder.clearCallingIdentity();
8153 try {
8154 Phone phone = getPhone(subId);
8155 if (phone == null) {
8156 return;
8157 }
8158 UiccCard uiccCard = phone.getUiccCard();
8159 if (uiccCard == null) {
8160 return;
8161 }
8162 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8163 if (uiccProfile == null) {
8164 return;
8165 }
8166 uiccProfile.refresh();
8167 } finally {
8168 Binder.restoreCallingIdentity(identity);
8169 }
8170 }
8171
8172 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008173 * Returns false if the mobile data is disabled by default, otherwise return true.
8174 */
8175 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008176 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008177 }
8178
8179 /**
8180 * Returns true if the data roaming is enabled by default, i.e the system property
8181 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8182 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8183 */
8184 private boolean getDefaultDataRoamingEnabled(int subId) {
8185 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008186 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008187 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008188 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8189 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8190 return isDataRoamingEnabled;
8191 }
8192
8193 /**
8194 * Returns the default network type for the given {@code subId}, if the default network type is
8195 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8196 */
8197 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008198 List<Integer> list = TelephonyProperties.default_network();
8199 int phoneId = mSubscriptionController.getPhoneId(subId);
8200 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8201 return list.get(phoneId);
8202 }
8203 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008204 }
fionaxua13278b2018-03-21 00:08:13 -07008205
8206 @Override
8207 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008208 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008209 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008210
8211 final long identity = Binder.clearCallingIdentity();
8212 try {
8213 final Phone phone = getPhone(subId);
8214 if (phone == null) {
8215 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8216 return;
8217 }
chen xueaba88a2019-03-15 13:15:10 -07008218 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8219 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008220 if (carrierPrivilegeRules == null) {
8221 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8222 } else {
8223 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8224 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008225 } finally {
8226 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008227 }
fionaxua13278b2018-03-21 00:08:13 -07008228 }
8229
8230 @Override
8231 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008232 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008233
8234 final long identity = Binder.clearCallingIdentity();
8235 try {
8236 final Phone phone = getPhone(subId);
8237 if (phone == null) {
8238 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8239 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8240 }
8241 return phone.getCarrierIdListVersion();
8242 } finally {
8243 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008244 }
fionaxua13278b2018-03-21 00:08:13 -07008245 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008246
8247 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008248 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8249 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008250 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008251 mApp, subId, callingPackage, callingFeatureId,
8252 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008253 return -1;
8254 }
8255
8256 final long identity = Binder.clearCallingIdentity();
8257 try {
8258 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8259 } finally {
8260 Binder.restoreCallingIdentity(identity);
8261 }
8262 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008263
8264 @Override
8265 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008266 TelephonyPermissions
8267 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008268 mApp, subId, "getCdmaRoamingMode");
8269
8270 final long identity = Binder.clearCallingIdentity();
8271 try {
8272 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8273 } finally {
8274 Binder.restoreCallingIdentity(identity);
8275 }
8276 }
8277
8278 @Override
8279 public boolean setCdmaRoamingMode(int subId, int mode) {
8280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8281 mApp, subId, "setCdmaRoamingMode");
8282
8283 final long identity = Binder.clearCallingIdentity();
8284 try {
8285 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8286 } finally {
8287 Binder.restoreCallingIdentity(identity);
8288 }
8289 }
8290
8291 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008292 public int getCdmaSubscriptionMode(int subId) {
8293 TelephonyPermissions
8294 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8295 mApp, subId, "getCdmaSubscriptionMode");
8296
8297 final long identity = Binder.clearCallingIdentity();
8298 try {
8299 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8300 } finally {
8301 Binder.restoreCallingIdentity(identity);
8302 }
8303 }
8304
8305 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008306 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8307 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8308 mApp, subId, "setCdmaSubscriptionMode");
8309
8310 final long identity = Binder.clearCallingIdentity();
8311 try {
8312 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8313 } finally {
8314 Binder.restoreCallingIdentity(identity);
8315 }
8316 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008317
sqianc5eccab2018-10-19 18:46:41 -07008318 @Override
sqian8c685422019-02-22 15:55:18 -08008319 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008320 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008321 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008322 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8323 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008324 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8325 }
8326 final long identity = Binder.clearCallingIdentity();
8327 try {
sqian854d44b2018-12-12 16:48:18 -08008328 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8329 for (Phone phone: PhoneFactory.getPhones()) {
8330 if (phone.getEmergencyNumberTracker() != null
8331 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8332 emergencyNumberListInternal.put(
8333 phone.getSubId(),
8334 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8335 }
sqian11b7a0e2018-12-05 18:48:28 -08008336 }
sqian854d44b2018-12-12 16:48:18 -08008337 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008338 } finally {
8339 Binder.restoreCallingIdentity(identity);
8340 }
sqianc5eccab2018-10-19 18:46:41 -07008341 }
8342
8343 @Override
sqian8c685422019-02-22 15:55:18 -08008344 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008345 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008346 if (!exactMatch) {
8347 TelephonyPermissions
8348 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008349 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008350 }
8351 final long identity = Binder.clearCallingIdentity();
8352 try {
sqian854d44b2018-12-12 16:48:18 -08008353 for (Phone phone: PhoneFactory.getPhones()) {
8354 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008355 && phone.getEmergencyNumberTracker()
8356 .isEmergencyNumber(number, exactMatch)) {
8357 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008358 }
sqian11b7a0e2018-12-05 18:48:28 -08008359 }
8360 return false;
8361 } finally {
8362 Binder.restoreCallingIdentity(identity);
8363 }
8364 }
8365
sqianf4ca7ed2019-01-15 18:32:07 -08008366 /**
8367 * Update emergency number list for test mode.
8368 */
8369 @Override
8370 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8371 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8372 "updateEmergencyNumberListTestMode");
8373
8374 final long identity = Binder.clearCallingIdentity();
8375 try {
8376 for (Phone phone: PhoneFactory.getPhones()) {
8377 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8378 if (tracker != null) {
8379 tracker.executeEmergencyNumberTestModeCommand(action, num);
8380 }
8381 }
8382 } finally {
8383 Binder.restoreCallingIdentity(identity);
8384 }
8385 }
8386
8387 /**
8388 * Get the full emergency number list for test mode.
8389 */
8390 @Override
8391 public List<String> getEmergencyNumberListTestMode() {
8392 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8393 "getEmergencyNumberListTestMode");
8394
8395 final long identity = Binder.clearCallingIdentity();
8396 try {
8397 Set<String> emergencyNumbers = new HashSet<>();
8398 for (Phone phone: PhoneFactory.getPhones()) {
8399 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8400 if (tracker != null) {
8401 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8402 emergencyNumbers.add(num.getNumber());
8403 }
8404 }
8405 }
8406 return new ArrayList<>(emergencyNumbers);
8407 } finally {
8408 Binder.restoreCallingIdentity(identity);
8409 }
8410 }
8411
chen xud6b45bd2018-10-30 22:27:10 -07008412 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008413 public int getEmergencyNumberDbVersion(int subId) {
8414 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8415
8416 final long identity = Binder.clearCallingIdentity();
8417 try {
8418 final Phone phone = getPhone(subId);
8419 if (phone == null) {
8420 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8421 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8422 }
8423 return phone.getEmergencyNumberDbVersion();
8424 } finally {
8425 Binder.restoreCallingIdentity(identity);
8426 }
8427 }
8428
8429 @Override
8430 public void notifyOtaEmergencyNumberDbInstalled() {
8431 enforceModifyPermission();
8432
8433 final long identity = Binder.clearCallingIdentity();
8434 try {
8435 for (Phone phone: PhoneFactory.getPhones()) {
8436 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8437 if (tracker != null) {
8438 tracker.updateOtaEmergencyNumberDatabase();
8439 }
8440 }
8441 } finally {
8442 Binder.restoreCallingIdentity(identity);
8443 }
8444 }
8445
8446 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008447 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008448 enforceActiveEmergencySessionPermission();
8449
8450 final long identity = Binder.clearCallingIdentity();
8451 try {
8452 for (Phone phone: PhoneFactory.getPhones()) {
8453 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8454 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008455 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8456 }
8457 }
8458 } finally {
8459 Binder.restoreCallingIdentity(identity);
8460 }
8461 }
8462
8463 @Override
8464 public void resetOtaEmergencyNumberDbFilePath() {
8465 enforceActiveEmergencySessionPermission();
8466
8467 final long identity = Binder.clearCallingIdentity();
8468 try {
8469 for (Phone phone: PhoneFactory.getPhones()) {
8470 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8471 if (tracker != null) {
8472 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008473 }
8474 }
8475 } finally {
8476 Binder.restoreCallingIdentity(identity);
8477 }
8478 }
8479
8480 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008481 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8482 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8483 Phone phone = getPhone(subId);
8484 if (phone == null) {
8485 return null;
8486 }
8487 final long identity = Binder.clearCallingIdentity();
8488 try {
8489 UiccProfile profile = UiccController.getInstance()
8490 .getUiccProfileForPhone(phone.getPhoneId());
8491 if (profile != null) {
8492 return profile.getCertsFromCarrierPrivilegeAccessRules();
8493 }
8494 } finally {
8495 Binder.restoreCallingIdentity(identity);
8496 }
8497 return null;
8498 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008499
8500 /**
8501 * Enable or disable a modem stack.
8502 */
8503 @Override
8504 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8505 enforceModifyPermission();
8506
8507 final long identity = Binder.clearCallingIdentity();
8508 try {
8509 Phone phone = PhoneFactory.getPhone(slotIndex);
8510 if (phone == null) {
8511 return false;
8512 } else {
8513 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8514 }
8515 } finally {
8516 Binder.restoreCallingIdentity(identity);
8517 }
8518 }
Michelecea4cf22018-12-21 15:00:11 -08008519
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008520 /**
8521 * Whether a modem stack is enabled or not.
8522 */
8523 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008524 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8525 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008526 Phone phone = PhoneFactory.getPhone(slotIndex);
8527 if (phone == null) return false;
8528
8529 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008530 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8531 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008532 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8533 }
8534
8535 final long identity = Binder.clearCallingIdentity();
8536 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008537 try {
8538 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8539 } catch (NoSuchElementException ex) {
8540 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8541 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008542 } finally {
8543 Binder.restoreCallingIdentity(identity);
8544 }
8545 }
8546
Michelecea4cf22018-12-21 15:00:11 -08008547 @Override
Michele0ea7d782019-03-19 14:58:42 -07008548 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008549 enforceModifyPermission();
8550
8551 final long identity = Binder.clearCallingIdentity();
8552 try {
8553 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008554 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008555 .commit();
8556 } finally {
8557 Binder.restoreCallingIdentity(identity);
8558 }
8559 }
8560
8561 @Override
Michele0ea7d782019-03-19 14:58:42 -07008562 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008563 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008565 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8566 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008567 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008568 }
Michelecea4cf22018-12-21 15:00:11 -08008569
8570 final long identity = Binder.clearCallingIdentity();
8571 try {
Michele0ea7d782019-03-19 14:58:42 -07008572 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008573 } finally {
8574 Binder.restoreCallingIdentity(identity);
8575 }
8576 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008577
Michele0ea7d782019-03-19 14:58:42 -07008578 @TelephonyManager.IsMultiSimSupportedResult
8579 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008580 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8581 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8582 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008583 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8584 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008585 }
8586 // Check if the hardware supports multisim functionality. If usage of multisim is not
8587 // supported by the modem, indicate that it is restricted.
8588 PhoneCapability staticCapability =
8589 mPhoneConfigurationManager.getStaticPhoneCapability();
8590 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008591 loge("isMultiSimSupportedInternal: no static configuration available");
8592 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008593 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008594 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008595 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8596 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008597 }
8598 // Check if support of multiple SIMs is restricted by carrier
8599 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008600 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008601 }
8602
Michele0ea7d782019-03-19 14:58:42 -07008603 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008604 }
8605
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008606 /**
8607 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008608 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8609 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8610 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008611 * @param numOfSims number of active sims we want to switch to
8612 */
8613 @Override
8614 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008615 if (numOfSims == 1) {
8616 enforceModifyPermission();
8617 } else {
8618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8619 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8620 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008621 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008622
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008623 try {
Michele30b57b22019-03-01 12:01:14 -08008624 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008625 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008626 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8627 return;
8628 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008629 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8630 } finally {
8631 Binder.restoreCallingIdentity(identity);
8632 }
8633 }
8634
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008635 @Override
8636 public boolean isApplicationOnUicc(int subId, int appType) {
8637 enforceReadPrivilegedPermission("isApplicationOnUicc");
8638 Phone phone = getPhone(subId);
8639 if (phone == null) {
8640 return false;
8641 }
8642 final long identity = Binder.clearCallingIdentity();
8643 try {
8644 UiccCard uiccCard = phone.getUiccCard();
8645 if (uiccCard == null) {
8646 return false;
8647 }
8648 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8649 if (uiccProfile == null) {
8650 return false;
8651 }
8652 if (TelephonyManager.APPTYPE_SIM <= appType
8653 && appType <= TelephonyManager.APPTYPE_ISIM) {
8654 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8655 }
8656 return false;
8657 } finally {
8658 Binder.restoreCallingIdentity(identity);
8659 }
8660 }
8661
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008662 /**
chen xub4baa772019-04-03 10:23:41 -07008663 * Get whether making changes to modem configurations will trigger reboot.
8664 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008665 */
8666 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008667 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8668 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008669 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008670 mApp, subId, callingPackage, callingFeatureId,
8671 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008672 return false;
8673 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008674 final long identity = Binder.clearCallingIdentity();
8675 try {
8676 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8677 } finally {
8678 Binder.restoreCallingIdentity(identity);
8679 }
8680 }
8681
Nathan Harold29f5f052019-02-15 13:41:57 -08008682 private void updateModemStateMetrics() {
8683 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8684 // TODO: check the state for each modem if the api is ready.
8685 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8686 }
8687
Pengquan Meng3889a572019-01-23 11:16:29 -08008688 @Override
8689 public int[] getSlotsMapping() {
8690 enforceReadPrivilegedPermission("getSlotsMapping");
8691
8692 final long identity = Binder.clearCallingIdentity();
8693 try {
8694 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8695 // All logical slots should have a mapping to a physical slot.
8696 int[] logicalSlotsMapping = new int[phoneCount];
8697 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8698 for (int i = 0; i < slotInfos.length; i++) {
8699 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8700 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8701 }
8702 }
8703 return logicalSlotsMapping;
8704 } finally {
8705 Binder.restoreCallingIdentity(identity);
8706 }
8707 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008708
8709 /**
8710 * Get the IRadio HAL Version
8711 */
8712 @Override
8713 public int getRadioHalVersion() {
8714 Phone phone = getDefaultPhone();
8715 if (phone == null) return -1;
8716 HalVersion hv = phone.getHalVersion();
8717 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8718 return hv.major * 100 + hv.minor;
8719 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008720
8721 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008722 * Get the current calling package name.
8723 * @return the current calling package name
8724 */
8725 @Override
8726 public String getCurrentPackageName() {
8727 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8728 }
8729
8730 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008731 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8732 * corresponding network requests on a subId.
8733 *
8734 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008735 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008736 * 2) APN is un-metered for this subscription, or
8737 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008738 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008739 *
8740 * @return whether data is allowed for a apn type.
8741 *
8742 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008743 */
8744 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008745 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008746 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8747 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008748
8749 // Now that all security checks passes, perform the operation as ourselves.
8750 final long identity = Binder.clearCallingIdentity();
8751 try {
8752 Phone phone = getPhone(subId);
8753 if (phone == null) return false;
8754
Jack Yu41407ee2019-05-13 16:54:09 -07008755 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008756 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8757 } finally {
8758 Binder.restoreCallingIdentity(identity);
8759 }
8760 }
8761
8762 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008763 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008764 enforceReadPrivilegedPermission("isApnMetered");
8765
8766 // Now that all security checks passes, perform the operation as ourselves.
8767 final long identity = Binder.clearCallingIdentity();
8768 try {
8769 Phone phone = getPhone(subId);
8770 if (phone == null) return true; // By default return true.
8771
Jack Yu41407ee2019-05-13 16:54:09 -07008772 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008773 } finally {
8774 Binder.restoreCallingIdentity(identity);
8775 }
8776 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008777
8778 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008779 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8780 int subscriptionId, IBooleanConsumer resultCallback) {
8781 enforceModifyPermission();
8782 long token = Binder.clearCallingIdentity();
8783 try {
8784 Phone phone = getPhone(subscriptionId);
8785 if (phone == null) {
8786 try {
8787 if (resultCallback != null) {
8788 resultCallback.accept(false);
8789 }
8790 } catch (RemoteException e) {
8791 // ignore
8792 }
8793 return;
8794 }
8795 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8796 Pair.create(specifiers, (x) -> {
8797 try {
8798 if (resultCallback != null) {
8799 resultCallback.accept(x);
8800 }
8801 } catch (RemoteException e) {
8802 // ignore
8803 }
8804 });
8805 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8806 } finally {
8807 Binder.restoreCallingIdentity(token);
8808 }
8809 }
8810
8811 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008812 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8813 TelephonyPermissions
8814 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8815 mApp, subId, "getSystemSelectionChannels");
8816 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8817 final long identity = Binder.clearCallingIdentity();
8818 try {
8819 List<RadioAccessSpecifier> specifiers =
8820 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8821 null, subId, workSource);
8822 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8823 return specifiers;
8824 } finally {
8825 Binder.restoreCallingIdentity(identity);
8826 }
8827 }
8828
8829 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008830 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008831 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008832 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8833 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8834 if (iccRecords == null) {
8835 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8836 return false;
8837 }
8838 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8839 }
8840
8841 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008842 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8843 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008844 if (callingPackage == null) {
8845 callingPackage = getCurrentPackageName();
8846 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008847 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8848 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008849 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8850 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008851 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8852 }
8853 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8854 Intent intent = new Intent();
8855 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8856 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8857 // Bring up choose default SMS subscription dialog right now
8858 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8859 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8860 mApp.startActivity(intent);
8861 }
chen xud5ca2d52019-05-28 15:20:57 -07008862
8863 @Override
8864 public String getMmsUAProfUrl(int subId) {
8865 //TODO investigate if this API should require proper permission check in R b/133791609
8866 final long identity = Binder.clearCallingIdentity();
8867 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008868 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8869 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8870 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8871 return carrierUAProfUrl;
8872 }
chen xud5ca2d52019-05-28 15:20:57 -07008873 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8874 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8875 } finally {
8876 Binder.restoreCallingIdentity(identity);
8877 }
8878 }
8879
8880 @Override
8881 public String getMmsUserAgent(int subId) {
8882 //TODO investigate if this API should require proper permission check in R b/133791609
8883 final long identity = Binder.clearCallingIdentity();
8884 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008885 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8886 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8887 if (!TextUtils.isEmpty(carrierUserAgent)) {
8888 return carrierUserAgent;
8889 }
chen xud5ca2d52019-05-28 15:20:57 -07008890 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8891 .getString(com.android.internal.R.string.config_mms_user_agent);
8892 } finally {
8893 Binder.restoreCallingIdentity(identity);
8894 }
8895 }
Jack Yub07d4972019-05-28 16:12:25 -07008896
8897 @Override
Hall Liuc041a552020-09-25 10:42:19 -07008898 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8899 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
8900
8901 final long identity = Binder.clearCallingIdentity();
8902 try {
8903 Phone phone = getPhone(subscriptionId);
8904 if (phone == null) return false;
8905
8906 switch (policy) {
8907 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8908 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8909 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8910 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8911 default:
8912 throw new IllegalArgumentException(policy + " is not a valid policy");
8913 }
8914 } finally {
8915 Binder.restoreCallingIdentity(identity);
8916 }
8917 }
8918
8919 @Override
8920 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8921 boolean enabled) {
8922 enforceModifyPermission();
8923
8924 final long identity = Binder.clearCallingIdentity();
8925 try {
8926 Phone phone = getPhone(subscriptionId);
8927 if (phone == null) return;
8928
8929 switch (policy) {
8930 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8931 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8932 break;
8933 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8934 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
8935 break;
8936 default:
8937 throw new IllegalArgumentException(policy + " is not a valid policy");
8938 }
8939 } finally {
8940 Binder.restoreCallingIdentity(identity);
8941 }
8942 }
8943
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008944 /**
Hall Liub48cf452020-09-25 11:13:49 -07008945 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008946 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8947 * otherwise.
8948 */
8949 @Override
8950 public void setCepEnabled(boolean isCepEnabled) {
8951 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8952
8953 final long identity = Binder.clearCallingIdentity();
8954 try {
8955 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8956 for (Phone phone : PhoneFactory.getPhones()) {
8957 Phone defaultPhone = phone.getImsPhone();
8958 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8959 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8960 ImsPhoneCallTracker imsPhoneCallTracker =
8961 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8962 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8963 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8964 + imsPhone.getMsisdn());
8965 }
8966 }
8967 } finally {
8968 Binder.restoreCallingIdentity(identity);
8969 }
8970 }
allenwtsu46dcc572020-01-08 18:24:03 +08008971
8972 /**
8973 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8974 *
8975 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8976 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8977 * before being read.
8978 */
8979 @Override
8980 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8981 isCompressed) {
8982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8983 mApp, subId, "notifyRcsAutoConfigurationReceived");
8984 try {
8985 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8986 if (configBinder == null) {
8987 Rlog.e(LOG_TAG, "null result for getImsConfig");
8988 } else {
8989 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8990 }
8991 } catch (RemoteException e) {
8992 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8993 }
8994 }
zoey chenf95ca592019-12-30 16:11:23 +08008995
8996 @Override
8997 public boolean isIccLockEnabled(int subId) {
8998 enforceReadPrivilegedPermission("isIccLockEnabled");
8999
9000 // Now that all security checks passes, perform the operation as ourselves.
9001 final long identity = Binder.clearCallingIdentity();
9002 try {
9003 Phone phone = getPhone(subId);
9004 if (phone != null && phone.getIccCard() != null) {
9005 return phone.getIccCard().getIccLockEnabled();
9006 } else {
9007 return false;
9008 }
9009 } finally {
9010 Binder.restoreCallingIdentity(identity);
9011 }
9012 }
9013
9014 /**
zoey chene02881a2019-12-30 16:11:23 +08009015 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009016 *
zoey chene02881a2019-12-30 16:11:23 +08009017 * @return an integer representing the status of IccLock enabled or disabled in the following
9018 * three cases:
9019 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9020 * successfully.
9021 * - Positive number and zero for remaining password attempts.
9022 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009023 *
9024 */
9025 @Override
9026 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9027 enforceModifyPermission();
9028
9029 Phone phone = getPhone(subId);
9030 if (phone == null) {
9031 return 0;
9032 }
9033 // Now that all security checks passes, perform the operation as ourselves.
9034 final long identity = Binder.clearCallingIdentity();
9035 try {
9036 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9037 new Pair<Boolean, String>(enabled, password), phone, null);
9038 return attemptsRemaining;
9039
9040 } catch (Exception e) {
9041 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9042 } finally {
9043 Binder.restoreCallingIdentity(identity);
9044 }
9045 return 0;
9046 }
9047
9048 /**
9049 * Change the ICC password used in ICC pin lock.
9050 *
zoey chene02881a2019-12-30 16:11:23 +08009051 * @return an integer representing the status of IccLock changed in the following three cases:
9052 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9053 * - Positive number and zero for remaining password attempts.
9054 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009055 *
9056 */
9057 @Override
9058 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9059 enforceModifyPermission();
9060
9061 Phone phone = getPhone(subId);
9062 if (phone == null) {
9063 return 0;
9064 }
9065 // Now that all security checks passes, perform the operation as ourselves.
9066 final long identity = Binder.clearCallingIdentity();
9067 try {
9068 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9069 new Pair<String, String>(oldPassword, newPassword), phone, null);
9070 return attemptsRemaining;
9071
9072 } catch (Exception e) {
9073 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9074 } finally {
9075 Binder.restoreCallingIdentity(identity);
9076 }
9077 return 0;
9078 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009079
Peter Wangdafb9ac2020-01-15 14:13:38 -08009080 /**
9081 * Request for receiving user activity notification
9082 */
9083 @Override
9084 public void requestUserActivityNotification() {
9085 if (!mNotifyUserActivity.get()
9086 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9087 mNotifyUserActivity.set(true);
9088 }
9089 }
9090
9091 /**
9092 * Called when userActivity is signalled in the power manager.
9093 * This is safe to call from any thread, with any window manager locks held or not.
9094 */
9095 @Override
9096 public void userActivity() {
9097 // ***************************************
9098 // * Inherited from PhoneWindowManager *
9099 // ***************************************
9100 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9101 // WITH ITS LOCKS HELD.
9102 //
9103 // This code must be VERY careful about the locks
9104 // it acquires.
9105 // In fact, the current code acquires way too many,
9106 // and probably has lurking deadlocks.
9107
9108 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9109 throw new SecurityException("Only the OS may call notifyUserActivity()");
9110 }
9111
9112 if (mNotifyUserActivity.getAndSet(false)) {
9113 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9114 USER_ACTIVITY_NOTIFICATION_DELAY);
9115 }
9116 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009117
Malcolm Chen884180b2020-04-13 11:59:40 -07009118 @Override
9119 public boolean canConnectTo5GInDsdsMode() {
9120 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9121 }
Jack Yud10cdd42020-09-28 20:28:01 -07009122
9123 @Override
9124 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9125 String callingFeatureId) {
9126 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9127 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9128 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9129 }
9130
9131 Phone phone = getPhone(subId);
9132 if (phone == null) {
9133 throw new RuntimeException("phone is not available");
9134 }
9135 // Now that all security checks passes, perform the operation as ourselves.
9136 final long identity = Binder.clearCallingIdentity();
9137 try {
9138 return phone.getEquivalentHomePlmns();
9139 } finally {
9140 Binder.restoreCallingIdentity(identity);
9141 }
9142 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009143
Hui Wang0866fcc2020-10-12 12:14:23 -07009144 @Override
9145 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9146 UaSecurityProtocolIdentifier securityProtocol,
9147 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9148 throws RemoteException {
9149 enforceModifyPermission();
9150 if (DBG) {
9151 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9152 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9153 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9154 }
9155
9156 if (!SubscriptionManager.isValidSubscriptionId(subId)
9157 || appType < TelephonyManager.APPTYPE_UNKNOWN
9158 || appType > TelephonyManager.APPTYPE_ISIM
9159 || nafUrl == null || securityProtocol == null || callback == null) {
9160 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9161 if (callback != null) {
9162 try {
9163 callback.onAuthenticationFailure(
9164 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9165 } catch (RemoteException exception) {
9166 log("Fail to notify onAuthenticationFailure due to " + exception);
9167 }
9168 return;
9169 }
9170 }
9171
9172 final long token = Binder.clearCallingIdentity();
9173 try {
9174 getGbaManager(subId).bootstrapAuthenticationRequest(
9175 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9176 forceBootStrapping, callback));
9177 } finally {
9178 Binder.restoreCallingIdentity(token);
9179 }
9180 }
9181
Jack Nudelman24d51a52020-11-24 12:08:04 -08009182 /**
9183 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9184 * requested radio power state will actually be set. See {@link
9185 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9186 *
9187 * @param subId the subscription ID of the phone requesting to set the radio power state.
9188 * @param enable {@code true} if trying to turn radio on.
9189 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9190 * false}.
9191 */
9192 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9193 Phone phone = getPhone(subId);
9194 if (phone != null) {
9195 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9196 return true;
9197 }
9198 return false;
9199 }
9200
9201 private int handleDataThrottlingRequest(int subId,
9202 DataThrottlingRequest dataThrottlingRequest) {
9203 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9204 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9205 if (!setRadioPowerForThermal(subId, true)) {
9206 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9207 }
9208
9209 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9210
9211 int thermalMitigationResult =
9212 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9213 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9214 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9215 }
9216 return thermalMitigationResult;
9217 }
9218
9219 /**
9220 * Thermal mitigation request to control functionalities at modem.
9221 *
9222 * @param subId the id of the subscription.
9223 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9224 *
9225 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9226 */
9227 @Override
9228 @ThermalMitigationResult
9229 public int sendThermalMitigationRequest(
9230 int subId,
9231 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9232 enforceModifyPermission();
9233
9234 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9235 final long identity = Binder.clearCallingIdentity();
9236
9237 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9238 try {
9239 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9240 switch (thermalMitigationAction) {
9241 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9242 thermalMitigationResult =
9243 handleDataThrottlingRequest(subId,
9244 thermalMitigationRequest.getDataThrottlingRequest());
9245 break;
9246 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9247 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9248 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9249 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9250 }
9251
9252 // Ensure that radio is on. If not able to power on due to phone being
9253 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9254 if (!setRadioPowerForThermal(subId, true)) {
9255 thermalMitigationResult =
9256 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9257 break;
9258 }
9259
9260 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9261 false);
9262 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9263 break;
9264 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9265 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9266 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9267 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9268 }
9269
9270 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9271 if (registry != null) {
9272 TelephonyConnectionService service =
9273 registry.getTelephonyConnectionService();
9274 Phone phone = getPhone(subId);
9275 if (phone == null) {
9276 thermalMitigationResult =
9277 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9278 break;
9279 }
9280
9281 if (PhoneConstantConversions.convertCallState(phone.getState())
9282 != TelephonyManager.CALL_STATE_IDLE
9283 || phone.isInEmergencySmsMode() || phone.isInEcm()
9284 || (service != null && service.isEmergencyCallPending())) {
9285 String errorMessage = "Phone state is not valid. call state = "
9286 + PhoneConstantConversions.convertCallState(phone.getState())
9287 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9288 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9289 errorMessage += service == null
9290 ? " TelephonyConnectionService is null"
9291 : " isEmergencyCallPending = "
9292 + service.isEmergencyCallPending();
9293 Log.e(LOG_TAG, errorMessage);
9294 thermalMitigationResult =
9295 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9296 break;
9297 }
9298 } else {
9299 thermalMitigationResult =
9300 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9301 break;
9302 }
9303
9304 // Turn radio off. If not able to power off due to phone being unavailable,
9305 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9306 if (!setRadioPowerForThermal(subId, false)) {
9307 thermalMitigationResult =
9308 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9309 break;
9310 }
9311 thermalMitigationResult =
9312 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9313 break;
9314 default:
9315 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9316 + "not exist. Requested action: " + thermalMitigationAction);
9317 }
9318 } catch (IllegalArgumentException e) {
9319 throw e;
9320 } catch (Exception e) {
9321 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9322 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9323 } finally {
9324 Binder.restoreCallingIdentity(identity);
9325 }
9326
9327 if (DBG) {
9328 log("thermalMitigationRequest returning with thermalMitigationResult: "
9329 + thermalMitigationResult);
9330 }
9331
9332 return thermalMitigationResult;
9333 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009334
9335 /**
9336 * Set the GbaService Package Name that Telephony will bind to.
9337 *
9338 * @param subId The sim that the GbaService is associated with.
9339 * @param packageName The name of the package to be replaced with.
9340 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9341 */
9342 @Override
9343 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9344 enforceModifyPermission();
9345
9346 final long identity = Binder.clearCallingIdentity();
9347 try {
9348 return getGbaManager(subId).overrideServicePackage(packageName);
9349 } finally {
9350 Binder.restoreCallingIdentity(identity);
9351 }
9352 }
9353
9354 /**
9355 * Return the package name of the currently bound GbaService.
9356 *
9357 * @param subId The sim that the GbaService is associated with.
9358 * @return the package name of the GbaService configuration, null if GBA is not supported.
9359 */
9360 @Override
9361 public String getBoundGbaService(int subId) {
9362 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9363
9364 final long identity = Binder.clearCallingIdentity();
9365 try {
9366 return getGbaManager(subId).getServicePackage();
9367 } finally {
9368 Binder.restoreCallingIdentity(identity);
9369 }
9370 }
9371
9372 /**
9373 * Set the release time for telephony to unbind GbaService.
9374 *
9375 * @param subId The sim that the GbaService is associated with.
9376 * @param interval The release time to unbind GbaService by millisecond.
9377 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9378 */
9379 @Override
9380 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9381 enforceModifyPermission();
9382
9383 final long identity = Binder.clearCallingIdentity();
9384 try {
9385 return getGbaManager(subId).overrideReleaseTime(interval);
9386 } finally {
9387 Binder.restoreCallingIdentity(identity);
9388 }
9389 }
9390
9391 /**
9392 * Return the release time for telephony to unbind GbaService.
9393 *
9394 * @param subId The sim that the GbaService is associated with.
9395 * @return The release time to unbind GbaService by millisecond.
9396 */
9397 @Override
9398 public int getGbaReleaseTime(int subId) {
9399 enforceReadPrivilegedPermission("getGbaReleaseTime");
9400
9401 final long identity = Binder.clearCallingIdentity();
9402 try {
9403 return getGbaManager(subId).getReleaseTime();
9404 } finally {
9405 Binder.restoreCallingIdentity(identity);
9406 }
9407 }
9408
9409 private GbaManager getGbaManager(int subId) {
9410 GbaManager instance = GbaManager.getInstance(subId);
9411 if (instance == null) {
9412 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9413 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9414 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9415 }
9416 return instance;
9417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009418}