blob: 722dfe73aaec8beef154ce686aa431a59d118739 [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;
Hall Liua1548bd2019-12-24 14:14:12 -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;
Hall Liua1548bd2019-12-24 14:14:12 -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 Qiancd19c462020-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 Nallurid63128d2019-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 Kim14bb3d02018-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 Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Shuo Qian4a594052020-01-23 11:59:30 -080067import android.telephony.CallForwardingInfo;
Sooraj Sasindran4deb8872020-10-30 13:17:53 -070068import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070069import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080070import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070071import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080072import android.telephony.CellIdentityCdma;
73import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070075import android.telephony.CellInfoGsm;
76import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070077import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070078import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070079import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080080import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070081import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080082import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070083import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080084import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080085import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070086import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.RadioAccessSpecifier;
Daniel Bright59e67312020-11-13 11:49:37 -080088import android.telephony.RadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080090import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080091import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080092import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080093import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070094import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070095import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080096import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080097import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000098import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070099import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700100import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800101import android.telephony.data.ApnSetting;
102import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700103import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800104import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700105import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700106import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700108import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700118import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800120import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121
Andrew Lee312e8172014-10-23 17:01:36 -0700122import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800123import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800124import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700125import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700126import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700127import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800128import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700129import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700130import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800131import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800133import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800134import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700135import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700136import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800137import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800139import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700140import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700141import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700142import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700144import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800145import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700146import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700147import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700148import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700149import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700150import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700151import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700152import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700153import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800154import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800155import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800156import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700157import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800158import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700159import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800160import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700161import com.android.internal.telephony.imsphone.ImsPhone;
162import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800163import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700164import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800166import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700167import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800168import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700169import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800170import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700171import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800172import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000173import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800174import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700175import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700176import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800177import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700178import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700179import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800180import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700181import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700182import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800183import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800184
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700185import java.io.FileDescriptor;
186import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800188import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800189import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800190import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800191import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100192import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800193import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700194import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800195import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800196import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800197import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198
199/**
200 * Implementation of the ITelephony interface.
201 */
Santos Cordon117fee72014-05-16 17:56:12 -0700202public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700203 private static final String LOG_TAG = "PhoneInterfaceManager";
204 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
205 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800206 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207
208 // Message codes used with mMainThreadHandler
209 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700210 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
211 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700212 private static final int CMD_OPEN_CHANNEL = 9;
213 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
214 private static final int CMD_CLOSE_CHANNEL = 11;
215 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800216 private static final int CMD_NV_READ_ITEM = 13;
217 private static final int EVENT_NV_READ_ITEM_DONE = 14;
218 private static final int CMD_NV_WRITE_ITEM = 15;
219 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
220 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
221 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700222 private static final int CMD_RESET_MODEM_CONFIG = 19;
223 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800224 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
225 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
226 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
227 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800228 private static final int CMD_SEND_ENVELOPE = 25;
229 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000230 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
231 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700232 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
233 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
234 private static final int CMD_EXCHANGE_SIM_IO = 31;
235 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800236 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
237 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700238 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
239 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700240 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
241 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700242 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
243 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
244 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
245 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700246 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
247 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
248 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
249 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700250 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800251 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
252 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000253 private static final int CMD_SWITCH_SLOTS = 50;
254 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700255 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
256 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
257 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
258 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
259 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
260 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
261 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
262 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700263 private static final int CMD_GET_ALL_CELL_INFO = 60;
264 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
265 private static final int CMD_GET_CELL_LOCATION = 62;
266 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700267 private static final int CMD_MODEM_REBOOT = 64;
268 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700269 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
270 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800271 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
272 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700273 private static final int CMD_GET_MODEM_STATUS = 70;
274 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700275 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
276 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700277 private static final int CMD_ERASE_MODEM_CONFIG = 74;
278 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800279 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
280 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
281 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
282 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800283 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
284 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800285 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800286 private static final int CMD_GET_CALL_FORWARDING = 83;
287 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
288 private static final int CMD_SET_CALL_FORWARDING = 85;
289 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
290 private static final int CMD_GET_CALL_WAITING = 87;
291 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
292 private static final int CMD_SET_CALL_WAITING = 89;
293 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700294 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
295 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
296 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
297 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700298 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
299 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800301 // Parameters of select command.
302 private static final int SELECT_COMMAND = 0xA4;
303 private static final int SELECT_P1 = 0x04;
304 private static final int SELECT_P2 = 0;
305 private static final int SELECT_P3 = 0x10;
306
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700307 /** The singleton instance. */
308 private static PhoneInterfaceManager sInstance;
309
Wink Saville3ab207e2014-11-20 13:07:20 -0800310 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800311 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800312 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700313 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800314 private AppOpsManager mAppOps;
315 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800316 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800317 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700318 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319
Peter Wangdafb9ac2020-01-15 14:13:38 -0800320 /** User Activity */
321 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800322 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
323
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700324 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
325
Derek Tan97ebb422014-09-05 16:55:38 -0700326 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
327 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800328 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800329 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700330
Michelecea4cf22018-12-21 15:00:11 -0800331 // String to store multi SIM allowed
332 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
333
Derek Tan740e1672017-06-27 14:56:27 -0700334 // The AID of ISD-R.
335 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
336
yinxub1bed742017-04-17 11:45:04 -0700337 private NetworkScanRequestTracker mNetworkScanRequestTracker;
338
David Kelly5e06a7f2018-03-12 14:10:59 +0000339 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
340 private static final int MANUFACTURER_CODE_LENGTH = 8;
341
Derek Tan89e89d42014-07-08 17:00:10 -0700342 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700343 * Experiment flag to enable erase modem config on reset network, default value is false
344 */
345 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
346 "reset_network_erase_modem_config_enabled";
347
348 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700349 * A request object to use for transmitting data to an ICC.
350 */
351 private static final class IccAPDUArgument {
352 public int channel, cla, command, p1, p2, p3;
353 public String data;
354
355 public IccAPDUArgument(int channel, int cla, int command,
356 int p1, int p2, int p3, String data) {
357 this.channel = channel;
358 this.cla = cla;
359 this.command = command;
360 this.p1 = p1;
361 this.p2 = p2;
362 this.p3 = p3;
363 this.data = data;
364 }
365 }
366
367 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700368 * A request object to use for transmitting data to an ICC.
369 */
370 private static final class ManualNetworkSelectionArgument {
371 public OperatorInfo operatorInfo;
372 public boolean persistSelection;
373
374 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
375 this.operatorInfo = operatorInfo;
376 this.persistSelection = persistSelection;
377 }
378 }
379
380 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
382 * request after sending. The main thread will notify the request when it is complete.
383 */
384 private static final class MainThreadRequest {
385 /** The argument to use for the request */
386 public Object argument;
387 /** The result of the request that is run on the main thread */
388 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800389 // The subscriber id that this request applies to. Defaults to
390 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
391 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700392
Nathan Harold92bed182018-10-12 18:16:49 -0700393 // In cases where subId is unavailable, the caller needs to specify the phone.
394 public Phone phone;
395
vagdeviaf9a5b92018-08-15 16:01:53 -0700396 public WorkSource workSource;
397
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 public MainThreadRequest(Object argument) {
399 this.argument = argument;
400 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800401
Nathan Harold92bed182018-10-12 18:16:49 -0700402 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
403 this.argument = argument;
404 if (phone != null) {
405 this.phone = phone;
406 }
407 this.workSource = workSource;
408 }
409
vagdeviaf9a5b92018-08-15 16:01:53 -0700410 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800411 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800412 if (subId != null) {
413 this.subId = subId;
414 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700415 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417 }
418
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800419 private static final class IncomingThirdPartyCallArgs {
420 public final ComponentName component;
421 public final String callId;
422 public final String callerDisplayName;
423
424 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
425 String callerDisplayName) {
426 this.component = component;
427 this.callId = callId;
428 this.callerDisplayName = callerDisplayName;
429 }
430 }
431
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432 /**
433 * A handler that processes messages on the main thread in the phone process. Since many
434 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
435 * inbound binder threads to the main thread in the phone process. The Binder thread
436 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
437 * on, which will be notified when the operation completes and will contain the result of the
438 * request.
439 *
440 * <p>If a MainThreadRequest object is provided in the msg.obj field,
441 * note that request.result must be set to something non-null for the calling thread to
442 * unblock.
443 */
444 private final class MainThreadHandler extends Handler {
445 @Override
446 public void handleMessage(Message msg) {
447 MainThreadRequest request;
448 Message onCompleted;
449 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800450 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700451 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800452 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700453
454 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700455 case CMD_HANDLE_USSD_REQUEST: {
456 request = (MainThreadRequest) msg.obj;
457 final Phone phone = getPhoneFromRequest(request);
458 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
459 String ussdRequest = ussdObject.first;
460 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700461
Pengquan Menga1bb6272018-09-06 09:59:22 -0700462 if (!isUssdApiAllowed(request.subId)) {
463 // Carrier does not support use of this API, return failure.
464 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
465 UssdResponse response = new UssdResponse(ussdRequest, null);
466 Bundle returnData = new Bundle();
467 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
468 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700469
Pengquan Menga1bb6272018-09-06 09:59:22 -0700470 request.result = true;
471 notifyRequester(request);
472 return;
473 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700474
Pengquan Menga1bb6272018-09-06 09:59:22 -0700475 try {
476 request.result = phone != null
477 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
478 } catch (CallStateException cse) {
479 request.result = false;
480 }
481 // Wake up the requesting thread
482 notifyRequester(request);
483 break;
pkanwar32d516d2016-10-14 19:37:38 -0700484 }
485
Yorke Lee716f67e2015-06-17 15:39:16 -0700486 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700487 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700488 final Phone phone = getPhoneFromRequest(request);
489 request.result = phone != null ?
490 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
491 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700492 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700494 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700495 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700496
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700498 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800500 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700501 if (uiccCard == null) {
502 loge("iccTransmitApduLogicalChannel: No UICC");
503 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700504 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700505 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700506 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
507 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700508 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700509 iccArgument.channel, iccArgument.cla, iccArgument.command,
510 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700511 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700512 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700513 break;
514
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700515 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700516 ar = (AsyncResult) msg.obj;
517 request = (MainThreadRequest) ar.userObj;
518 if (ar.exception == null && ar.result != null) {
519 request.result = ar.result;
520 } else {
521 request.result = new IccIoResult(0x6F, 0, (byte[])null);
522 if (ar.result == null) {
523 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800524 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700525 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800526 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700527 } else {
528 loge("iccTransmitApduLogicalChannel: Unknown exception");
529 }
530 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700532 break;
533
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
535 request = (MainThreadRequest) msg.obj;
536 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800537 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 if (uiccCard == null) {
539 loge("iccTransmitApduBasicChannel: No UICC");
540 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700541 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700542 } else {
543 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
544 request);
545 uiccCard.iccTransmitApduBasicChannel(
546 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
547 iccArgument.p3, iccArgument.data, onCompleted);
548 }
549 break;
550
551 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
552 ar = (AsyncResult) msg.obj;
553 request = (MainThreadRequest) ar.userObj;
554 if (ar.exception == null && ar.result != null) {
555 request.result = ar.result;
556 } else {
557 request.result = new IccIoResult(0x6F, 0, (byte[])null);
558 if (ar.result == null) {
559 loge("iccTransmitApduBasicChannel: Empty response");
560 } else if (ar.exception instanceof CommandException) {
561 loge("iccTransmitApduBasicChannel: CommandException: " +
562 ar.exception);
563 } else {
564 loge("iccTransmitApduBasicChannel: Unknown exception");
565 }
566 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700567 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 break;
569
570 case CMD_EXCHANGE_SIM_IO:
571 request = (MainThreadRequest) msg.obj;
572 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800573 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 if (uiccCard == null) {
575 loge("iccExchangeSimIO: No UICC");
576 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700577 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700578 } else {
579 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
580 request);
581 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
582 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
583 iccArgument.data, onCompleted);
584 }
585 break;
586
587 case EVENT_EXCHANGE_SIM_IO_DONE:
588 ar = (AsyncResult) msg.obj;
589 request = (MainThreadRequest) ar.userObj;
590 if (ar.exception == null && ar.result != null) {
591 request.result = ar.result;
592 } else {
593 request.result = new IccIoResult(0x6f, 0, (byte[])null);
594 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700595 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 break;
597
Derek Tan4d5e5c12014-02-04 11:54:58 -0800598 case CMD_SEND_ENVELOPE:
599 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800600 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700601 if (uiccCard == null) {
602 loge("sendEnvelopeWithStatus: No UICC");
603 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700604 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700605 } else {
606 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
607 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
608 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800609 break;
610
611 case EVENT_SEND_ENVELOPE_DONE:
612 ar = (AsyncResult) msg.obj;
613 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700614 if (ar.exception == null && ar.result != null) {
615 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800616 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700617 request.result = new IccIoResult(0x6F, 0, (byte[])null);
618 if (ar.result == null) {
619 loge("sendEnvelopeWithStatus: Empty response");
620 } else if (ar.exception instanceof CommandException) {
621 loge("sendEnvelopeWithStatus: CommandException: " +
622 ar.exception);
623 } else {
624 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
625 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800626 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700627 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800628 break;
629
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 case CMD_OPEN_CHANNEL:
631 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800632 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800633 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700634 if (uiccCard == null) {
635 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800636 request.result = new IccOpenLogicalChannelResponse(-1,
637 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700638 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700639 } else {
640 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800641 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
642 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700643 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 break;
645
646 case EVENT_OPEN_CHANNEL_DONE:
647 ar = (AsyncResult) msg.obj;
648 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700649 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700651 int[] result = (int[]) ar.result;
652 int channelId = result[0];
653 byte[] selectResponse = null;
654 if (result.length > 1) {
655 selectResponse = new byte[result.length - 1];
656 for (int i = 1; i < result.length; ++i) {
657 selectResponse[i - 1] = (byte) result[i];
658 }
659 }
660 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700661 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 if (ar.result == null) {
664 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700666 if (ar.exception != null) {
667 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
668 }
669
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700670 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700671 if (ar.exception instanceof CommandException) {
672 CommandException.Error error =
673 ((CommandException) (ar.exception)).getCommandError();
674 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700675 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700676 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700677 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700678 }
679 }
680 openChannelResp = new IccOpenLogicalChannelResponse(
681 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700683 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700684 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700685 break;
686
687 case CMD_CLOSE_CHANNEL:
688 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800689 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700690 if (uiccCard == null) {
691 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900692 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700693 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700694 } else {
695 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
696 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
697 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700698 break;
699
700 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800701 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
702 break;
703
704 case CMD_NV_READ_ITEM:
705 request = (MainThreadRequest) msg.obj;
706 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800707 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
708 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800709 break;
710
711 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700712 ar = (AsyncResult) msg.obj;
713 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800714 if (ar.exception == null && ar.result != null) {
715 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700716 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800717 request.result = "";
718 if (ar.result == null) {
719 loge("nvReadItem: Empty response");
720 } else if (ar.exception instanceof CommandException) {
721 loge("nvReadItem: CommandException: " +
722 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700723 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800724 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700725 }
726 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700727 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700728 break;
729
Jake Hambye994d462014-02-03 13:10:13 -0800730 case CMD_NV_WRITE_ITEM:
731 request = (MainThreadRequest) msg.obj;
732 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
733 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800734 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700735 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800736 break;
737
738 case EVENT_NV_WRITE_ITEM_DONE:
739 handleNullReturnEvent(msg, "nvWriteItem");
740 break;
741
742 case CMD_NV_WRITE_CDMA_PRL:
743 request = (MainThreadRequest) msg.obj;
744 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800745 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800746 break;
747
748 case EVENT_NV_WRITE_CDMA_PRL_DONE:
749 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
750 break;
751
chen xu6dac5ab2018-10-26 17:39:23 -0700752 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800753 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700754 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800755 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800756 break;
757
chen xu6dac5ab2018-10-26 17:39:23 -0700758 case EVENT_RESET_MODEM_CONFIG_DONE:
759 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800760 break;
761
Sooraj Sasindran37444802020-08-11 10:40:43 -0700762 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
763 request = (MainThreadRequest) msg.obj;
764 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
765 request);
766 Phone phone = getPhoneFromRequest(request);
767 if (phone != null) {
768 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
769 } else {
770 loge("isNRDualConnectivityEnabled: No phone object");
771 request.result = false;
772 notifyRequester(request);
773 }
774 break;
775 }
776
777 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
778 ar = (AsyncResult) msg.obj;
779 request = (MainThreadRequest) ar.userObj;
780 if (ar.exception == null && ar.result != null) {
781 request.result = ar.result;
782 } else {
783 // request.result must be set to something non-null
784 // for the calling thread to unblock
785 if (request.result != null) {
786 request.result = ar.result;
787 } else {
788 request.result = false;
789 }
790 if (ar.result == null) {
791 loge("isNRDualConnectivityEnabled: Empty response");
792 } else if (ar.exception instanceof CommandException) {
793 loge("isNRDualConnectivityEnabled: CommandException: "
794 + ar.exception);
795 } else {
796 loge("isNRDualConnectivityEnabled: Unknown exception");
797 }
798 }
799 notifyRequester(request);
800 break;
801
802 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
803 request = (MainThreadRequest) msg.obj;
804 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
805 Phone phone = getPhoneFromRequest(request);
806 if (phone != null) {
807 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
808 request.workSource);
809 } else {
810 loge("enableNrDualConnectivity: No phone object");
811 request.result =
812 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
813 notifyRequester(request);
814 }
815 break;
816 }
817
818 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
819 ar = (AsyncResult) msg.obj;
820 request = (MainThreadRequest) ar.userObj;
821 if (ar.exception == null) {
822 request.result =
823 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
824 } else {
825 request.result =
826 TelephonyManager
827 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
828 if (ar.exception instanceof CommandException) {
829 CommandException.Error error =
830 ((CommandException) (ar.exception)).getCommandError();
831 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
832 request.result =
833 TelephonyManager
834 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
835 }
836 loge("enableNrDualConnectivity" + ": CommandException: "
837 + ar.exception);
838 } else {
839 loge("enableNrDualConnectivity" + ": Unknown exception");
840 }
841 }
842 notifyRequester(request);
843 break;
844 }
845
Jake Hamby7c27be32014-03-03 13:25:59 -0800846 case CMD_GET_PREFERRED_NETWORK_TYPE:
847 request = (MainThreadRequest) msg.obj;
848 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700849 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800850 break;
851
852 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
853 ar = (AsyncResult) msg.obj;
854 request = (MainThreadRequest) ar.userObj;
855 if (ar.exception == null && ar.result != null) {
856 request.result = ar.result; // Integer
857 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530858 // request.result must be set to something non-null
859 // for the calling thread to unblock
860 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800861 if (ar.result == null) {
862 loge("getPreferredNetworkType: Empty response");
863 } else if (ar.exception instanceof CommandException) {
864 loge("getPreferredNetworkType: CommandException: " +
865 ar.exception);
866 } else {
867 loge("getPreferredNetworkType: Unknown exception");
868 }
869 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700870 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800871 break;
872
873 case CMD_SET_PREFERRED_NETWORK_TYPE:
874 request = (MainThreadRequest) msg.obj;
875 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
876 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700877 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800878 break;
879
880 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
881 handleNullReturnEvent(msg, "setPreferredNetworkType");
882 break;
883
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000884 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
885 request = (MainThreadRequest)msg.obj;
886 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800887 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000888 break;
889
890 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
891 ar = (AsyncResult)msg.obj;
892 request = (MainThreadRequest)ar.userObj;
893 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700894 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000895 break;
896
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800897 case CMD_SET_VOICEMAIL_NUMBER:
898 request = (MainThreadRequest) msg.obj;
899 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
900 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800901 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
902 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800903 break;
904
905 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
906 handleNullReturnEvent(msg, "setVoicemailNumber");
907 break;
908
Stuart Scott54788802015-03-30 13:18:01 -0700909 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
910 request = (MainThreadRequest) msg.obj;
911 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
912 request);
913 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
914 break;
915
916 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
917 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
918 break;
919
Shishir Agrawal302c8692015-06-19 13:49:39 -0700920 case CMD_PERFORM_NETWORK_SCAN:
921 request = (MainThreadRequest) msg.obj;
922 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
923 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
924 break;
925
Hall Liu27d24262020-09-18 19:04:59 -0700926 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800927 request = (MainThreadRequest) msg.obj;
928 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700929 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
930 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
931 request.argument;
932 int callForwardingReason = args.first;
933 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800934 break;
Hall Liu27d24262020-09-18 19:04:59 -0700935 }
936 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800937 ar = (AsyncResult) msg.obj;
938 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700939 TelephonyManager.CallForwardingInfoCallback callback =
940 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
941 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800942 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700943 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800944 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
945 for (CallForwardInfo callForwardInfo : callForwardInfos) {
946 // Service Class is a bit mask per 3gpp 27.007. Search for
947 // any service for voice call.
948 if ((callForwardInfo.serviceClass
949 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700950 callForwardingInfo = new CallForwardingInfo(true,
951 callForwardInfo.reason,
952 callForwardInfo.number,
953 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800954 break;
955 }
956 }
957 // Didn't find a call forward info for voice call.
958 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700959 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
960 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -0800961 }
Hall Liu27d24262020-09-18 19:04:59 -0700962 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -0800963 } else {
964 if (ar.result == null) {
965 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
966 }
967 if (ar.exception != null) {
968 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
969 }
Hall Liu940c4ca2020-09-29 17:10:18 -0700970 int errorCode = TelephonyManager
971 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -0800972 if (ar.exception instanceof CommandException) {
973 CommandException.Error error =
974 ((CommandException) (ar.exception)).getCommandError();
975 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700976 errorCode = TelephonyManager
977 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -0800978 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700979 errorCode = TelephonyManager
980 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -0800981 }
982 }
Hall Liu27d24262020-09-18 19:04:59 -0700983 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -0800984 }
Shuo Qian4a594052020-01-23 11:59:30 -0800985 break;
Hall Liu27d24262020-09-18 19:04:59 -0700986 }
Shuo Qian4a594052020-01-23 11:59:30 -0800987
Hall Liu27d24262020-09-18 19:04:59 -0700988 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800989 request = (MainThreadRequest) msg.obj;
990 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700991 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -0800992 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -0700993 ((Pair<CallForwardingInfo, Consumer<Integer>>)
994 request.argument).first;
995 request.phone.setCallForwardingOption(
996 callForwardingInfoToSet.isEnabled()
997 ? CommandsInterface.CF_ACTION_ENABLE
998 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -0800999 callForwardingInfoToSet.getReason(),
1000 callForwardingInfoToSet.getNumber(),
1001 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1002 break;
Hall Liu27d24262020-09-18 19:04:59 -07001003 }
Shuo Qian4a594052020-01-23 11:59:30 -08001004
Hall Liu27d24262020-09-18 19:04:59 -07001005 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001006 ar = (AsyncResult) msg.obj;
1007 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001008 Consumer<Integer> callback =
1009 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1010 request.argument).second;
1011 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001012 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001013 int errorCode = TelephonyManager.CallForwardingInfoCallback
1014 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001015 if (ar.exception instanceof CommandException) {
1016 CommandException.Error error =
1017 ((CommandException) (ar.exception)).getCommandError();
1018 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001019 errorCode = TelephonyManager.CallForwardingInfoCallback
1020 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001021 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001022 errorCode = TelephonyManager.CallForwardingInfoCallback
1023 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001024 }
1025 }
1026 callback.accept(errorCode);
1027 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001028 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001029 }
Shuo Qian4a594052020-01-23 11:59:30 -08001030 break;
Hall Liu27d24262020-09-18 19:04:59 -07001031 }
Shuo Qian4a594052020-01-23 11:59:30 -08001032
Hall Liu27d24262020-09-18 19:04:59 -07001033 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001034 request = (MainThreadRequest) msg.obj;
1035 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1036 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1037 break;
Hall Liu27d24262020-09-18 19:04:59 -07001038 }
Shuo Qian4a594052020-01-23 11:59:30 -08001039
Hall Liu27d24262020-09-18 19:04:59 -07001040 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001043 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001044 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1045 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001046 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001047 // Service Class is a bit mask per 3gpp 27.007.
1048 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001049 if (callForwardResults.length > 1
1050 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001051 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001052 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001053 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1054 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001055 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001056 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001057 }
1058 } else {
1059 if (ar.result == null) {
1060 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1061 }
1062 if (ar.exception != null) {
1063 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1064 }
1065 if (ar.exception instanceof CommandException) {
1066 CommandException.Error error =
1067 ((CommandException) (ar.exception)).getCommandError();
1068 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1069 callForwardingStatus =
1070 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1071 }
1072 }
1073 }
Hall Liu27d24262020-09-18 19:04:59 -07001074 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001075 break;
Hall Liu27d24262020-09-18 19:04:59 -07001076 }
Shuo Qian4a594052020-01-23 11:59:30 -08001077
Hall Liu27d24262020-09-18 19:04:59 -07001078 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001079 request = (MainThreadRequest) msg.obj;
1080 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001081 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1082 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001083 break;
Hall Liu27d24262020-09-18 19:04:59 -07001084 }
Shuo Qian4a594052020-01-23 11:59:30 -08001085
Hall Liu27d24262020-09-18 19:04:59 -07001086 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001087 ar = (AsyncResult) msg.obj;
1088 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001089 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1090 Consumer<Integer> callback =
1091 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1092 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001093 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001094 if (ar.exception instanceof CommandException) {
1095 CommandException.Error error =
1096 ((CommandException) (ar.exception)).getCommandError();
1097 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1098 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1099 } else {
1100 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1101 }
1102 } else {
1103 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1104 }
1105 } else {
1106 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1107 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001108 }
Shuo Qian4a594052020-01-23 11:59:30 -08001109 break;
Hall Liu27d24262020-09-18 19:04:59 -07001110 }
Shuo Qian4a594052020-01-23 11:59:30 -08001111
Shishir Agrawal302c8692015-06-19 13:49:39 -07001112 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1113 ar = (AsyncResult) msg.obj;
1114 request = (MainThreadRequest) ar.userObj;
1115 CellNetworkScanResult cellScanResult;
1116 if (ar.exception == null && ar.result != null) {
1117 cellScanResult = new CellNetworkScanResult(
1118 CellNetworkScanResult.STATUS_SUCCESS,
1119 (List<OperatorInfo>) ar.result);
1120 } else {
1121 if (ar.result == null) {
1122 loge("getCellNetworkScanResults: Empty response");
1123 }
1124 if (ar.exception != null) {
1125 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1126 }
1127 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1128 if (ar.exception instanceof CommandException) {
1129 CommandException.Error error =
1130 ((CommandException) (ar.exception)).getCommandError();
1131 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1132 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1133 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1134 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1135 }
1136 }
1137 cellScanResult = new CellNetworkScanResult(errorCode, null);
1138 }
1139 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001140 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001141 break;
1142
1143 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1144 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001145 ManualNetworkSelectionArgument selArg =
1146 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001147 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1148 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001149 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1150 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001151 break;
1152
1153 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001154 ar = (AsyncResult) msg.obj;
1155 request = (MainThreadRequest) ar.userObj;
1156 if (ar.exception == null) {
1157 request.result = true;
1158 } else {
1159 request.result = false;
1160 loge("setNetworkSelectionModeManual " + ar.exception);
1161 }
1162 notifyRequester(request);
1163 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001164 break;
1165
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001166 case CMD_GET_MODEM_ACTIVITY_INFO:
1167 request = (MainThreadRequest) msg.obj;
1168 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001169 if (defaultPhone != null) {
1170 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001171 } else {
1172 ResultReceiver result = (ResultReceiver) request.argument;
1173 Bundle bundle = new Bundle();
1174 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001175 new ModemActivityInfo(0, 0, 0,
1176 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001177 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001178 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001179 break;
1180
Hall Liud0f208c2020-10-14 16:54:44 -07001181 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001182 ar = (AsyncResult) msg.obj;
1183 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001184 ResultReceiver result = (ResultReceiver) request.argument;
1185
Hall Liud0f208c2020-10-14 16:54:44 -07001186 ModemActivityInfo ret = null;
1187 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001188 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001189 // Update the last modem activity info and the result of the request.
1190 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1191 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001192 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001193 int[] txTimeMs = info.getTransmitTimeMillis();
1194 int[] lastModemTxTimeMs = mLastModemActivityInfo
1195 .getTransmitTimeMillis();
1196 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1197 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1198 }
Hall Liu49656c02020-10-09 19:00:11 -07001199 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001200 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1201 + mLastModemActivityInfo.getSleepTimeMillis());
1202 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1203 + mLastModemActivityInfo.getIdleTimeMillis());
1204 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1205 mLastModemActivityInfo.setReceiveTimeMillis(
1206 info.getReceiveTimeMillis()
1207 + mLastModemActivityInfo.getReceiveTimeMillis());
1208 }
Hall Liu49656c02020-10-09 19:00:11 -07001209 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001210 mLastModemActivityInfo.getSleepTimeMillis(),
1211 mLastModemActivityInfo.getIdleTimeMillis(),
1212 mLastModemActivityInfo.getTransmitTimeMillis(),
1213 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001214 } else {
1215 if (ar.result == null) {
1216 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001217 error = TelephonyManager.ModemActivityInfoException
1218 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001219 } else if (ar.exception instanceof CommandException) {
1220 loge("queryModemActivityInfo: CommandException: " +
1221 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001222 error = TelephonyManager.ModemActivityInfoException
1223 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001224 } else {
1225 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001226 error = TelephonyManager.ModemActivityInfoException
1227 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001228 }
1229 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001230 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001231 if (ret != null) {
1232 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1233 } else {
1234 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1235 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001236 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001237 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001238 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001239 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001240
Meng Wang1a7c35a2016-05-05 20:56:15 -07001241 case CMD_SET_ALLOWED_CARRIERS:
1242 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001243 CarrierRestrictionRules argument =
1244 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001245 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001246 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001247 break;
1248
1249 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1250 ar = (AsyncResult) msg.obj;
1251 request = (MainThreadRequest) ar.userObj;
1252 if (ar.exception == null && ar.result != null) {
1253 request.result = ar.result;
1254 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001255 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1256 if (ar.exception instanceof CommandException) {
1257 loge("setAllowedCarriers: CommandException: " + ar.exception);
1258 CommandException.Error error =
1259 ((CommandException) (ar.exception)).getCommandError();
1260 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1261 request.result =
1262 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1263 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001264 } else {
1265 loge("setAllowedCarriers: Unknown exception");
1266 }
1267 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001268 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001269 break;
1270
1271 case CMD_GET_ALLOWED_CARRIERS:
1272 request = (MainThreadRequest) msg.obj;
1273 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001274 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001275 break;
1276
1277 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1278 ar = (AsyncResult) msg.obj;
1279 request = (MainThreadRequest) ar.userObj;
1280 if (ar.exception == null && ar.result != null) {
1281 request.result = ar.result;
1282 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001283 request.result = new IllegalStateException(
1284 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001285 if (ar.result == null) {
1286 loge("getAllowedCarriers: Empty response");
1287 } else if (ar.exception instanceof CommandException) {
1288 loge("getAllowedCarriers: CommandException: " +
1289 ar.exception);
1290 } else {
1291 loge("getAllowedCarriers: Unknown exception");
1292 }
1293 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001294 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001295 break;
1296
Nathan Haroldb3014052017-01-25 15:57:32 -08001297 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1298 ar = (AsyncResult) msg.obj;
1299 request = (MainThreadRequest) ar.userObj;
1300 if (ar.exception == null && ar.result != null) {
1301 request.result = ar.result;
1302 } else {
1303 request.result = new IllegalArgumentException(
1304 "Failed to retrieve Forbidden Plmns");
1305 if (ar.result == null) {
1306 loge("getForbiddenPlmns: Empty response");
1307 } else {
1308 loge("getForbiddenPlmns: Unknown exception");
1309 }
1310 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001311 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001312 break;
1313
1314 case CMD_GET_FORBIDDEN_PLMNS:
1315 request = (MainThreadRequest) msg.obj;
1316 uiccCard = getUiccCardFromRequest(request);
1317 if (uiccCard == null) {
1318 loge("getForbiddenPlmns() UiccCard is null");
1319 request.result = new IllegalArgumentException(
1320 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001321 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001322 break;
1323 }
1324 Integer appType = (Integer) request.argument;
1325 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1326 if (uiccApp == null) {
1327 loge("getForbiddenPlmns() no app with specified type -- "
1328 + appType);
1329 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001330 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001331 break;
1332 } else {
1333 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1334 + " specified type -- " + appType);
1335 }
1336 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1337 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1338 onCompleted);
1339 break;
1340
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001341 case CMD_SWITCH_SLOTS:
1342 request = (MainThreadRequest) msg.obj;
1343 int[] physicalSlots = (int[]) request.argument;
1344 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1345 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1346 break;
1347
1348 case EVENT_SWITCH_SLOTS_DONE:
1349 ar = (AsyncResult) msg.obj;
1350 request = (MainThreadRequest) ar.userObj;
1351 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001352 notifyRequester(request);
1353 break;
1354 case CMD_GET_NETWORK_SELECTION_MODE:
1355 request = (MainThreadRequest) msg.obj;
1356 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1357 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1358 break;
1359
1360 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1361 ar = (AsyncResult) msg.obj;
1362 request = (MainThreadRequest) ar.userObj;
1363 if (ar.exception != null) {
1364 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1365 } else {
1366 int mode = ((int[]) ar.result)[0];
1367 if (mode == 0) {
1368 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1369 } else {
1370 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1371 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001372 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001373 notifyRequester(request);
1374 break;
1375 case CMD_GET_CDMA_ROAMING_MODE:
1376 request = (MainThreadRequest) msg.obj;
1377 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1378 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1379 break;
1380 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1381 ar = (AsyncResult) msg.obj;
1382 request = (MainThreadRequest) ar.userObj;
1383 if (ar.exception != null) {
1384 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1385 } else {
1386 request.result = ((int[]) ar.result)[0];
1387 }
1388 notifyRequester(request);
1389 break;
1390 case CMD_SET_CDMA_ROAMING_MODE:
1391 request = (MainThreadRequest) msg.obj;
1392 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1393 int mode = (int) request.argument;
1394 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1395 break;
1396 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1397 ar = (AsyncResult) msg.obj;
1398 request = (MainThreadRequest) ar.userObj;
1399 request.result = ar.exception == null;
1400 notifyRequester(request);
1401 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001402 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1403 request = (MainThreadRequest) msg.obj;
1404 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1405 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1406 break;
1407 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1408 ar = (AsyncResult) msg.obj;
1409 request = (MainThreadRequest) ar.userObj;
1410 if (ar.exception != null) {
1411 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1412 } else {
1413 request.result = ((int[]) ar.result)[0];
1414 }
1415 notifyRequester(request);
1416 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001417 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1418 request = (MainThreadRequest) msg.obj;
1419 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1420 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001421 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1422 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001423 break;
1424 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1425 ar = (AsyncResult) msg.obj;
1426 request = (MainThreadRequest) ar.userObj;
1427 request.result = ar.exception == null;
1428 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001429 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001430 case CMD_GET_ALL_CELL_INFO:
1431 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001432 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001433 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001434 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001435 case EVENT_GET_ALL_CELL_INFO_DONE:
1436 ar = (AsyncResult) msg.obj;
1437 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001438 // If a timeout occurs, the response will be null
1439 request.result = (ar.exception == null && ar.result != null)
1440 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001441 synchronized (request) {
1442 request.notifyAll();
1443 }
1444 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001445 case CMD_REQUEST_CELL_INFO_UPDATE:
1446 request = (MainThreadRequest) msg.obj;
1447 request.phone.requestCellInfoUpdate(request.workSource,
1448 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1449 break;
1450 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1451 ar = (AsyncResult) msg.obj;
1452 request = (MainThreadRequest) ar.userObj;
1453 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1454 try {
1455 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001456 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001457 cb.onError(
1458 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1459 ar.exception.getClass().getName(),
1460 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001461 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001462 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001463 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001464 } else {
1465 // use the result as returned
1466 cb.onCellInfo((List<CellInfo>) ar.result);
1467 }
1468 } catch (RemoteException re) {
1469 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1470 }
1471 break;
1472 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001473 request = (MainThreadRequest) msg.obj;
1474 WorkSource ws = (WorkSource) request.argument;
1475 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001476 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001477 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001478 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001479 ar = (AsyncResult) msg.obj;
1480 request = (MainThreadRequest) ar.userObj;
1481 if (ar.exception == null) {
1482 request.result = ar.result;
1483 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001484 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001485 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001486 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001487 }
1488
1489 synchronized (request) {
1490 request.notifyAll();
1491 }
1492 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001493 case CMD_MODEM_REBOOT:
1494 request = (MainThreadRequest) msg.obj;
1495 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001496 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001497 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001498 case EVENT_CMD_MODEM_REBOOT_DONE:
1499 handleNullReturnEvent(msg, "rebootModem");
1500 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001501 case CMD_REQUEST_ENABLE_MODEM:
1502 request = (MainThreadRequest) msg.obj;
1503 boolean enable = (boolean) request.argument;
1504 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001505 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001506 PhoneConfigurationManager.getInstance()
1507 .enablePhone(request.phone, enable, onCompleted);
1508 break;
1509 case EVENT_ENABLE_MODEM_DONE:
1510 ar = (AsyncResult) msg.obj;
1511 request = (MainThreadRequest) ar.userObj;
1512 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001513 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001514 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001515 if ((boolean) request.result) {
1516 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1517 updateModemStateMetrics();
1518 } else {
1519 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1520 + ar.exception);
1521 }
1522 notifyRequester(request);
1523 break;
1524 case CMD_GET_MODEM_STATUS:
1525 request = (MainThreadRequest) msg.obj;
1526 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1527 PhoneConfigurationManager.getInstance()
1528 .getPhoneStatusFromModem(request.phone, onCompleted);
1529 break;
1530 case EVENT_GET_MODEM_STATUS_DONE:
1531 ar = (AsyncResult) msg.obj;
1532 request = (MainThreadRequest) ar.userObj;
1533 int id = request.phone.getPhoneId();
1534 if (ar.exception == null && ar.result != null) {
1535 request.result = ar.result;
1536 //update the cache as modem status has changed
1537 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1538 (boolean) request.result);
1539 } else {
1540 // Return true if modem status cannot be retrieved. For most cases,
1541 // modem status is on. And for older version modems, GET_MODEM_STATUS
1542 // and disable modem are not supported. Modem is always on.
1543 // TODO: this should be fixed in R to support a third
1544 // status UNKNOWN b/131631629
1545 request.result = true;
1546 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1547 + ar.exception);
1548 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001549 notifyRequester(request);
1550 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001551 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1552 request = (MainThreadRequest) msg.obj;
1553 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1554 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1555 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1556 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1557 break;
1558 }
1559 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1560 ar = (AsyncResult) msg.obj;
1561 request = (MainThreadRequest) ar.userObj;
1562 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1563 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1564 args.second.accept(ar.exception == null);
1565 notifyRequester(request);
1566 break;
1567 }
yincheng zhao2737e882019-09-06 17:06:54 -07001568 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1569 ar = (AsyncResult) msg.obj;
1570 request = (MainThreadRequest) ar.userObj;
1571 if (ar.exception == null && ar.result != null) {
1572 request.result = ar.result;
1573 } else {
1574 request.result = -1;
1575 loge("Failed to set Forbidden Plmns");
1576 if (ar.result == null) {
1577 loge("setForbidenPlmns: Empty response");
1578 } else if (ar.exception != null) {
1579 loge("setForbiddenPlmns: Exception: " + ar.exception);
1580 request.result = -1;
1581 } else {
1582 loge("setForbiddenPlmns: Unknown exception");
1583 }
1584 }
1585 notifyRequester(request);
1586 break;
1587 case CMD_SET_FORBIDDEN_PLMNS:
1588 request = (MainThreadRequest) msg.obj;
1589 uiccCard = getUiccCardFromRequest(request);
1590 if (uiccCard == null) {
1591 loge("setForbiddenPlmns: UiccCard is null");
1592 request.result = -1;
1593 notifyRequester(request);
1594 break;
1595 }
1596 Pair<Integer, List<String>> setFplmnsArgs =
1597 (Pair<Integer, List<String>>) request.argument;
1598 appType = setFplmnsArgs.first;
1599 List<String> fplmns = setFplmnsArgs.second;
1600 uiccApp = uiccCard.getApplicationByType(appType);
1601 if (uiccApp == null) {
1602 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1603 request.result = -1;
1604 loge("Failed to get UICC App");
1605 notifyRequester(request);
1606 } else {
1607 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1608 ((SIMRecords) uiccApp.getIccRecords())
1609 .setForbiddenPlmns(onCompleted, fplmns);
1610 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001611 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001612 case CMD_ERASE_MODEM_CONFIG:
1613 request = (MainThreadRequest) msg.obj;
1614 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1615 defaultPhone.eraseModemConfig(onCompleted);
1616 break;
1617 case EVENT_ERASE_MODEM_CONFIG_DONE:
1618 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001619 break;
zoey chene02881a2019-12-30 16:11:23 +08001620
1621 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1622 request = (MainThreadRequest) msg.obj;
1623 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1624 Pair<String, String> changed = (Pair<String, String>) request.argument;
1625 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1626 changed.first, changed.second, onCompleted);
1627 break;
1628 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1629 ar = (AsyncResult) msg.obj;
1630 request = (MainThreadRequest) ar.userObj;
1631 if (ar.exception == null) {
1632 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1633 } else {
1634 request.result = msg.arg1;
1635 }
1636 notifyRequester(request);
1637 break;
1638
1639 case CMD_SET_ICC_LOCK_ENABLED:
1640 request = (MainThreadRequest) msg.obj;
1641 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1642 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1643 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1644 enabled.first, enabled.second, onCompleted);
1645 break;
1646 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1647 ar = (AsyncResult) msg.obj;
1648 request = (MainThreadRequest) ar.userObj;
1649 if (ar.exception == null) {
1650 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1651 } else {
1652 request.result = msg.arg1;
1653 }
1654 notifyRequester(request);
1655 break;
1656
Peter Wangdafb9ac2020-01-15 14:13:38 -08001657 case MSG_NOTIFY_USER_ACTIVITY:
1658 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001659 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001660 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1661 getDefaultPhone().getContext().sendBroadcastAsUser(
1662 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1663 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001664 default:
1665 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1666 break;
1667 }
1668 }
Jake Hambye994d462014-02-03 13:10:13 -08001669
Pengquan Menga1bb6272018-09-06 09:59:22 -07001670 private void notifyRequester(MainThreadRequest request) {
1671 synchronized (request) {
1672 request.notifyAll();
1673 }
1674 }
1675
Jake Hambye994d462014-02-03 13:10:13 -08001676 private void handleNullReturnEvent(Message msg, String command) {
1677 AsyncResult ar = (AsyncResult) msg.obj;
1678 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1679 if (ar.exception == null) {
1680 request.result = true;
1681 } else {
1682 request.result = false;
1683 if (ar.exception instanceof CommandException) {
1684 loge(command + ": CommandException: " + ar.exception);
1685 } else {
1686 loge(command + ": Unknown exception");
1687 }
1688 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001689 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 }
1692
1693 /**
1694 * Posts the specified command to be executed on the main thread,
1695 * waits for the request to complete, and returns the result.
1696 * @see #sendRequestAsync
1697 */
1698 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001699 return sendRequest(
1700 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001701 }
1702
1703 /**
1704 * Posts the specified command to be executed on the main thread,
1705 * waits for the request to complete, and returns the result.
1706 * @see #sendRequestAsync
1707 */
1708 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1709 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001710 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001711 }
1712
1713 /**
1714 * Posts the specified command to be executed on the main thread,
1715 * waits for the request to complete, and returns the result.
1716 * @see #sendRequestAsync
1717 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001718 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001719 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001720 }
1721
1722 /**
1723 * Posts the specified command to be executed on the main thread,
1724 * waits for the request to complete, and returns the result.
1725 * @see #sendRequestAsync
1726 */
Nathan Harold92bed182018-10-12 18:16:49 -07001727 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1728 return sendRequest(command, argument, subId, null, workSource);
1729 }
1730
1731 /**
1732 * Posts the specified command to be executed on the main thread,
1733 * waits for the request to complete, and returns the result.
1734 * @see #sendRequestAsync
1735 */
1736 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1737 return sendRequest(
1738 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1739 }
1740
1741 /**
1742 * Posts the specified command to be executed on the main thread,
1743 * waits for the request to complete, and returns the result.
1744 * @see #sendRequestAsync
1745 */
1746 private Object sendRequest(
1747 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1749 throw new RuntimeException("This method will deadlock if called from the main thread.");
1750 }
1751
Nathan Harold92bed182018-10-12 18:16:49 -07001752 MainThreadRequest request = null;
1753 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1754 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1755 } else if (phone != null) {
1756 request = new MainThreadRequest(argument, phone, workSource);
1757 } else {
1758 request = new MainThreadRequest(argument, subId, workSource);
1759 }
1760
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 Message msg = mMainThreadHandler.obtainMessage(command, request);
1762 msg.sendToTarget();
1763
1764 // Wait for the request to complete
1765 synchronized (request) {
1766 while (request.result == null) {
1767 try {
1768 request.wait();
1769 } catch (InterruptedException e) {
1770 // Do nothing, go back and wait until the request is complete
1771 }
1772 }
1773 }
1774 return request.result;
1775 }
1776
1777 /**
1778 * Asynchronous ("fire and forget") version of sendRequest():
1779 * Posts the specified command to be executed on the main thread, and
1780 * returns immediately.
1781 * @see #sendRequest
1782 */
1783 private void sendRequestAsync(int command) {
1784 mMainThreadHandler.sendEmptyMessage(command);
1785 }
1786
1787 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001788 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001789 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001790 */
1791 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001792 sendRequestAsync(command, argument, null, null);
1793 }
1794
1795 /**
1796 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1797 * @see {@link #sendRequest(int,Object)}
1798 */
1799 private void sendRequestAsync(
1800 int command, Object argument, Phone phone, WorkSource workSource) {
1801 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001802 Message msg = mMainThreadHandler.obtainMessage(command, request);
1803 msg.sendToTarget();
1804 }
1805
1806 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 * Initialize the singleton PhoneInterfaceManager instance.
1808 * This is only done once, at startup, from PhoneApp.onCreate().
1809 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001810 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 synchronized (PhoneInterfaceManager.class) {
1812 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001813 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 } else {
1815 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1816 }
1817 return sInstance;
1818 }
1819 }
1820
1821 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001822 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001825 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001826 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1828 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001829 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001830 mTelephonySharedPreferences =
1831 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001832 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001833 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001834 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001835
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836 publish();
1837 }
1838
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001839 private Phone getDefaultPhone() {
1840 Phone thePhone = getPhone(getDefaultSubscription());
1841 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1842 }
1843
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001844 private void publish() {
1845 if (DBG) log("publish: " + this);
1846
Peter Wangc035ce42020-01-08 21:00:22 -08001847 TelephonyFrameworkInitializer
1848 .getTelephonyServiceManager()
1849 .getTelephonyServiceRegisterer()
1850 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001851 }
1852
Stuart Scott584921c2015-01-15 17:10:34 -08001853 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001854 if (request.phone != null) {
1855 return request.phone;
1856 } else {
1857 return getPhoneFromSubId(request.subId);
1858 }
1859 }
1860
1861 private Phone getPhoneFromSubId(int subId) {
1862 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1863 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001864 }
1865
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001866 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1867 Phone phone = getPhoneFromRequest(request);
1868 return phone == null ? null :
1869 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1870 }
1871
Wink Saville36469e72014-06-11 15:17:00 -07001872 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001873 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001874 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001875 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876
Naina Nallurid63128d2019-09-17 14:10:30 -07001877 private void sendEraseModemConfig(Phone phone) {
1878 if (phone != null) {
1879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1880 mApp, phone.getSubId(), "eraseModemConfig");
1881 final long identity = Binder.clearCallingIdentity();
1882 try {
1883 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1884 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1885 } finally {
1886 Binder.restoreCallingIdentity(identity);
1887 }
1888 }
1889 }
1890
Peter Wang44b186e2020-01-13 23:33:09 -08001891 private boolean isImsAvailableOnDevice() {
1892 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1893 if (pm == null) {
1894 // For some reason package manger is not available.. This will fail internally anyway,
1895 // so do not throw error and allow.
1896 return true;
1897 }
1898 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1899 }
1900
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001901 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001902 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001903 }
1904
Wink Savilleb564aae2014-10-23 10:18:09 -07001905 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001906 if (DBG) log("dial: " + number);
1907 // No permission check needed here: This is just a wrapper around the
1908 // ACTION_DIAL intent, which is available to any app since it puts up
1909 // the UI before it does anything.
1910
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001911 final long identity = Binder.clearCallingIdentity();
1912 try {
1913 String url = createTelUrl(number);
1914 if (url == null) {
1915 return;
1916 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001917
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001918 // PENDING: should we just silently fail if phone is offhook or ringing?
1919 PhoneConstants.State state = mCM.getState(subId);
1920 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1921 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1922 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1923 mApp.startActivity(intent);
1924 }
1925 } finally {
1926 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001927 }
1928 }
1929
1930 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001931 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001932 }
1933
Wink Savilleb564aae2014-10-23 10:18:09 -07001934 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001935 if (DBG) log("call: " + number);
1936
1937 // This is just a wrapper around the ACTION_CALL intent, but we still
1938 // need to do a permission check since we're calling startActivity()
1939 // from the context of the phone app.
1940 enforceCallPermission();
1941
Jordan Liu1617b712019-07-10 15:06:26 -07001942 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 != AppOpsManager.MODE_ALLOWED) {
1944 return;
1945 }
1946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001947 final long identity = Binder.clearCallingIdentity();
1948 try {
1949 String url = createTelUrl(number);
1950 if (url == null) {
1951 return;
1952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001954 boolean isValid = false;
1955 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1956 if (slist != null) {
1957 for (SubscriptionInfo subInfoRecord : slist) {
1958 if (subInfoRecord.getSubscriptionId() == subId) {
1959 isValid = true;
1960 break;
1961 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001962 }
Wink Saville08874612014-08-31 19:19:58 -07001963 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001964 if (!isValid) {
1965 return;
1966 }
Wink Saville08874612014-08-31 19:19:58 -07001967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001968 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1969 intent.putExtra(SUBSCRIPTION_KEY, subId);
1970 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1971 mApp.startActivity(intent);
1972 } finally {
1973 Binder.restoreCallingIdentity(identity);
1974 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 }
1976
Wink Savilleb564aae2014-10-23 10:18:09 -07001977 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001978 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001979 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1980 }
1981
Wink Savilleb564aae2014-10-23 10:18:09 -07001982 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001983 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001984 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1985 }
1986
Wink Savilleb564aae2014-10-23 10:18:09 -07001987 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001988 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001989
1990 final long identity = Binder.clearCallingIdentity();
1991 try {
1992 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1993 checkSimPin.start();
1994 return checkSimPin.unlockSim(null, pin);
1995 } finally {
1996 Binder.restoreCallingIdentity(identity);
1997 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001998 }
1999
Wink Savilleb564aae2014-10-23 10:18:09 -07002000 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002001 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002002
2003 final long identity = Binder.clearCallingIdentity();
2004 try {
2005 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2006 checkSimPuk.start();
2007 return checkSimPuk.unlockSim(puk, pin);
2008 } finally {
2009 Binder.restoreCallingIdentity(identity);
2010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002011 }
2012
2013 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002014 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002015 * a synchronous one.
2016 */
2017 private static class UnlockSim extends Thread {
2018
2019 private final IccCard mSimCard;
2020
2021 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002022 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2023 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002024
2025 // For replies from SimCard interface
2026 private Handler mHandler;
2027
2028 // For async handler to identify request type
2029 private static final int SUPPLY_PIN_COMPLETE = 100;
2030
2031 public UnlockSim(IccCard simCard) {
2032 mSimCard = simCard;
2033 }
2034
2035 @Override
2036 public void run() {
2037 Looper.prepare();
2038 synchronized (UnlockSim.this) {
2039 mHandler = new Handler() {
2040 @Override
2041 public void handleMessage(Message msg) {
2042 AsyncResult ar = (AsyncResult) msg.obj;
2043 switch (msg.what) {
2044 case SUPPLY_PIN_COMPLETE:
2045 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2046 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002047 mRetryCount = msg.arg1;
2048 if (ar.exception != null) {
2049 if (ar.exception instanceof CommandException &&
2050 ((CommandException)(ar.exception)).getCommandError()
2051 == CommandException.Error.PASSWORD_INCORRECT) {
2052 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002053 } //When UiccCardApp dispose,handle message and return exception
2054 else if (ar.exception instanceof CommandException &&
2055 ((CommandException) (ar.exception)).getCommandError()
2056 == CommandException.Error.ABORTED) {
2057 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002058 } else {
2059 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2060 }
2061 } else {
2062 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2063 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002064 mDone = true;
2065 UnlockSim.this.notifyAll();
2066 }
2067 break;
2068 }
2069 }
2070 };
2071 UnlockSim.this.notifyAll();
2072 }
2073 Looper.loop();
2074 }
2075
2076 /*
2077 * Use PIN or PUK to unlock SIM card
2078 *
2079 * If PUK is null, unlock SIM card with PIN
2080 *
2081 * If PUK is not null, unlock SIM card with PUK and set PIN code
2082 */
Wink Saville9de0f752013-10-22 19:04:03 -07002083 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002084
2085 while (mHandler == null) {
2086 try {
2087 wait();
2088 } catch (InterruptedException e) {
2089 Thread.currentThread().interrupt();
2090 }
2091 }
2092 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2093
2094 if (puk == null) {
2095 mSimCard.supplyPin(pin, callback);
2096 } else {
2097 mSimCard.supplyPuk(puk, pin, callback);
2098 }
2099
2100 while (!mDone) {
2101 try {
2102 Log.d(LOG_TAG, "wait for done");
2103 wait();
2104 } catch (InterruptedException e) {
2105 // Restore the interrupted status
2106 Thread.currentThread().interrupt();
2107 }
2108 }
2109 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002110 int[] resultArray = new int[2];
2111 resultArray[0] = mResult;
2112 resultArray[1] = mRetryCount;
2113 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002114 }
2115 }
2116
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002117 /**
2118 * This method has been removed due to privacy and stability concerns.
2119 */
2120 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002121 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002122 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2123 return;
Wink Saville36469e72014-06-11 15:17:00 -07002124 }
2125
Nathan Harold1f889d82020-06-04 17:05:26 -07002126 @Override
2127 public void updateServiceLocationWithPackageName(String callingPackage) {
2128 mApp.getSystemService(AppOpsManager.class)
2129 .checkPackage(Binder.getCallingUid(), callingPackage);
2130
2131 final int targetSdk = getTargetSdk(callingPackage);
2132 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2133 // Callers targeting S have no business invoking this method.
2134 return;
2135 }
2136
2137 LocationAccessPolicy.LocationPermissionResult locationResult =
2138 LocationAccessPolicy.checkLocationPermission(mApp,
2139 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2140 .setCallingPackage(callingPackage)
2141 .setCallingFeatureId(null)
2142 .setCallingPid(Binder.getCallingPid())
2143 .setCallingUid(Binder.getCallingUid())
2144 .setMethod("updateServiceLocation")
2145 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2146 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2147 .build());
2148 // Apps that lack location permission have no business calling this method;
2149 // however, because no permission was declared in the public API, denials must
2150 // all be "soft".
2151 switch (locationResult) {
2152 case DENIED_HARD: /* fall through */
2153 case DENIED_SOFT:
2154 return;
2155 }
2156
2157 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002158 final long identity = Binder.clearCallingIdentity();
2159 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002160 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002161 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002162 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002163 }
2164 } finally {
2165 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002166 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 }
2168
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002169 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002170 @Override
2171 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002172 return isRadioOnWithFeature(callingPackage, null);
2173 }
2174
2175
2176 @Override
2177 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2178 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2179 callingFeatureId);
2180 }
2181
2182 @Deprecated
2183 @Override
2184 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2185 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002186 }
2187
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002188 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002189 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2190 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002191 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002192 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002193 return false;
2194 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002195
2196 final long identity = Binder.clearCallingIdentity();
2197 try {
2198 return isRadioOnForSubscriber(subId);
2199 } finally {
2200 Binder.restoreCallingIdentity(identity);
2201 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002202 }
2203
2204 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002205 final long identity = Binder.clearCallingIdentity();
2206 try {
2207 final Phone phone = getPhone(subId);
2208 if (phone != null) {
2209 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2210 } else {
2211 return false;
2212 }
2213 } finally {
2214 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 }
2217
2218 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002219 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
Wink Saville36469e72014-06-11 15:17:00 -07002221
Wink Savilleb564aae2014-10-23 10:18:09 -07002222 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002223 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002224
2225 final long identity = Binder.clearCallingIdentity();
2226 try {
2227 final Phone phone = getPhone(subId);
2228 if (phone != null) {
2229 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2230 }
2231 } finally {
2232 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002233 }
Wink Saville36469e72014-06-11 15:17:00 -07002234 }
2235
2236 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002237 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002238 }
2239
Wink Savilleb564aae2014-10-23 10:18:09 -07002240 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002241 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002242
2243 final long identity = Binder.clearCallingIdentity();
2244 try {
2245 final Phone phone = getPhone(subId);
2246 if (phone == null) {
2247 return false;
2248 }
2249 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2250 toggleRadioOnOffForSubscriber(subId);
2251 }
2252 return true;
2253 } finally {
2254 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 }
Wink Saville36469e72014-06-11 15:17:00 -07002257
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002258 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002259 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002260 /*
2261 * If any of the Radios are available, it will need to be
2262 * shutdown. So return true if any Radio is available.
2263 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002264 final long identity = Binder.clearCallingIdentity();
2265 try {
2266 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2267 Phone phone = PhoneFactory.getPhone(i);
2268 if (phone != null && phone.isRadioAvailable()) return true;
2269 }
2270 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2271 return false;
2272 } finally {
2273 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002274 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002275 }
2276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002277 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002278 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002279 enforceModifyPermission();
2280
2281 final long identity = Binder.clearCallingIdentity();
2282 try {
2283 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2284 logv("Shutting down Phone " + i);
2285 shutdownRadioUsingPhoneId(i);
2286 }
2287 } finally {
2288 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002289 }
2290 }
2291
2292 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002293 Phone phone = PhoneFactory.getPhone(phoneId);
2294 if (phone != null && phone.isRadioAvailable()) {
2295 phone.shutdownRadio();
2296 }
2297 }
2298
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002300 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002301
2302 final long identity = Binder.clearCallingIdentity();
2303 try {
2304 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2305 if (defaultPhone != null) {
2306 defaultPhone.setRadioPower(turnOn);
2307 return true;
2308 } else {
2309 loge("There's no default phone.");
2310 return false;
2311 }
2312 } finally {
2313 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002314 }
Wink Saville36469e72014-06-11 15:17:00 -07002315 }
2316
Wink Savilleb564aae2014-10-23 10:18:09 -07002317 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002319
2320 final long identity = Binder.clearCallingIdentity();
2321 try {
2322 final Phone phone = getPhone(subId);
2323 if (phone != null) {
2324 phone.setRadioPower(turnOn);
2325 return true;
2326 } else {
2327 return false;
2328 }
2329 } finally {
2330 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002331 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002332 }
2333
Wink Saville36469e72014-06-11 15:17:00 -07002334 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002335 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 public boolean enableDataConnectivity() {
2337 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002338
2339 final long identity = Binder.clearCallingIdentity();
2340 try {
2341 int subId = mSubscriptionController.getDefaultDataSubId();
2342 final Phone phone = getPhone(subId);
2343 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002344 phone.getDataEnabledSettings().setDataEnabled(
2345 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002346 return true;
2347 } else {
2348 return false;
2349 }
2350 } finally {
2351 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 }
2354
Wink Saville36469e72014-06-11 15:17:00 -07002355 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002356 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 public boolean disableDataConnectivity() {
2358 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002359
2360 final long identity = Binder.clearCallingIdentity();
2361 try {
2362 int subId = mSubscriptionController.getDefaultDataSubId();
2363 final Phone phone = getPhone(subId);
2364 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002365 phone.getDataEnabledSettings().setDataEnabled(
2366 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002367 return true;
2368 } else {
2369 return false;
2370 }
2371 } finally {
2372 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002373 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 }
2375
Sanket Padawe356d7632015-06-22 14:03:32 -07002376 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002377 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002378 final long identity = Binder.clearCallingIdentity();
2379 try {
2380 final Phone phone = getPhone(subId);
2381 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002382 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002383 } else {
2384 return false;
2385 }
2386 } finally {
2387 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389 }
2390
2391 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002392 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002393 }
2394
pkanwarae03a6b2016-11-06 20:37:09 -08002395 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002396 enforceCallPermission();
2397
2398 final long identity = Binder.clearCallingIdentity();
2399 try {
2400 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2401 return;
2402 }
2403 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2404 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2405 } finally {
2406 Binder.restoreCallingIdentity(identity);
2407 }
pkanwar32d516d2016-10-14 19:37:38 -07002408 };
2409
Wink Savilleb564aae2014-10-23 10:18:09 -07002410 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002411 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002412
2413 final long identity = Binder.clearCallingIdentity();
2414 try {
2415 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2416 return false;
2417 }
2418 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2419 } finally {
2420 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002421 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 }
2423
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002425 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002426 }
2427
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002428 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002429 final long identity = Binder.clearCallingIdentity();
2430 try {
2431 Phone phone = PhoneFactory.getPhone(slotIndex);
2432 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2433 PhoneConstantConversions.convertCallState(phone.getState());
2434 } finally {
2435 Binder.restoreCallingIdentity(identity);
2436 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002437 }
2438
Sanket Padawe356d7632015-06-22 14:03:32 -07002439 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002440 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002441 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2442 }
2443
2444 @Override
2445 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002446 final long identity = Binder.clearCallingIdentity();
2447 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002448 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002449 if (phone != null) {
2450 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2451 } else {
2452 return PhoneConstantConversions.convertDataState(
2453 PhoneConstants.DataState.DISCONNECTED);
2454 }
2455 } finally {
2456 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 }
2459
Sanket Padawe356d7632015-06-22 14:03:32 -07002460 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002461 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002462 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2463 }
2464
2465 @Override
2466 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002467 final long identity = Binder.clearCallingIdentity();
2468 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002469 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002470 if (phone != null) {
2471 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2472 } else {
2473 return TelephonyManager.DATA_ACTIVITY_NONE;
2474 }
2475 } finally {
2476 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002477 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 }
2479
2480 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002481 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002482 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002483 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002484
2485 LocationAccessPolicy.LocationPermissionResult locationResult =
2486 LocationAccessPolicy.checkLocationPermission(mApp,
2487 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2488 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002489 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002490 .setCallingPid(Binder.getCallingPid())
2491 .setCallingUid(Binder.getCallingUid())
2492 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002493 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002494 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2495 .build());
2496 switch (locationResult) {
2497 case DENIED_HARD:
2498 throw new SecurityException("Not allowed to access cell location");
2499 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002500 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2501 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002502 }
2503
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002504 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505 final long identity = Binder.clearCallingIdentity();
2506 try {
2507 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002508 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002509 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002510 } finally {
2511 Binder.restoreCallingIdentity(identity);
2512 }
Svetoslav64fad262015-04-14 14:35:21 -07002513 }
2514
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002516 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002517 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2518 // registered cell info, so return a NULL country instead.
2519 final long identity = Binder.clearCallingIdentity();
2520 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002521 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2522 // Get default phone in this case.
2523 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2524 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002525 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002526 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002527 if (phone == null) return "";
2528 ServiceStateTracker sst = phone.getServiceStateTracker();
2529 if (sst == null) return "";
2530 LocaleTracker lt = sst.getLocaleTracker();
2531 if (lt == null) return "";
2532 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2533 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2534 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002535 } finally {
2536 Binder.restoreCallingIdentity(identity);
2537 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002538 }
2539
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002540 /**
2541 * This method was removed due to potential issues caused by performing partial
2542 * updates of service state, and lack of a credible use case.
2543 *
2544 * This has the ability to break the telephony implementation by disabling notification of
2545 * changes in device connectivity. DO NOT USE THIS!
2546 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002547 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002548 public void enableLocationUpdates() {
2549 mApp.enforceCallingOrSelfPermission(
2550 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002551 }
2552
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002553 /**
2554 * This method was removed due to potential issues caused by performing partial
2555 * updates of service state, and lack of a credible use case.
2556 *
2557 * This has the ability to break the telephony implementation by disabling notification of
2558 * changes in device connectivity. DO NOT USE THIS!
2559 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002560 @Override
2561 public void disableLocationUpdates() {
2562 mApp.enforceCallingOrSelfPermission(
2563 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 }
2565
Nathan Harold31d7ff32018-10-15 20:20:30 -07002566 /**
2567 * Returns the target SDK version number for a given package name.
2568 *
Nathan Haroldec184742019-07-10 17:04:16 -07002569 * This call MUST be invoked before clearing the calling UID.
2570 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002571 * @return target SDK if the package is found or INT_MAX.
2572 */
2573 private int getTargetSdk(String packageName) {
2574 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002575 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002576 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002577 if (ai != null) return ai.targetSdkVersion;
2578 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002579 loge("Failed to get package info for pkg="
2580 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002581 }
2582 return Integer.MAX_VALUE;
2583 }
2584
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002585 @Override
2586 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002587 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2588 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002589 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002590 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2591 throw new SecurityException(
2592 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2593 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002594
Jordan Liu1617b712019-07-10 15:06:26 -07002595 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002596 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2597 return null;
2598 }
Svetoslav64fad262015-04-14 14:35:21 -07002599
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002600 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002601
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002602 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002603 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604
Nathan Haroldf180aac2018-06-01 18:43:55 -07002605 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2606 for (CellInfo ci : info) {
2607 if (ci instanceof CellInfoGsm) {
2608 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2609 } else if (ci instanceof CellInfoWcdma) {
2610 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2611 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002612 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002613 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002614 }
2615
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002616 private List<CellInfo> getCachedCellInfo() {
2617 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2618 for (Phone phone : PhoneFactory.getPhones()) {
2619 List<CellInfo> info = phone.getAllCellInfo();
2620 if (info != null) cellInfos.addAll(info);
2621 }
2622 return cellInfos;
2623 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002624
2625 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002626 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002627 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002628 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002629
2630 LocationAccessPolicy.LocationPermissionResult locationResult =
2631 LocationAccessPolicy.checkLocationPermission(mApp,
2632 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2633 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002634 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002635 .setCallingPid(Binder.getCallingPid())
2636 .setCallingUid(Binder.getCallingUid())
2637 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002638 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002639 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2640 .build());
2641 switch (locationResult) {
2642 case DENIED_HARD:
2643 throw new SecurityException("Not allowed to access cell info");
2644 case DENIED_SOFT:
2645 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002646 }
2647
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002648 final int targetSdk = getTargetSdk(callingPackage);
2649 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2650 return getCachedCellInfo();
2651 }
2652
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002653 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002654 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655 final long identity = Binder.clearCallingIdentity();
2656 try {
2657 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2658 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002659 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002660 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661 if (info != null) cellInfos.addAll(info);
2662 }
2663 return cellInfos;
2664 } finally {
2665 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 }
2667 }
2668
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002669 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002670 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2671 String callingFeatureId) {
2672 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2673 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002674 }
2675
2676 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002677 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2678 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002679 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002680 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002681 }
2682
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002683 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2684 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002685 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002686 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002687
2688 LocationAccessPolicy.LocationPermissionResult locationResult =
2689 LocationAccessPolicy.checkLocationPermission(mApp,
2690 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2691 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002692 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002693 .setCallingPid(Binder.getCallingPid())
2694 .setCallingUid(Binder.getCallingUid())
2695 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002696 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2697 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002698 .build());
2699 switch (locationResult) {
2700 case DENIED_HARD:
Hall Liud60acc92020-05-21 17:09:35 -07002701 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2702 // Safetynet logging for b/154934934
2703 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2704 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002705 throw new SecurityException("Not allowed to access cell info");
2706 case DENIED_SOFT:
Hall Liud60acc92020-05-21 17:09:35 -07002707 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2708 // Safetynet logging for b/154934934
2709 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2710 }
Nathan Harold5320c422019-05-09 10:26:08 -07002711 try {
2712 cb.onCellInfo(new ArrayList<CellInfo>());
2713 } catch (RemoteException re) {
2714 // Drop without consequences
2715 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002716 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002717 }
2718
Nathan Harolda939a962019-05-09 10:13:47 -07002719
2720 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002721 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2722
2723 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2724 }
2725
2726 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002727 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002728 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002729 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002730
2731 final long identity = Binder.clearCallingIdentity();
2732 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002733 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734 } finally {
2735 Binder.restoreCallingIdentity(identity);
2736 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002737 }
2738
Shishir Agrawala9f32182016-04-12 12:00:16 -07002739 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002740 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002741 Phone phone = PhoneFactory.getPhone(slotIndex);
2742 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002743 return null;
2744 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002745 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002746 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002747 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002748 return null;
2749 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002750
2751 final long identity = Binder.clearCallingIdentity();
2752 try {
2753 return phone.getImei();
2754 } finally {
2755 Binder.restoreCallingIdentity(identity);
2756 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002757 }
2758
2759 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002760 public String getTypeAllocationCodeForSlot(int slotIndex) {
2761 Phone phone = PhoneFactory.getPhone(slotIndex);
2762 String tac = null;
2763 if (phone != null) {
2764 String imei = phone.getImei();
2765 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2766 }
2767 return tac;
2768 }
2769
2770 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002771 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002772 Phone phone = PhoneFactory.getPhone(slotIndex);
2773 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002774 return null;
2775 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002776
Jeff Davidson913390f2018-02-23 17:11:49 -08002777 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002778 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002779 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002780 return null;
2781 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002782
2783 final long identity = Binder.clearCallingIdentity();
2784 try {
2785 return phone.getMeid();
2786 } finally {
2787 Binder.restoreCallingIdentity(identity);
2788 }
Jack Yu2af8d712017-03-15 17:14:14 -07002789 }
2790
2791 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002792 public String getManufacturerCodeForSlot(int slotIndex) {
2793 Phone phone = PhoneFactory.getPhone(slotIndex);
2794 String manufacturerCode = null;
2795 if (phone != null) {
2796 String meid = phone.getMeid();
2797 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2798 }
2799 return manufacturerCode;
2800 }
2801
2802 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002803 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2804 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002805 Phone phone = PhoneFactory.getPhone(slotIndex);
2806 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002807 return null;
2808 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002809 int subId = phone.getSubId();
2810 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002811 mApp, subId, callingPackage, callingFeatureId,
2812 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002813 return null;
2814 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002815
2816 final long identity = Binder.clearCallingIdentity();
2817 try {
2818 return phone.getDeviceSvn();
2819 } finally {
2820 Binder.restoreCallingIdentity(identity);
2821 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002822 }
2823
fionaxu43304da2017-11-27 22:51:16 -08002824 @Override
2825 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826 final long identity = Binder.clearCallingIdentity();
2827 try {
2828 final Phone phone = getPhone(subId);
2829 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2830 } finally {
2831 Binder.restoreCallingIdentity(identity);
2832 }
fionaxu43304da2017-11-27 22:51:16 -08002833 }
2834
2835 @Override
2836 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002837 final long identity = Binder.clearCallingIdentity();
2838 try {
2839 final Phone phone = getPhone(subId);
2840 return phone == null ? null : phone.getCarrierName();
2841 } finally {
2842 Binder.restoreCallingIdentity(identity);
2843 }
fionaxu43304da2017-11-27 22:51:16 -08002844 }
2845
calvinpanffe225e2018-11-01 19:43:06 +08002846 @Override
chen xu0026ca62019-03-06 15:28:50 -08002847 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 final Phone phone = getPhone(subId);
2851 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002852 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002853 } finally {
2854 Binder.restoreCallingIdentity(identity);
2855 }
2856 }
2857
2858 @Override
chen xu0026ca62019-03-06 15:28:50 -08002859 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002860 final long identity = Binder.clearCallingIdentity();
2861 try {
2862 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002863 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002864 } finally {
2865 Binder.restoreCallingIdentity(identity);
2866 }
2867 }
2868
chen xu651eec72018-11-11 19:03:44 -08002869 @Override
chen xu864e11c2018-12-06 22:10:03 -08002870 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2871 if (!isSubscriptionMccMnc) {
2872 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2873 }
chen xu651eec72018-11-11 19:03:44 -08002874 final Phone phone = PhoneFactory.getPhone(slotIndex);
2875 if (phone == null) {
2876 return TelephonyManager.UNKNOWN_CARRIER_ID;
2877 }
2878 final long identity = Binder.clearCallingIdentity();
2879 try {
2880 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2881 } finally {
2882 Binder.restoreCallingIdentity(identity);
2883 }
2884 }
2885
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002886 //
2887 // Internal helper methods.
2888 //
2889
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002890 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002891 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2892 *
2893 * @throws SecurityException if the caller does not have the required permission
2894 */
2895 private void enforceModifyPermission() {
2896 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2897 }
2898
Shuo Qiancd19c462020-01-16 20:51:11 -08002899 /**
2900 * Make sure the caller is system.
2901 *
2902 * @throws SecurityException if the caller is not system.
2903 */
2904 private void enforceSystemCaller() {
2905 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2906 throw new SecurityException("Caller must be system");
2907 }
2908 }
2909
Shuo Qian3b6ee772019-11-13 17:43:31 -08002910 private void enforceActiveEmergencySessionPermission() {
2911 mApp.enforceCallingOrSelfPermission(
2912 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2913 }
2914
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002915 /**
2916 * Make sure the caller has the CALL_PHONE permission.
2917 *
2918 * @throws SecurityException if the caller does not have the required permission
2919 */
2920 private void enforceCallPermission() {
2921 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2922 }
2923
paulhu5a773602019-08-23 19:17:33 +08002924 private void enforceSettingsPermission() {
2925 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002926 }
2927
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002928 private String createTelUrl(String number) {
2929 if (TextUtils.isEmpty(number)) {
2930 return null;
2931 }
2932
Jake Hambye994d462014-02-03 13:10:13 -08002933 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002934 }
2935
Ihab Awadf9e92732013-12-05 18:02:52 -08002936 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002937 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2938 }
2939
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002940 private static void logv(String msg) {
2941 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2942 }
2943
Ihab Awadf9e92732013-12-05 18:02:52 -08002944 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002945 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2946 }
2947
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002948 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002949 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002950 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002951 }
2952
Sanket Padawe356d7632015-06-22 14:03:32 -07002953 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002954 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002955 final long identity = Binder.clearCallingIdentity();
2956 try {
2957 final Phone phone = PhoneFactory.getPhone(slotIndex);
2958 if (phone == null) {
2959 return PhoneConstants.PHONE_TYPE_NONE;
2960 } else {
2961 return phone.getPhoneType();
2962 }
2963 } finally {
2964 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002965 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002966 }
2967
2968 /**
2969 * Returns the CDMA ERI icon index to display
2970 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002971 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002972 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2973 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2974 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002975 }
2976
Sanket Padawe356d7632015-06-22 14:03:32 -07002977 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002978 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2979 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002980 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002981 mApp, subId, callingPackage, callingFeatureId,
2982 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002983 return -1;
2984 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002985
2986 final long identity = Binder.clearCallingIdentity();
2987 try {
2988 final Phone phone = getPhone(subId);
2989 if (phone != null) {
2990 return phone.getCdmaEriIconIndex();
2991 } else {
2992 return -1;
2993 }
2994 } finally {
2995 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002996 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002997 }
2998
2999 /**
3000 * Returns the CDMA ERI icon mode,
3001 * 0 - ON
3002 * 1 - FLASHING
3003 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003004 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003005 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3006 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3007 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003008 }
3009
Sanket Padawe356d7632015-06-22 14:03:32 -07003010 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003011 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3012 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003013 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003014 mApp, subId, callingPackage, callingFeatureId,
3015 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003016 return -1;
3017 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018
3019 final long identity = Binder.clearCallingIdentity();
3020 try {
3021 final Phone phone = getPhone(subId);
3022 if (phone != null) {
3023 return phone.getCdmaEriIconMode();
3024 } else {
3025 return -1;
3026 }
3027 } finally {
3028 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003029 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003030 }
3031
3032 /**
3033 * Returns the CDMA ERI text,
3034 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003035 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003036 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3037 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3038 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003039 }
3040
Sanket Padawe356d7632015-06-22 14:03:32 -07003041 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003042 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3043 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003044 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003045 mApp, subId, callingPackage, callingFeatureId,
3046 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003047 return null;
3048 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003049
3050 final long identity = Binder.clearCallingIdentity();
3051 try {
3052 final Phone phone = getPhone(subId);
3053 if (phone != null) {
3054 return phone.getCdmaEriText();
3055 } else {
3056 return null;
3057 }
3058 } finally {
3059 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003060 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003061 }
3062
3063 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003064 * Returns the CDMA MDN.
3065 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003066 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003067 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3069 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003070
3071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003074 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003075 return phone.getLine1Number();
3076 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003077 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003078 return null;
3079 }
3080 } finally {
3081 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003082 }
3083 }
3084
3085 /**
3086 * Returns the CDMA MIN.
3087 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003088 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003089 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003090 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3091 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003092
3093 final long identity = Binder.clearCallingIdentity();
3094 try {
3095 final Phone phone = getPhone(subId);
3096 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3097 return phone.getCdmaMin();
3098 } else {
3099 return null;
3100 }
3101 } finally {
3102 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003103 }
3104 }
3105
Hall Liud892bec2018-11-30 14:51:45 -08003106 @Override
3107 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3108 INumberVerificationCallback callback, String callingPackage) {
3109 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3110 != PERMISSION_GRANTED) {
3111 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3112 }
3113 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3114
3115 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3116 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3117 throw new SecurityException("Calling package must be configured in the device config");
3118 }
3119
3120 if (range == null) {
3121 throw new NullPointerException("Range must be non-null");
3122 }
3123
3124 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003125 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003126
3127 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3128 }
3129
Junda Liuca05d5d2014-08-14 22:36:34 -07003130 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003131 * Returns true if CDMA provisioning needs to run.
3132 */
3133 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003134 final long identity = Binder.clearCallingIdentity();
3135 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003136 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003137 } finally {
3138 Binder.restoreCallingIdentity(identity);
3139 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003140 }
3141
3142 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003143 * Sets the voice mail number of a given subId.
3144 */
3145 @Override
3146 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003147 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3148 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003149
3150 final long identity = Binder.clearCallingIdentity();
3151 try {
3152 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3153 new Pair<String, String>(alphaTag, number), new Integer(subId));
3154 return success;
3155 } finally {
3156 Binder.restoreCallingIdentity(identity);
3157 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003158 }
3159
Ta-wei Yen87c49842016-05-13 21:19:52 -07003160 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003161 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3162 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003163 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3164 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003165 if (!TextUtils.equals(callingPackage, systemDialer)) {
3166 throw new SecurityException("caller must be system dialer");
3167 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003168
3169 final long identity = Binder.clearCallingIdentity();
3170 try {
3171 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3172 if (phoneAccountHandle == null) {
3173 return null;
3174 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003175 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003176 } finally {
3177 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003178 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003179 }
3180
3181 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003182 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3183 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003184 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003185 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003186 mApp, subId, callingPackage, callingFeatureId,
3187 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003188 return null;
3189 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003190
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003191 final long identity = Binder.clearCallingIdentity();
3192 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003193 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003194 } finally {
3195 Binder.restoreCallingIdentity(identity);
3196 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003197 }
3198
3199 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003200 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3201 VisualVoicemailSmsFilterSettings settings) {
3202 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003203
3204 final long identity = Binder.clearCallingIdentity();
3205 try {
3206 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003207 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003208 } finally {
3209 Binder.restoreCallingIdentity(identity);
3210 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003211 }
3212
3213 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003214 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3215 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216
3217 final long identity = Binder.clearCallingIdentity();
3218 try {
3219 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003220 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003221 } finally {
3222 Binder.restoreCallingIdentity(identity);
3223 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003224 }
3225
3226 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003227 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3228 String callingPackage, int subId) {
3229 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003230
3231 final long identity = Binder.clearCallingIdentity();
3232 try {
3233 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003234 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003235 } finally {
3236 Binder.restoreCallingIdentity(identity);
3237 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003238 }
3239
3240 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003241 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003242 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003243
3244 final long identity = Binder.clearCallingIdentity();
3245 try {
3246 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003247 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003248 } finally {
3249 Binder.restoreCallingIdentity(identity);
3250 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003251 }
3252
3253 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003254 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3255 String callingAttributionTag, int subId, String number, int port, String text,
3256 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003257 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003258 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003259 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003260 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003261 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3262 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003263 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003264
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003265 /**
fionaxu0152e512016-11-14 13:36:14 -08003266 * Sets the voice activation state of a given subId.
3267 */
3268 @Override
3269 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3271 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003272
3273 final long identity = Binder.clearCallingIdentity();
3274 try {
3275 final Phone phone = getPhone(subId);
3276 if (phone != null) {
3277 phone.setVoiceActivationState(activationState);
3278 } else {
3279 loge("setVoiceActivationState fails with invalid subId: " + subId);
3280 }
3281 } finally {
3282 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003283 }
3284 }
3285
3286 /**
3287 * Sets the data activation state of a given subId.
3288 */
3289 @Override
3290 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3292 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003293
3294 final long identity = Binder.clearCallingIdentity();
3295 try {
3296 final Phone phone = getPhone(subId);
3297 if (phone != null) {
3298 phone.setDataActivationState(activationState);
3299 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003300 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003301 }
3302 } finally {
3303 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003304 }
3305 }
3306
3307 /**
3308 * Returns the voice activation state of a given subId.
3309 */
3310 @Override
3311 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003312 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003313
fionaxu0152e512016-11-14 13:36:14 -08003314 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003315 final long identity = Binder.clearCallingIdentity();
3316 try {
3317 if (phone != null) {
3318 return phone.getVoiceActivationState();
3319 } else {
3320 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3321 }
3322 } finally {
3323 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003324 }
3325 }
3326
3327 /**
3328 * Returns the data activation state of a given subId.
3329 */
3330 @Override
3331 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003332 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003333
fionaxu0152e512016-11-14 13:36:14 -08003334 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003335 final long identity = Binder.clearCallingIdentity();
3336 try {
3337 if (phone != null) {
3338 return phone.getDataActivationState();
3339 } else {
3340 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3341 }
3342 } finally {
3343 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003344 }
3345 }
3346
3347 /**
Wink Saville36469e72014-06-11 15:17:00 -07003348 * Returns the unread count of voicemails for a subId
3349 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003350 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003351 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3352 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003353 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003354 mApp, subId, callingPackage, callingFeatureId,
3355 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003356 return 0;
3357 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003358 final long identity = Binder.clearCallingIdentity();
3359 try {
3360 final Phone phone = getPhone(subId);
3361 if (phone != null) {
3362 return phone.getVoiceMessageCount();
3363 } else {
3364 return 0;
3365 }
3366 } finally {
3367 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003369 }
3370
3371 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003372 * returns true, if the device is in a state where both voice and data
3373 * are supported simultaneously. This can change based on location or network condition.
3374 */
3375 @Override
3376 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003377 final long identity = Binder.clearCallingIdentity();
3378 try {
3379 final Phone phone = getPhone(subId);
3380 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3381 } finally {
3382 Binder.restoreCallingIdentity(identity);
3383 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003384 }
3385
3386 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003387 * Send the dialer code if called from the current default dialer or the caller has
3388 * carrier privilege.
3389 * @param inputCode The dialer code to send
3390 */
3391 @Override
3392 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003393 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003394 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003395 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3396 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003397 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003398 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003399 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003400 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003401
3402 final long identity = Binder.clearCallingIdentity();
3403 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003404 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003405 } finally {
3406 Binder.restoreCallingIdentity(identity);
3407 }
fionaxu235cc5e2017-03-06 22:25:57 -08003408 }
3409
Pengquan Menga1bb6272018-09-06 09:59:22 -07003410 @Override
3411 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003412 TelephonyPermissions
3413 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3414 mApp, subId, "getNetworkSelectionMode");
3415 final long identity = Binder.clearCallingIdentity();
3416 try {
3417 if (!isActiveSubscription(subId)) {
3418 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3419 }
3420 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3421 } finally {
3422 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003423 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003424 }
3425
Brad Ebinger35c841c2018-10-01 10:40:55 -07003426 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003427 public boolean isInEmergencySmsMode() {
3428 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3429 final long identity = Binder.clearCallingIdentity();
3430 try {
3431 for (Phone phone : PhoneFactory.getPhones()) {
3432 if (phone.isInEmergencySmsMode()) {
3433 return true;
3434 }
3435 }
3436 } finally {
3437 Binder.restoreCallingIdentity(identity);
3438 }
3439 return false;
3440 }
3441
shilu366312e2019-12-17 09:28:10 -08003442 /**
3443 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3444 * @param subId The subscription to use to check the configuration.
3445 * @param c The callback that will be used to send the result.
3446 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003447 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003448 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3449 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003450 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3451 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003452
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003453 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3454 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3455 "IMS not available on device.");
3456 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003457 final long token = Binder.clearCallingIdentity();
3458 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003459 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003460 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003461 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003462 } catch (ImsException e) {
3463 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003464 } finally {
3465 Binder.restoreCallingIdentity(token);
3466 }
3467 }
3468
shilu366312e2019-12-17 09:28:10 -08003469 /**
3470 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3471 * @param subId The subscription to use to check the configuration.
3472 * @param c The callback that will be used to send the result.
3473 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003474 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003475 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003476 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3477 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003478 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3479 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3480 }
Meng Wangafbc5852019-09-19 17:37:13 -07003481 final long token = Binder.clearCallingIdentity();
3482 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003483 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003484 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3485 .removeRegistrationCallbackForSubscription(c, subId);
3486 } catch (ImsException e) {
3487 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3488 + "is inactive, ignoring unregister.");
3489 // If the subscription is no longer active, just return, since the callback
3490 // will already have been removed internally.
3491 } finally {
3492 Binder.restoreCallingIdentity(token);
3493 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003494 }
3495
Brad Ebingera34a6c22019-10-22 17:36:18 -07003496 /**
3497 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3498 */
3499 @Override
3500 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3501 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3502 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3503 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3504 "IMS not available on device.");
3505 }
3506 final long token = Binder.clearCallingIdentity();
3507 try {
3508 Phone phone = getPhone(subId);
3509 if (phone == null) {
3510 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3511 + subId + "'");
3512 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3513 }
3514 phone.getImsRegistrationState(regState -> {
3515 try {
3516 consumer.accept((regState == null)
3517 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3518 } catch (RemoteException e) {
3519 // Ignore if the remote process is no longer available to call back.
3520 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3521 }
3522 });
3523 } finally {
3524 Binder.restoreCallingIdentity(token);
3525 }
3526 }
3527
3528 /**
3529 * Get the transport type for the IMS service registration state.
3530 */
3531 @Override
3532 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003533 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3534 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003535 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3536 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3537 "IMS not available on device.");
3538 }
3539 final long token = Binder.clearCallingIdentity();
3540 try {
3541 Phone phone = getPhone(subId);
3542 if (phone == null) {
3543 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3544 + subId + "'");
3545 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3546 }
3547 phone.getImsRegistrationTech(regTech -> {
3548 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3549 int regTechConverted = (regTech == null)
3550 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3551 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3552 regTechConverted);
3553 try {
3554 consumer.accept(regTechConverted);
3555 } catch (RemoteException e) {
3556 // Ignore if the remote process is no longer available to call back.
3557 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3558 }
3559 });
3560 } finally {
3561 Binder.restoreCallingIdentity(token);
3562 }
3563 }
3564
shilu366312e2019-12-17 09:28:10 -08003565 /**
3566 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3567 * @param subId The subscription to use to check the configuration.
3568 * @param c The callback that will be used to send the result.
3569 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003570 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003571 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3572 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003573 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3574 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003575 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3576 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3577 "IMS not available on device.");
3578 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003579 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3580 final long token = Binder.clearCallingIdentity();
3581 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003582 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003583 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003584 } catch (ImsException e) {
3585 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003586 } finally {
3587 Binder.restoreCallingIdentity(token);
3588 }
3589 }
3590
shilu366312e2019-12-17 09:28:10 -08003591 /**
3592 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3593 * @param subId The subscription to use to check the configuration.
3594 * @param c The callback that will be used to send the result.
3595 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003596 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003597 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003598 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3599 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003600 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3601 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3602 }
Meng Wangafbc5852019-09-19 17:37:13 -07003603
3604 final long token = Binder.clearCallingIdentity();
3605 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003606 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003607 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003608 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003609 } catch (ImsException e) {
3610 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3611 + "is inactive, ignoring unregister.");
3612 // If the subscription is no longer active, just return, since the callback
3613 // will already have been removed internally.
3614 } finally {
3615 Binder.restoreCallingIdentity(token);
3616 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003617 }
3618
3619 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003620 public boolean isCapable(int subId, int capability, int regTech) {
3621 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003622 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3623 final long token = Binder.clearCallingIdentity();
3624 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003625 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003626 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003627 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003628 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3629 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003630 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003631 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3632 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003633 } finally {
3634 Binder.restoreCallingIdentity(token);
3635 }
3636 }
3637
3638 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003639 public boolean isAvailable(int subId, int capability, int regTech) {
3640 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003641 final long token = Binder.clearCallingIdentity();
3642 try {
3643 Phone phone = getPhone(subId);
3644 if (phone == null) return false;
3645 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003646 } catch (com.android.ims.ImsException e) {
3647 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3648 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003649 } finally {
3650 Binder.restoreCallingIdentity(token);
3651 }
3652 }
3653
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003654 /**
3655 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3656 * subscription.
3657 * @param subId The subscription to use to check the configuration.
3658 * @param callback The callback that will be used to send the result.
3659 * @param capability The MmTelFeature capability that will be used to send the result.
3660 * @param transportType The transport type of the MmTelFeature capability.
3661 */
3662 @Override
3663 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3664 int transportType) {
3665 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3666 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3667 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3668 "IMS not available on device.");
3669 }
3670 final long token = Binder.clearCallingIdentity();
3671 try {
3672 int slotId = getSlotIndex(subId);
3673 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3674 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3675 + subId + "'");
3676 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3677 }
3678 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3679 transportType, aBoolean -> {
3680 try {
3681 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3682 } catch (RemoteException e) {
3683 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3684 + "running. Ignore");
3685 }
3686 });
3687 } finally {
3688 Binder.restoreCallingIdentity(token);
3689 }
3690 }
3691
shilu366312e2019-12-17 09:28:10 -08003692 /**
3693 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3694 * @param subId The subscription to use to check the configuration.
3695 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003696 @Override
3697 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003698 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3699 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003700
Brad Ebinger35c841c2018-10-01 10:40:55 -07003701 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3702 final long token = Binder.clearCallingIdentity();
3703 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003704 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003705 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003706 } catch (ImsException e) {
3707 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003708 } finally {
3709 Binder.restoreCallingIdentity(token);
3710 }
3711 }
3712
3713 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003714 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003716 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003717 final long identity = Binder.clearCallingIdentity();
3718 try {
3719 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003720 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003721 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003722 } catch (ImsException e) {
3723 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003724 } finally {
3725 Binder.restoreCallingIdentity(identity);
3726 }
3727 }
3728
shilu366312e2019-12-17 09:28:10 -08003729 /**
3730 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3731 * @param subId The subscription to use to check the configuration.
3732 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003733 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003734 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003735 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3736 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003737 final long identity = Binder.clearCallingIdentity();
3738 try {
3739 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003740 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3741 } catch (ImsException e) {
3742 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003743 } finally {
3744 Binder.restoreCallingIdentity(identity);
3745 }
3746 }
3747
3748 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003749 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003750 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003751 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003752 final long identity = Binder.clearCallingIdentity();
3753 try {
3754 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003755 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003756 } catch (ImsException e) {
3757 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003758 } finally {
3759 Binder.restoreCallingIdentity(identity);
3760 }
3761 }
3762
shilu366312e2019-12-17 09:28:10 -08003763 /**
3764 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3765 * @param subId The subscription to use to check the configuration.
3766 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003767 @Override
3768 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003769 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3770 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003771 final long identity = Binder.clearCallingIdentity();
3772 try {
3773 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003774 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003775 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003776 } catch (ImsException e) {
3777 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003778 } finally {
3779 Binder.restoreCallingIdentity(identity);
3780 }
3781 }
3782
3783 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003784 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003786 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003787 final long identity = Binder.clearCallingIdentity();
3788 try {
3789 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003790 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003791 } catch (ImsException e) {
3792 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003793 } finally {
3794 Binder.restoreCallingIdentity(identity);
3795 }
3796 }
3797
shilu366312e2019-12-17 09:28:10 -08003798 /**
3799 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3800 * @param subId The subscription to use to check the configuration.
3801 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003802 @Override
3803 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003804 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3805 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003806 final long identity = Binder.clearCallingIdentity();
3807 try {
3808 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003809 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003810 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003811 } catch (ImsException e) {
3812 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003813 } finally {
3814 Binder.restoreCallingIdentity(identity);
3815 }
3816 }
3817
3818 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003819 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003821 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003822 final long identity = Binder.clearCallingIdentity();
3823 try {
3824 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003825 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003826 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003827 } catch (ImsException e) {
3828 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003829 } finally {
3830 Binder.restoreCallingIdentity(identity);
3831 }
3832 }
3833
3834 @Override
3835 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3837 "setVoWiFiNonPersistent");
3838 final long identity = Binder.clearCallingIdentity();
3839 try {
3840 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003841 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003842 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003843 } catch (ImsException e) {
3844 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003845 } finally {
3846 Binder.restoreCallingIdentity(identity);
3847 }
3848 }
3849
shilu366312e2019-12-17 09:28:10 -08003850 /**
3851 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3852 * @param subId The subscription to use to check the configuration.
3853 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003854 @Override
3855 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003856 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3857 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003858 final long identity = Binder.clearCallingIdentity();
3859 try {
3860 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003861 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003862 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003863 } catch (ImsException e) {
3864 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003865 } finally {
3866 Binder.restoreCallingIdentity(identity);
3867 }
3868 }
3869
3870 @Override
3871 public void setVoWiFiModeSetting(int subId, int mode) {
3872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3873 "setVoWiFiModeSetting");
3874 final long identity = Binder.clearCallingIdentity();
3875 try {
3876 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003877 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003878 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003879 } catch (ImsException e) {
3880 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003881 } finally {
3882 Binder.restoreCallingIdentity(identity);
3883 }
3884 }
3885
3886 @Override
3887 public int getVoWiFiRoamingModeSetting(int subId) {
3888 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3889 final long identity = Binder.clearCallingIdentity();
3890 try {
3891 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003892 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003893 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003894 } catch (ImsException e) {
3895 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003896 } finally {
3897 Binder.restoreCallingIdentity(identity);
3898 }
3899 }
3900
3901 @Override
3902 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3904 "setVoWiFiRoamingModeSetting");
3905 final long identity = Binder.clearCallingIdentity();
3906 try {
3907 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003908 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003909 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003910 } catch (ImsException e) {
3911 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003912 } finally {
3913 Binder.restoreCallingIdentity(identity);
3914 }
3915 }
3916
3917 @Override
3918 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3920 "setRttCapabilityEnabled");
3921 final long identity = Binder.clearCallingIdentity();
3922 try {
3923 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003924 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3925 } catch (ImsException e) {
3926 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003927 } finally {
3928 Binder.restoreCallingIdentity(identity);
3929 }
3930 }
3931
shilu366312e2019-12-17 09:28:10 -08003932 /**
3933 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3934 * @param subId The subscription to use to check the configuration.
3935 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003936 @Override
3937 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003938 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3939 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003940 final long identity = Binder.clearCallingIdentity();
3941 try {
3942 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003943 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003944 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003945 } catch (ImsException e) {
3946 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003947 } finally {
3948 Binder.restoreCallingIdentity(identity);
3949 }
3950 }
3951
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003952 @Override
3953 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3954 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3955 final long identity = Binder.clearCallingIdentity();
3956 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003957 if (!isImsAvailableOnDevice()) {
3958 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3959 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003960 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003961 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003962 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003963 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003964 } catch (ImsException e) {
3965 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003966 } finally {
3967 Binder.restoreCallingIdentity(identity);
3968 }
3969 }
3970
3971 @Override
3972 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3973 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3974 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003975 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3976 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3977 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003978 try {
3979 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003980 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003981 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003982 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003983 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3984 + "is inactive, ignoring unregister.");
3985 // If the subscription is no longer active, just return, since the callback will already
3986 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003987 } finally {
3988 Binder.restoreCallingIdentity(identity);
3989 }
3990 }
3991
allenwtsu99c623b2020-01-03 18:24:23 +08003992
3993 private void checkModifyPhoneStatePermission(int subId, String message) {
3994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3995 message);
3996 }
3997
3998 private boolean isImsProvisioningRequired(int subId, int capability,
3999 boolean isMmtelCapability) {
4000 Phone phone = getPhone(subId);
4001 if (phone == null) {
4002 loge("phone instance null for subid " + subId);
4003 return false;
4004 }
4005 if (isMmtelCapability) {
4006 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4007 return false;
4008 }
4009 } else {
4010 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4011 return false;
4012 }
4013 }
4014 return true;
4015 }
4016
4017 @Override
4018 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4019 boolean isProvisioned) {
4020 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4021
4022 final long identity = Binder.clearCallingIdentity();
4023 try {
4024 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4025 if (!isImsProvisioningRequired(subId, capability, false)) {
4026 return;
4027 }
4028
4029 // this capability requires provisioning, route to the correct API.
4030 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4031 switch (capability) {
4032 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4033 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4034 ims.setEabProvisioned(isProvisioned);
4035 break;
4036 default: {
4037 throw new IllegalArgumentException("Tried to set provisioning for "
4038 + "rcs capability '" + capability + "', which does not require "
4039 + "provisioning.");
4040 }
4041 }
4042 } finally {
4043 Binder.restoreCallingIdentity(identity);
4044 }
4045
4046 }
4047
4048
4049 @Override
4050 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4051 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4055 if (!isImsProvisioningRequired(subId, capability, false)) {
4056 return true;
4057 }
4058
4059 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4060 switch (capability) {
4061 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4062 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4063 return ims.isEabProvisionedOnDevice();
4064
4065 default: {
4066 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4067 + "capability '" + capability + "', which does not require "
4068 + "provisioning.");
4069 }
4070 }
4071
4072 } finally {
4073 Binder.restoreCallingIdentity(identity);
4074 }
4075 }
4076
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004077 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004078 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4079 boolean isProvisioned) {
4080 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4081 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4082 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4083 }
allenwtsu99c623b2020-01-03 18:24:23 +08004084 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004085 final long identity = Binder.clearCallingIdentity();
4086 try {
4087 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004088 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004089 return;
4090 }
4091
4092 // this capability requires provisioning, route to the correct API.
4093 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4094 switch (capability) {
4095 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4096 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4097 ims.setVolteProvisioned(isProvisioned);
4098 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4099 ims.setWfcProvisioned(isProvisioned);
4100 }
4101 break;
4102 }
4103 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4104 // There is currently no difference in VT provisioning type.
4105 ims.setVtProvisioned(isProvisioned);
4106 break;
4107 }
4108 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4109 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4110 // change the capability of the feature instead if needed.
4111 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4112 == isProvisioned) {
4113 // No change in provisioning.
4114 return;
4115 }
4116 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4117 try {
4118 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004119 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004120 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4121 + ", Exception" + e.getMessage());
4122 }
4123 break;
4124 }
4125 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004126 throw new IllegalArgumentException("Tried to set provisioning for "
4127 + "MmTel capability '" + capability + "', which does not require "
4128 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004129 }
4130 }
4131
4132 } finally {
4133 Binder.restoreCallingIdentity(identity);
4134 }
4135 }
4136
4137 @Override
4138 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4139 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4140 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4141 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4142 }
4143 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4144 final long identity = Binder.clearCallingIdentity();
4145 try {
4146 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004147 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004148 return true;
4149 }
4150
4151 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4152 switch (capability) {
4153 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4154 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4155 return ims.isVolteProvisionedOnDevice();
4156 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4157 return ims.isWfcProvisionedOnDevice();
4158 }
4159 // This should never happen, since we are checking tech above to make sure it
4160 // is either LTE or IWLAN.
4161 throw new IllegalArgumentException("Invalid radio technology for voice "
4162 + "capability.");
4163 }
4164 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4165 // There is currently no difference in VT provisioning type.
4166 return ims.isVtProvisionedOnDevice();
4167 }
4168 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4169 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4170 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4171 }
4172 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004173 throw new IllegalArgumentException(
4174 "Tried to get provisioning for MmTel capability '" + capability
4175 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004176 }
4177 }
4178
4179 } finally {
4180 Binder.restoreCallingIdentity(identity);
4181 }
4182 }
4183
4184 @Override
4185 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4186 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4187 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4188 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4189 }
4190 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4191 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4192 return (provisionedBits & capability) > 0;
4193 }
4194
4195 @Override
4196 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4197 boolean isProvisioned) {
4198 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4199 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4200 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4201 }
4202 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4203 "setProvisioningStatusForCapability");
4204 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4205 // If the current provisioning status for capability already matches isProvisioned,
4206 // do nothing.
4207 if (((provisionedBits & capability) > 0) == isProvisioned) {
4208 return;
4209 }
4210 if (isProvisioned) {
4211 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4212 } else {
4213 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4214 }
4215 }
4216
4217 /**
4218 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4219 * technology. The bitfield should mirror the bitfield defined by
4220 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4221 */
4222 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4223 String key = getMmTelProvisioningKey(subId, tech);
4224 // Default is no capabilities are provisioned.
4225 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4226 }
4227
4228 /**
4229 * Sets the MmTel capability provisioning bitfield (defined by
4230 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4231 * technology specified.
4232 *
4233 * Note: This is a synchronous command and should not be called on UI thread.
4234 */
4235 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4236 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4237 String key = getMmTelProvisioningKey(subId, tech);
4238 editor.putInt(key, newField);
4239 editor.commit();
4240 }
4241
4242 private static String getMmTelProvisioningKey(int subId, int tech) {
4243 // resulting key is provision_ims_mmtel_{subId}_{tech}
4244 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4245 }
4246
4247 /**
4248 * Query CarrierConfig to see if the specified capability requires provisioning for the
4249 * carrier associated with the subscription id.
4250 */
4251 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4252 int capability) {
4253 CarrierConfigManager configManager = new CarrierConfigManager(context);
4254 PersistableBundle c = configManager.getConfigForSubId(subId);
4255 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004256 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004257 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4258 false);
4259 boolean requireVoiceVtProvisioning = c.getBoolean(
4260 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4261
4262 // First check to make sure that the capability requires provisioning.
4263 switch (capability) {
4264 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4265 // intentional fallthrough
4266 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4267 if (requireVoiceVtProvisioning) {
4268 // Voice and Video requires provisioning
4269 return true;
4270 }
4271 break;
4272 }
4273 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4274 if (requireUtProvisioning) {
4275 // UT requires provisioning
4276 return true;
4277 }
4278 break;
4279 }
4280 }
4281 return false;
4282 }
4283
allenwtsu99c623b2020-01-03 18:24:23 +08004284 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4285 int capability) {
4286 CarrierConfigManager configManager = new CarrierConfigManager(context);
4287 PersistableBundle c = configManager.getConfigForSubId(subId);
4288
4289 boolean requireRcsProvisioning = c.getBoolean(
4290 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4291
4292 // First check to make sure that the capability requires provisioning.
4293 switch (capability) {
4294 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4295 // intentional fallthrough
4296 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4297 if (requireRcsProvisioning) {
4298 // OPTION or PRESENCE requires provisioning
4299 return true;
4300 }
4301 break;
4302 }
4303 }
4304 return false;
4305 }
4306
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004307 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004308 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004309 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4310 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4311 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004312 enforceReadPrivilegedPermission("getImsProvisioningInt");
4313 final long identity = Binder.clearCallingIdentity();
4314 try {
4315 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004316 int slotId = getSlotIndex(subId);
4317 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4318 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4319 + subId + "' for key:" + key);
4320 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4321 }
4322 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004323 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004324 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4325 + subId + "' for key:" + key);
4326 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004327 } finally {
4328 Binder.restoreCallingIdentity(identity);
4329 }
4330 }
4331
4332 @Override
4333 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004334 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4335 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4336 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004337 enforceReadPrivilegedPermission("getImsProvisioningString");
4338 final long identity = Binder.clearCallingIdentity();
4339 try {
4340 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004341 int slotId = getSlotIndex(subId);
4342 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4343 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4344 + subId + "' for key:" + key);
4345 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4346 }
4347 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004348 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004349 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4350 + subId + "' for key:" + key);
4351 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004352 } finally {
4353 Binder.restoreCallingIdentity(identity);
4354 }
4355 }
4356
4357 @Override
4358 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004359 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4360 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4361 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004362 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4363 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004364 final long identity = Binder.clearCallingIdentity();
4365 try {
4366 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004367 int slotId = getSlotIndex(subId);
4368 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4369 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4370 + subId + "' for key:" + key);
4371 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4372 }
4373 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004374 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004375 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4376 + "' for key:" + key);
4377 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004378 } finally {
4379 Binder.restoreCallingIdentity(identity);
4380 }
4381 }
4382
4383 @Override
4384 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004385 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4386 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4387 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4389 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004390 final long identity = Binder.clearCallingIdentity();
4391 try {
4392 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004393 int slotId = getSlotIndex(subId);
4394 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4395 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4396 + subId + "' for key:" + key);
4397 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4398 }
4399 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004400 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004401 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4402 + "' for key:" + key);
4403 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004404 } finally {
4405 Binder.restoreCallingIdentity(identity);
4406 }
4407 }
4408
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004409 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004410 int slotId = SubscriptionManager.getSlotIndex(subId);
4411 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004412 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4413 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004414 }
4415 return slotId;
4416 }
4417
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004418 private int getSlotIndex(int subId) {
4419 int slotId = SubscriptionManager.getSlotIndex(subId);
4420 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4421 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4422 }
4423 return slotId;
4424 }
4425
Wink Saville36469e72014-06-11 15:17:00 -07004426 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004427 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004428 */
4429 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004430 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4431 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004432 final int targetSdk = getTargetSdk(callingPackage);
4433 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004434 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004435 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004436 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004437 mApp, subId, callingPackage, callingFeatureId,
4438 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004439 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4440 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004441
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442 final long identity = Binder.clearCallingIdentity();
4443 try {
4444 final Phone phone = getPhone(subId);
4445 if (phone != null) {
4446 return phone.getServiceState().getDataNetworkType();
4447 } else {
4448 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4449 }
4450 } finally {
4451 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004452 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004453 }
4454
4455 /**
4456 * Returns the data network type
4457 */
4458 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004459 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4460 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4461 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004462 }
4463
4464 /**
4465 * Returns the data network type for a subId
4466 */
4467 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004468 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4469 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004471 mApp, subId, callingPackage, callingFeatureId,
4472 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004473 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4474 }
4475
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004476 final long identity = Binder.clearCallingIdentity();
4477 try {
4478 final Phone phone = getPhone(subId);
4479 if (phone != null) {
4480 return phone.getServiceState().getDataNetworkType();
4481 } else {
4482 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4483 }
4484 } finally {
4485 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004486 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004487 }
4488
4489 /**
Wink Saville36469e72014-06-11 15:17:00 -07004490 * Returns the Voice network type for a subId
4491 */
4492 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004493 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4494 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004495 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004496 mApp, subId, callingPackage, callingFeatureId,
4497 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004498 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4499 }
4500
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004501 final long identity = Binder.clearCallingIdentity();
4502 try {
4503 final Phone phone = getPhone(subId);
4504 if (phone != null) {
4505 return phone.getServiceState().getVoiceNetworkType();
4506 } else {
4507 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4508 }
4509 } finally {
4510 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004511 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004512 }
4513
4514 /**
4515 * @return true if a ICC card is present
4516 */
4517 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004518 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004519 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4520 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004521 }
4522
4523 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004524 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004525 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004526 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004527 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004528 final long identity = Binder.clearCallingIdentity();
4529 try {
4530 final Phone phone = PhoneFactory.getPhone(slotIndex);
4531 if (phone != null) {
4532 return phone.getIccCard().hasIccCard();
4533 } else {
4534 return false;
4535 }
4536 } finally {
4537 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004538 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004539 }
4540
4541 /**
4542 * Return if the current radio is LTE on CDMA. This
4543 * is a tri-state return value as for a period of time
4544 * the mode may be unknown.
4545 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004546 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004547 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004548 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004549 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004550 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004551 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4552 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4553 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004554 }
4555
Sanket Padawe356d7632015-06-22 14:03:32 -07004556 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004557 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4558 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004559 try {
4560 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4561 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004562 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4563 }
4564
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004565 final long identity = Binder.clearCallingIdentity();
4566 try {
4567 final Phone phone = getPhone(subId);
4568 if (phone == null) {
4569 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4570 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004571 return TelephonyProperties.lte_on_cdma_device()
4572 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004573 }
4574 } finally {
4575 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004576 }
Wink Saville36469e72014-06-11 15:17:00 -07004577 }
4578
Wink Saville36469e72014-06-11 15:17:00 -07004579 /**
4580 * {@hide}
4581 * Returns Default subId, 0 in the case of single standby.
4582 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004583 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004584 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004585 }
4586
Shishir Agrawala9f32182016-04-12 12:00:16 -07004587 private int getSlotForDefaultSubscription() {
4588 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4589 }
4590
Wink Savilleb564aae2014-10-23 10:18:09 -07004591 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004592 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004593 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004594
Pengquan Menge92a50d2018-09-21 15:54:48 -07004595 private boolean isActiveSubscription(int subId) {
4596 return mSubscriptionController.isActiveSubId(subId);
4597 }
4598
Ihab Awadf2177b72013-11-25 13:33:23 -08004599 /**
4600 * @see android.telephony.TelephonyManager.WifiCallingChoices
4601 */
4602 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004603 final long identity = Binder.clearCallingIdentity();
4604 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004605 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004606 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4607 getWhenToMakeWifiCallsDefaultPreference());
4608 } finally {
4609 Binder.restoreCallingIdentity(identity);
4610 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004611 }
4612
4613 /**
4614 * @see android.telephony.TelephonyManager.WifiCallingChoices
4615 */
4616 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004617 final long identity = Binder.clearCallingIdentity();
4618 try {
4619 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004620 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004621 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4622 } finally {
4623 Binder.restoreCallingIdentity(identity);
4624 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004625 }
4626
Sailesh Nepald1e68152013-12-12 19:08:02 -08004627 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004628 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004629 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004630 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004631
Jordan Liu4c733742019-02-28 12:03:40 -08004632 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4633 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4634 if (phoneId == -1) {
4635 throw new IllegalArgumentException("Given slot index: " + slotIndex
4636 + " does not correspond to an active phone");
4637 }
4638 return PhoneFactory.getPhone(phoneId);
4639 }
4640
Shishir Agrawal566b7612013-10-28 14:41:00 -07004641 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004642 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4643 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4645 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004646 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004647 if (DBG) {
4648 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4649 }
4650 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4651 p2);
4652 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004653
Jordan Liu4c733742019-02-28 12:03:40 -08004654
4655 @Override
4656 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4657 int slotIndex, String callingPackage, String aid, int p2) {
4658 enforceModifyPermission();
4659 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4660 if (DBG) {
4661 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4662 }
4663 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4664 callingPackage, aid, p2);
4665 }
4666
4667 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4668 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004669 final long identity = Binder.clearCallingIdentity();
4670 try {
4671 if (TextUtils.equals(ISDR_AID, aid)) {
4672 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004673 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4674 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004675 if (bestComponent == null
4676 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4677 loge("The calling package is not allowed to access ISD-R.");
4678 throw new SecurityException(
4679 "The calling package is not allowed to access ISD-R.");
4680 }
Derek Tan740e1672017-06-27 14:56:27 -07004681 }
Derek Tan740e1672017-06-27 14:56:27 -07004682
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004683 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004684 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4685 null /* workSource */);
4686 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004687 return response;
4688 } finally {
4689 Binder.restoreCallingIdentity(identity);
4690 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004691 }
4692
4693 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004694 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4696 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004697 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4698 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4699 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004700
Jordan Liu4c733742019-02-28 12:03:40 -08004701 @Override
4702 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4703 enforceModifyPermission();
4704 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4705 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4706 channel);
4707 }
4708
4709 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004710 final long identity = Binder.clearCallingIdentity();
4711 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004712 if (channel < 0) {
4713 return false;
4714 }
Jordan Liu4c733742019-02-28 12:03:40 -08004715 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4716 null /* workSource */);
4717 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004718 return success;
4719 } finally {
4720 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004721 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004722 }
4723
4724 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004725 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004726 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004727 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4728 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004729 if (DBG) {
4730 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4731 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4732 + p3 + " data=" + data);
4733 }
4734 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4735 command, p1, p2, p3, data);
4736 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004737
Jordan Liu4c733742019-02-28 12:03:40 -08004738 @Override
4739 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4740 int command, int p1, int p2, int p3, String data) {
4741 enforceModifyPermission();
4742 if (DBG) {
4743 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4744 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4745 + p3 + " data=" + data);
4746 }
4747 return iccTransmitApduLogicalChannelWithPermission(
4748 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4749 data);
4750 }
4751
4752 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4753 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004754 final long identity = Binder.clearCallingIdentity();
4755 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004756 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004757 return "";
4758 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004759
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004760 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004761 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4762 null /* workSource */);
4763 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004765 // Append the returned status code to the end of the response payload.
4766 String s = Integer.toHexString(
4767 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4768 if (response.payload != null) {
4769 s = IccUtils.bytesToHexString(response.payload) + s;
4770 }
4771 return s;
4772 } finally {
4773 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004774 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004775 }
Jake Hambye994d462014-02-03 13:10:13 -08004776
Evan Charltonc66da362014-05-16 14:06:40 -07004777 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004778 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4779 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4781 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004782 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004783 if (DBG) {
4784 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4785 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4786 }
4787 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4788 cla, command, p1, p2, p3, data);
4789 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004790
Jordan Liu4c733742019-02-28 12:03:40 -08004791 @Override
4792 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4793 int command, int p1, int p2, int p3, String data) {
4794 enforceModifyPermission();
4795 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4796 if (DBG) {
4797 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4798 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4799 + " data=" + data);
4800 }
4801
4802 return iccTransmitApduBasicChannelWithPermission(
4803 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4804 p2, p3, data);
4805 }
4806
4807 // open APDU basic channel assuming the caller has sufficient permissions
4808 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4809 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004810 final long identity = Binder.clearCallingIdentity();
4811 try {
4812 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4813 && TextUtils.equals(ISDR_AID, data)) {
4814 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004815 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4816 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004817 if (bestComponent == null
4818 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4819 loge("The calling package is not allowed to select ISD-R.");
4820 throw new SecurityException(
4821 "The calling package is not allowed to select ISD-R.");
4822 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004823 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004824
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004825 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004826 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4827 null /* workSource */);
4828 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004829
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004830 // Append the returned status code to the end of the response payload.
4831 String s = Integer.toHexString(
4832 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4833 if (response.payload != null) {
4834 s = IccUtils.bytesToHexString(response.payload) + s;
4835 }
4836 return s;
4837 } finally {
4838 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004839 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004840 }
4841
4842 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004843 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004844 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4846 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004847
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004848 final long identity = Binder.clearCallingIdentity();
4849 try {
4850 if (DBG) {
4851 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4852 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4853 }
4854
4855 IccIoResult response =
4856 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4857 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4858 subId);
4859
4860 if (DBG) {
4861 log("Exchange SIM_IO [R]" + response);
4862 }
4863
4864 byte[] result = null;
4865 int length = 2;
4866 if (response.payload != null) {
4867 length = 2 + response.payload.length;
4868 result = new byte[length];
4869 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4870 } else {
4871 result = new byte[length];
4872 }
4873
4874 result[length - 1] = (byte) response.sw2;
4875 result[length - 2] = (byte) response.sw1;
4876 return result;
4877 } finally {
4878 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004879 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004880 }
4881
Nathan Haroldb3014052017-01-25 15:57:32 -08004882 /**
4883 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4884 * on a particular subscription
4885 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004886 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4887 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004888 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004889 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004890 return null;
4891 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004892
4893 final long identity = Binder.clearCallingIdentity();
4894 try {
4895 if (appType != TelephonyManager.APPTYPE_USIM
4896 && appType != TelephonyManager.APPTYPE_SIM) {
4897 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4898 return null;
4899 }
4900 Object response = sendRequest(
4901 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4902 if (response instanceof String[]) {
4903 return (String[]) response;
4904 }
yincheng zhao2737e882019-09-06 17:06:54 -07004905 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004906 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004907 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004908 } finally {
4909 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004910 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004911 }
4912
yincheng zhao2737e882019-09-06 17:06:54 -07004913 /**
4914 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4915 * subscription.
4916 *
4917 * @param subId the id of the subscription.
4918 * @param appType the uicc app type, must be USIM or SIM.
4919 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4920 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004921 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004922 * @return number of fplmns that is successfully written to the SIM.
4923 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004924 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4925 String callingFeatureId) {
4926 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4927 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004928 if (DBG) logv("no permissions for setForbiddenplmns");
4929 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4930 }
4931 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4932 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4933 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4934 }
4935 if (fplmns == null) {
4936 throw new IllegalArgumentException("Fplmn List provided is null");
4937 }
4938 for (String fplmn : fplmns) {
4939 if (!CellIdentity.isValidPlmn(fplmn)) {
4940 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4941 }
4942 }
4943 final long identity = Binder.clearCallingIdentity();
4944 try {
4945 Object response = sendRequest(
4946 CMD_SET_FORBIDDEN_PLMNS,
4947 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4948 subId);
4949 return (int) response;
4950 } finally {
4951 Binder.restoreCallingIdentity(identity);
4952 }
4953 }
4954
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004955 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004956 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4958 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004959
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004960 final long identity = Binder.clearCallingIdentity();
4961 try {
4962 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4963 if (response.payload == null) {
4964 return "";
4965 }
Evan Charltonc66da362014-05-16 14:06:40 -07004966
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004967 // Append the returned status code to the end of the response payload.
4968 String s = Integer.toHexString(
4969 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4970 s = IccUtils.bytesToHexString(response.payload) + s;
4971 return s;
4972 } finally {
4973 Binder.restoreCallingIdentity(identity);
4974 }
Evan Charltonc66da362014-05-16 14:06:40 -07004975 }
4976
Jake Hambye994d462014-02-03 13:10:13 -08004977 /**
4978 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4979 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4980 *
4981 * @param itemID the ID of the item to read
4982 * @return the NV item as a String, or null on error.
4983 */
4984 @Override
4985 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004986 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4988 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989
4990 final long identity = Binder.clearCallingIdentity();
4991 try {
4992 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004993 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4995 return value;
4996 } finally {
4997 Binder.restoreCallingIdentity(identity);
4998 }
Jake Hambye994d462014-02-03 13:10:13 -08004999 }
5000
5001 /**
5002 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5003 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5004 *
5005 * @param itemID the ID of the item to read
5006 * @param itemValue the value to write, as a String
5007 * @return true on success; false on any failure
5008 */
5009 @Override
5010 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005011 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5013 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005014
5015 final long identity = Binder.clearCallingIdentity();
5016 try {
5017 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5018 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005019 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5021 return success;
5022 } finally {
5023 Binder.restoreCallingIdentity(identity);
5024 }
Jake Hambye994d462014-02-03 13:10:13 -08005025 }
5026
5027 /**
5028 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5029 * Used for device configuration by some CDMA operators.
5030 *
5031 * @param preferredRoamingList byte array containing the new PRL
5032 * @return true on success; false on any failure
5033 */
5034 @Override
5035 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5037 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038
5039 final long identity = Binder.clearCallingIdentity();
5040 try {
5041 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5042 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5043 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5044 return success;
5045 } finally {
5046 Binder.restoreCallingIdentity(identity);
5047 }
Jake Hambye994d462014-02-03 13:10:13 -08005048 }
5049
5050 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005051 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005052 * Used for device configuration by some CDMA operators.
5053 *
chen xu6dac5ab2018-10-26 17:39:23 -07005054 * @param slotIndex - device slot.
5055 *
Jake Hambye994d462014-02-03 13:10:13 -08005056 * @return true on success; false on any failure
5057 */
5058 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005059 public boolean resetModemConfig(int slotIndex) {
5060 Phone phone = PhoneFactory.getPhone(slotIndex);
5061 if (phone != null) {
5062 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5063 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005064
chen xu6dac5ab2018-10-26 17:39:23 -07005065 final long identity = Binder.clearCallingIdentity();
5066 try {
5067 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5068 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5069 return success;
5070 } finally {
5071 Binder.restoreCallingIdentity(identity);
5072 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005073 }
chen xu6dac5ab2018-10-26 17:39:23 -07005074 return false;
5075 }
5076
5077 /**
5078 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5079 *
5080 * @param slotIndex - device slot.
5081 *
5082 * @return true on success; false on any failure
5083 */
5084 @Override
5085 public boolean rebootModem(int slotIndex) {
5086 Phone phone = PhoneFactory.getPhone(slotIndex);
5087 if (phone != null) {
5088 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5089 mApp, phone.getSubId(), "rebootModem");
5090
5091 final long identity = Binder.clearCallingIdentity();
5092 try {
5093 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5094 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5095 return success;
5096 } finally {
5097 Binder.restoreCallingIdentity(identity);
5098 }
5099 }
5100 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005101 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005102
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005103 public String[] getPcscfAddress(String apnType, String callingPackage,
5104 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005105 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005106 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5107 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005108 return new String[0];
5109 }
5110
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005111 final long identity = Binder.clearCallingIdentity();
5112 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005113 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005114 } finally {
5115 Binder.restoreCallingIdentity(identity);
5116 }
Wink Saville36469e72014-06-11 15:17:00 -07005117 }
5118
Brad Ebinger51f743a2017-01-23 13:50:20 -08005119 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005120 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5121 * {@link #disableIms(int)}.
5122 * @param slotIndex device slot.
5123 */
5124 public void resetIms(int slotIndex) {
5125 enforceModifyPermission();
5126
5127 final long identity = Binder.clearCallingIdentity();
5128 try {
5129 if (mImsResolver == null) {
5130 // may happen if the does not support IMS.
5131 return;
5132 }
5133 mImsResolver.disableIms(slotIndex);
5134 mImsResolver.enableIms(slotIndex);
5135 } finally {
5136 Binder.restoreCallingIdentity(identity);
5137 }
5138 }
5139
5140 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005141 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5142 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005143 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005144 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005145 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005146
5147 final long identity = Binder.clearCallingIdentity();
5148 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005149 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005150 // may happen if the device does not support IMS.
5151 return;
5152 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005153 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154 } finally {
5155 Binder.restoreCallingIdentity(identity);
5156 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005157 }
5158
5159 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005160 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5161 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005162 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005163 public void disableIms(int slotId) {
5164 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005165
5166 final long identity = Binder.clearCallingIdentity();
5167 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005168 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005169 // may happen if the device does not support IMS.
5170 return;
5171 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005172 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 } finally {
5174 Binder.restoreCallingIdentity(identity);
5175 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005176 }
5177
5178 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005179 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5180 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005181 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005182 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005183 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005184 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005185
5186 final long identity = Binder.clearCallingIdentity();
5187 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005188 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005189 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5190 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005191 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005192 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193 } finally {
5194 Binder.restoreCallingIdentity(identity);
5195 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005196 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005197 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005198 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5199 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005200 @Override
5201 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005202 enforceModifyPermission();
5203
5204 final long identity = Binder.clearCallingIdentity();
5205 try {
5206 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005207 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005208 } finally {
5209 Binder.restoreCallingIdentity(identity);
5210 }
5211 }
5212
5213 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005214 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005215 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005216 */
5217 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5218 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005219
5220 final long identity = Binder.clearCallingIdentity();
5221 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005222 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005223 // may happen if the device does not support IMS.
5224 return null;
5225 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005226 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005227 } finally {
5228 Binder.restoreCallingIdentity(identity);
5229 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005230 }
5231
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005232 /**
5233 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005234 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005235 */
5236 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5237 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238
5239 final long identity = Binder.clearCallingIdentity();
5240 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005241 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005242 // may happen if the device does not support IMS.
5243 return null;
5244 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005245 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246 } finally {
5247 Binder.restoreCallingIdentity(identity);
5248 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005249 }
5250
Brad Ebinger884c07b2018-02-15 16:17:40 -08005251 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005252 * Sets the ImsService Package Name that Telephony will bind to.
5253 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005254 * @param slotIndex the slot ID that the ImsService should bind for.
5255 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005256 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005257 * @param featureTypes An integer array of feature types associated with a packageName.
5258 * @param packageName The name of the package that the current configuration will be replaced
5259 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005260 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005261 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005262 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5263 int[] featureTypes, String packageName) {
5264 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5265 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5267 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005268 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005269
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270 final long identity = Binder.clearCallingIdentity();
5271 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005272 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005273 // may happen if the device does not support IMS.
5274 return false;
5275 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005276 Map<Integer, String> featureConfig = new HashMap<>();
5277 for (int featureType : featureTypes) {
5278 featureConfig.put(featureType, packageName);
5279 }
5280 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5281 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 } finally {
5283 Binder.restoreCallingIdentity(identity);
5284 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005285 }
5286
5287 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005288 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005289 *
5290 * @param slotId The slot that the ImsService is associated with.
5291 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5292 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005293 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005294 * @return the package name of the ImsService configuration.
5295 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005296 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5297 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005298 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005299 TelephonyPermissions
5300 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5301 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5302 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005304 final long identity = Binder.clearCallingIdentity();
5305 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005306 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005307 // may happen if the device does not support IMS.
5308 return "";
5309 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005310 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005311 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5312 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005313 } finally {
5314 Binder.restoreCallingIdentity(identity);
5315 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005316 }
5317
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005318 /**
5319 * Get the MmTelFeature state associated with the requested subscription id.
5320 * @param subId The subscription that the MmTelFeature is associated with.
5321 * @param callback A callback with an integer containing the
5322 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5323 */
5324 @Override
5325 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5326 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5327 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5328 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5329 "IMS not available on device.");
5330 }
5331 final long token = Binder.clearCallingIdentity();
5332 try {
5333 int slotId = getSlotIndex(subId);
5334 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5335 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5336 + subId + "'");
5337 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5338 }
5339 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5340 try {
5341 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5342 } catch (RemoteException e) {
5343 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5344 + "Ignore");
5345 }
5346 });
5347 } finally {
5348 Binder.restoreCallingIdentity(token);
5349 }
5350 }
5351
Wink Saville36469e72014-06-11 15:17:00 -07005352 public void setImsRegistrationState(boolean registered) {
5353 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354
5355 final long identity = Binder.clearCallingIdentity();
5356 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005357 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 } finally {
5359 Binder.restoreCallingIdentity(identity);
5360 }
Wink Saville36469e72014-06-11 15:17:00 -07005361 }
5362
5363 /**
Stuart Scott54788802015-03-30 13:18:01 -07005364 * Set the network selection mode to automatic.
5365 *
5366 */
5367 @Override
5368 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5370 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005371
5372 final long identity = Binder.clearCallingIdentity();
5373 try {
shilufc958392020-01-20 11:36:01 -08005374 if (!isActiveSubscription(subId)) {
5375 return;
5376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005377 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5378 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5379 } finally {
5380 Binder.restoreCallingIdentity(identity);
5381 }
Stuart Scott54788802015-03-30 13:18:01 -07005382 }
5383
Jack Yud10cdd42020-09-28 20:28:01 -07005384 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005385 * Ask the radio to connect to the input network and change selection mode to manual.
5386 *
5387 * @param subId the id of the subscription.
5388 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5389 * the operator to attach to.
5390 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5391 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5392 * normal network selection next time.
5393 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005394 */
5395 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005396 public boolean setNetworkSelectionModeManual(
5397 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5399 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005400
5401 if (!isActiveSubscription(subId)) {
5402 return false;
5403 }
5404
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005405 final long identity = Binder.clearCallingIdentity();
5406 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005407 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005409 if (DBG) {
5410 log("setNetworkSelectionModeManual: subId: " + subId
5411 + " operator: " + operatorInfo);
5412 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005413 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5414 } finally {
5415 Binder.restoreCallingIdentity(identity);
5416 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005417 }
shilu84f6e8b2019-12-19 13:58:01 -08005418 /**
5419 * Get the manual network selection
5420 *
5421 * @param subId the id of the subscription.
5422 *
5423 * @return the previously saved user selected PLMN
5424 */
5425 @Override
5426 public String getManualNetworkSelectionPlmn(int subId) {
5427 TelephonyPermissions
5428 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5429 mApp, subId, "getManualNetworkSelectionPlmn");
5430
5431 final long identity = Binder.clearCallingIdentity();
5432 try {
5433 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005434 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005435 }
5436
5437 final Phone phone = getPhone(subId);
5438 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005439 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005440 }
5441 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5442 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5443 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5444 } finally {
5445 Binder.restoreCallingIdentity(identity);
5446 }
5447 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005448
5449 /**
5450 * Scans for available networks.
5451 */
5452 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005453 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5454 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5456 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005457 LocationAccessPolicy.LocationPermissionResult locationResult =
5458 LocationAccessPolicy.checkLocationPermission(mApp,
5459 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5460 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005461 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005462 .setCallingPid(Binder.getCallingPid())
5463 .setCallingUid(Binder.getCallingUid())
5464 .setMethod("getCellNetworkScanResults")
5465 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005466 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5467 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005468 .build());
5469 switch (locationResult) {
5470 case DENIED_HARD:
5471 throw new SecurityException("Not allowed to access scan results -- location");
5472 case DENIED_SOFT:
5473 return null;
5474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475
Pengquan Menga1bb6272018-09-06 09:59:22 -07005476 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005477 try {
5478 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005479 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005480 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481 } finally {
5482 Binder.restoreCallingIdentity(identity);
5483 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005484 }
5485
5486 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005487 * Get the call forwarding info, given the call forwarding reason.
5488 */
5489 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005490 public void getCallForwarding(int subId, int callForwardingReason,
5491 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005492 enforceReadPrivilegedPermission("getCallForwarding");
5493 long identity = Binder.clearCallingIdentity();
5494 try {
5495 if (DBG) {
5496 log("getCallForwarding: subId " + subId
5497 + " callForwardingReason" + callForwardingReason);
5498 }
Hall Liu27d24262020-09-18 19:04:59 -07005499
5500 Phone phone = getPhone(subId);
5501 if (phone == null) {
5502 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005503 callback.onError(
5504 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005505 } catch (RemoteException e) {
5506 // ignore
5507 }
5508 return;
5509 }
5510
5511 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5512 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5513 @Override
5514 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5515 try {
5516 callback.onCallForwardingInfoAvailable(info);
5517 } catch (RemoteException e) {
5518 // ignore
5519 }
5520 }
5521
5522 @Override
5523 public void onError(int error) {
5524 try {
5525 callback.onError(error);
5526 } catch (RemoteException e) {
5527 // ignore
5528 }
5529 }
5530 });
5531 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005532 } finally {
5533 Binder.restoreCallingIdentity(identity);
5534 }
5535 }
5536
5537 /**
5538 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5539 * reason, the number to forward, and the timeout before the forwarding is attempted.
5540 */
5541 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005542 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5543 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005544 enforceModifyPermission();
5545 long identity = Binder.clearCallingIdentity();
5546 try {
5547 if (DBG) {
5548 log("setCallForwarding: subId " + subId
5549 + " callForwardingInfo" + callForwardingInfo);
5550 }
Hall Liu27d24262020-09-18 19:04:59 -07005551
5552 Phone phone = getPhone(subId);
5553 if (phone == null) {
5554 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005555 callback.accept(
5556 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005557 } catch (RemoteException e) {
5558 // ignore
5559 }
5560 return;
5561 }
5562
5563 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5564 FunctionalUtils.ignoreRemoteException(callback::accept));
5565
5566 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005567 } finally {
5568 Binder.restoreCallingIdentity(identity);
5569 }
5570 }
5571
5572 /**
Hall Liu27d24262020-09-18 19:04:59 -07005573 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005574 */
5575 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005576 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005577 enforceReadPrivilegedPermission("getCallForwarding");
5578 long identity = Binder.clearCallingIdentity();
5579 try {
Hall Liu27d24262020-09-18 19:04:59 -07005580
5581 Phone phone = getPhone(subId);
5582 if (phone == null) {
5583 try {
5584 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5585 } catch (RemoteException e) {
5586 // ignore
5587 }
5588 return;
5589 }
5590
5591 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5592
Shuo Qian4a594052020-01-23 11:59:30 -08005593 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005594 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005595 } finally {
5596 Binder.restoreCallingIdentity(identity);
5597 }
5598 }
5599
5600 /**
Hall Liu27d24262020-09-18 19:04:59 -07005601 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005602 */
5603 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005604 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005605 enforceModifyPermission();
5606 long identity = Binder.clearCallingIdentity();
5607 try {
Hall Liu27d24262020-09-18 19:04:59 -07005608 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5609
5610 Phone phone = getPhone(subId);
5611 if (phone == null) {
5612 try {
5613 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5614 } catch (RemoteException e) {
5615 // ignore
5616 }
5617 return;
5618 }
5619
5620 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5621 FunctionalUtils.ignoreRemoteException(callback::accept));
5622
5623 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005624 } finally {
5625 Binder.restoreCallingIdentity(identity);
5626 }
5627 }
5628
5629 /**
yinxub1bed742017-04-17 11:45:04 -07005630 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005631 *
yinxub1bed742017-04-17 11:45:04 -07005632 * @param subId id of the subscription
5633 * @param request contains the radio access networks with bands/channels to scan
5634 * @param messenger callback messenger for scan results or errors
5635 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005636 * @return the id of the requested scan which can be used to stop the scan.
5637 */
5638 @Override
5639 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005640 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5642 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005643 LocationAccessPolicy.LocationPermissionResult locationResult =
5644 LocationAccessPolicy.checkLocationPermission(mApp,
5645 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5646 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005647 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005648 .setCallingPid(Binder.getCallingPid())
5649 .setCallingUid(Binder.getCallingUid())
5650 .setMethod("requestNetworkScan")
5651 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005652 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5653 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005654 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005655 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005656 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5657 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005658 if (e != null) {
5659 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5660 throw e;
5661 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005662 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005663 return TelephonyScanManager.INVALID_SCAN_ID;
5664 }
5665 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666 }
Hall Liu912dfd32019-04-25 14:02:26 -07005667 int callingUid = Binder.getCallingUid();
5668 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005669 final long identity = Binder.clearCallingIdentity();
5670 try {
5671 return mNetworkScanRequestTracker.startNetworkScan(
5672 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005673 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005674 } finally {
5675 Binder.restoreCallingIdentity(identity);
5676 }
yinxu504e1392017-04-12 16:03:22 -07005677 }
5678
Hall Liub2ac8ef2019-02-28 15:56:23 -08005679 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005680 NetworkScanRequest request, int subId, String callingPackage) {
5681 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005682 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5683 boolean hasNetworkScanPermission =
5684 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5685 == PERMISSION_GRANTED;
5686
5687 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5688 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5689 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005690 }
5691
5692 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5693 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005694 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5695 return new SecurityException("Specific channels must not be"
5696 + " scanned without location access.");
5697 }
5698 }
5699 }
5700
Hall Liub2ac8ef2019-02-28 15:56:23 -08005701 return null;
5702 }
5703
yinxu504e1392017-04-12 16:03:22 -07005704 /**
5705 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005706 *
5707 * @param subId id of the subscription
5708 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005709 */
5710 @Override
5711 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5713 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005714
Hall Liu912dfd32019-04-25 14:02:26 -07005715 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716 final long identity = Binder.clearCallingIdentity();
5717 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005718 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005719 } finally {
5720 Binder.restoreCallingIdentity(identity);
5721 }
yinxu504e1392017-04-12 16:03:22 -07005722 }
5723
5724 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005725 * Get the calculated preferred network type.
5726 * Used for debugging incorrect network type.
5727 *
5728 * @return the preferred network type, defined in RILConstants.java.
5729 */
5730 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005731 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005732 final Phone defaultPhone = getDefaultPhone();
5733 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005734 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005735 return RILConstants.PREFERRED_NETWORK_MODE;
5736 }
5737
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738 final long identity = Binder.clearCallingIdentity();
5739 try {
5740 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005741 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742 } finally {
5743 Binder.restoreCallingIdentity(identity);
5744 }
Junda Liu84d15a22014-07-02 11:21:04 -07005745 }
5746
5747 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005748 * Get the preferred network type.
5749 * Used for device configuration by some CDMA operators.
5750 *
5751 * @return the preferred network type, defined in RILConstants.java.
5752 */
5753 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005754 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005755 TelephonyPermissions
5756 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5757 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005758
5759 final long identity = Binder.clearCallingIdentity();
5760 try {
5761 if (DBG) log("getPreferredNetworkType");
5762 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5763 int networkType = (result != null ? result[0] : -1);
5764 if (DBG) log("getPreferredNetworkType: " + networkType);
5765 return networkType;
5766 } finally {
5767 Binder.restoreCallingIdentity(identity);
5768 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005769 }
5770
5771 /**
5772 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005773 *
5774 * @param networkType the preferred network type, defined in RILConstants.java.
5775 * @return true on success; false on any failure.
5776 */
5777 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005778 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5780 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005781
5782 final long identity = Binder.clearCallingIdentity();
5783 try {
calvinpan8ed33732020-03-12 14:17:55 +08005784 Boolean success = (Boolean) sendRequest(
5785 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005786
5787 if (success) {
5788 Settings.Global.putInt(mApp.getContentResolver(),
5789 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5790 }
calvinpan8ed33732020-03-12 14:17:55 +08005791 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5792 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005793 } finally {
5794 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005795 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005796 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005797
5798 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005799 * Get the allowed network types that store in the telephony provider.
5800 *
5801 * @param subId the id of the subscription.
5802 * @return allowedNetworkTypes the allowed network types.
5803 */
5804 @Override
5805 public long getAllowedNetworkTypes(int subId) {
5806 TelephonyPermissions
5807 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5808 mApp, subId, "getAllowedNetworkTypes");
5809
5810 final long identity = Binder.clearCallingIdentity();
5811 try {
5812 return SubscriptionManager.getLongSubscriptionProperty(
5813 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5814 } finally {
5815 Binder.restoreCallingIdentity(identity);
5816 }
5817 }
5818
5819 /**
5820 * Set the allowed network types.
5821 *
5822 * @param subId the id of the subscription.
5823 * @param allowedNetworkTypes the allowed network types.
5824 * @return true on success; false on any failure.
5825 */
5826 @Override
5827 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5829 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005830
calvinpan8ed33732020-03-12 14:17:55 +08005831 SubscriptionManager.setSubscriptionProperty(subId,
5832 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5833 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005834
calvinpan8ed33732020-03-12 14:17:55 +08005835 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5836 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5837 RILConstants.PREFERRED_NETWORK_MODE);
5838 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005839 }
5840
5841 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005842 * Get the allowed network types for certain reason.
5843 *
5844 * @param subId the id of the subscription.
5845 * @param reason the reason the allowed network type change is taking place
5846 * @return the allowed network types.
5847 */
5848 @Override
5849 public long getAllowedNetworkTypesForReason(int subId,
5850 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5851 TelephonyPermissions
5852 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5853 mApp, subId, "getAllowedNetworkTypesForReason");
5854 final long identity = Binder.clearCallingIdentity();
5855 try {
5856 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5857 } finally {
5858 Binder.restoreCallingIdentity(identity);
5859 }
5860 }
5861
5862 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07005863 * Enable/Disable E-UTRA-NR Dual Connectivity
5864 * @param subId subscription id of the sim card
5865 * @param nrDualConnectivityState expected NR dual connectivity state
5866 * This can be passed following states
5867 * <ol>
5868 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
5869 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
5870 * <li>Disable NR dual connectivity and force secondary cell to be released
5871 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
5872 * </ol>
5873 * @return operation result.
5874 */
5875 @Override
5876 public int setNrDualConnectivityState(int subId,
5877 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
5878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5879 mApp, subId, "enableNRDualConnectivity");
5880 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5881 final long identity = Binder.clearCallingIdentity();
5882 try {
5883 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
5884 nrDualConnectivityState, subId,
5885 workSource);
5886 if (DBG) log("enableNRDualConnectivity result: " + result);
5887 return result;
5888 } finally {
5889 Binder.restoreCallingIdentity(identity);
5890 }
5891 }
5892
5893 /**
5894 * Is E-UTRA-NR Dual Connectivity enabled
5895 * @return true if dual connectivity is enabled else false
5896 */
5897 @Override
5898 public boolean isNrDualConnectivityEnabled(int subId) {
5899 TelephonyPermissions
5900 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5901 mApp, subId, "isNRDualConnectivityEnabled");
5902 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5903 final long identity = Binder.clearCallingIdentity();
5904 try {
5905 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
5906 null, subId, workSource);
5907 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
5908 return isEnabled;
5909 } finally {
5910 Binder.restoreCallingIdentity(identity);
5911 }
5912 }
5913
5914 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07005915 * get carrier bandwidth per primary and secondary carrier
5916 * @param subId subscription id of the sim card
5917 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
5918 */
5919 @Override
5920 public CarrierBandwidth getCarrierBandwidth(int subId) {
5921 TelephonyPermissions
5922 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5923 mApp, subId, "isNRDualConnectivityEnabled");
5924 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5925 final long identity = Binder.clearCallingIdentity();
5926 try {
5927 CarrierBandwidth carrierBandwidth =
5928 getPhoneFromSubId(subId).getCarrierBandwidth();
5929 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
5930 return carrierBandwidth;
5931 } finally {
5932 Binder.restoreCallingIdentity(identity);
5933 }
5934 }
5935
5936 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005937 * Get the effective allowed network types on the device.
5938 * This API will return an intersection of allowed network types for all reasons,
5939 * including the configuration done through setAllowedNetworkTypes
5940 *
5941 * @param subId the id of the subscription.
5942 * @return the allowed network types
5943 */
5944 @Override
5945 public long getEffectiveAllowedNetworkTypes(int subId) {
5946 TelephonyPermissions
5947 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5948 mApp, subId, "getEffectiveAllowedNetworkTypes");
5949 final long identity = Binder.clearCallingIdentity();
5950 try {
5951 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5952 } finally {
5953 Binder.restoreCallingIdentity(identity);
5954 }
5955 }
5956
5957 /**
5958 * Set the allowed network types of the device and
5959 * provide the reason triggering the allowed network change.
5960 *
5961 * @param subId the id of the subscription.
5962 * @param reason the reason the allowed network type change is taking place
5963 * @param allowedNetworkTypes the allowed network types.
5964 * @return true on success; false on any failure.
5965 */
5966 @Override
5967 public boolean setAllowedNetworkTypesForReason(int subId,
5968 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5969 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5970 mApp, subId, "setAllowedNetworkTypesForReason");
5971 final long identity = Binder.clearCallingIdentity();
5972 try {
5973 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5974 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5975 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5976 RILConstants.PREFERRED_NETWORK_MODE);
5977 return setPreferredNetworkType(subId, preferredNetworkMode);
5978 } finally {
5979 Binder.restoreCallingIdentity(identity);
5980 }
5981 }
5982
5983 /**
Miaoa84611c2019-03-15 09:21:10 +08005984 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005985 *
Miaoa84611c2019-03-15 09:21:10 +08005986 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005987 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005988 * @hide
5989 */
5990 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005991 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005992 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005994 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995 try {
Miaoa84611c2019-03-15 09:21:10 +08005996 if (phone != null) {
5997 return phone.hasMatchedTetherApnSetting();
5998 } else {
5999 return false;
6000 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001 } finally {
6002 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006003 }
Junda Liu475951f2014-11-07 16:45:03 -08006004 }
6005
6006 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006007 * Enable or disable always reporting signal strength changes from radio.
6008 *
6009 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6010 */
6011 @Override
6012 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6013 enforceModifyPermission();
6014 enforceSystemCaller();
6015
6016 final long identity = Binder.clearCallingIdentity();
6017 final Phone phone = getPhone(subId);
6018 try {
6019 if (phone != null) {
6020 if (DBG) {
6021 log("setAlwaysReportSignalStrength: subId=" + subId
6022 + " isEnable=" + isEnable);
6023 }
6024 phone.setAlwaysReportSignalStrength(isEnable);
6025 } else {
6026 loge("setAlwaysReportSignalStrength: no phone found for subId="
6027 + subId);
6028 }
6029 } finally {
6030 Binder.restoreCallingIdentity(identity);
6031 }
6032 }
6033
6034 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006035 * Get the user enabled state of Mobile Data.
6036 *
6037 * TODO: remove and use isUserDataEnabled.
6038 * This can't be removed now because some vendor codes
6039 * calls through ITelephony directly while they should
6040 * use TelephonyManager.
6041 *
6042 * @return true on enabled
6043 */
6044 @Override
6045 public boolean getDataEnabled(int subId) {
6046 return isUserDataEnabled(subId);
6047 }
6048
6049 /**
6050 * Get whether mobile data is enabled per user setting.
6051 *
6052 * There are other factors deciding whether mobile data is actually enabled, but they are
6053 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006054 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006055 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006056 *
6057 * @return {@code true} if data is enabled else {@code false}
6058 */
6059 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006060 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006061 try {
6062 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6063 null);
6064 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6066 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068
6069 final long identity = Binder.clearCallingIdentity();
6070 try {
6071 int phoneId = mSubscriptionController.getPhoneId(subId);
6072 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6073 Phone phone = PhoneFactory.getPhone(phoneId);
6074 if (phone != null) {
6075 boolean retVal = phone.isUserDataEnabled();
6076 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6077 return retVal;
6078 } else {
6079 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6080 return false;
6081 }
6082 } finally {
6083 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006084 }
6085 }
6086
6087 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006088 * Checks if the device is capable of mobile data by considering whether whether the
6089 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6090 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006091 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006092 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006093 */
6094 @Override
6095 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006096 try {
6097 try {
6098 mApp.enforceCallingOrSelfPermission(
6099 android.Manifest.permission.ACCESS_NETWORK_STATE,
6100 null);
6101 } catch (Exception e) {
6102 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6103 "isDataEnabled");
6104 }
6105 } catch (Exception e) {
6106 enforceReadPrivilegedPermission("isDataEnabled");
6107 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006108
6109 final long identity = Binder.clearCallingIdentity();
6110 try {
6111 int phoneId = mSubscriptionController.getPhoneId(subId);
6112 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6113 Phone phone = PhoneFactory.getPhone(phoneId);
6114 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006115 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006116 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6117 return retVal;
6118 } else {
6119 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6120 return false;
6121 }
6122 } finally {
6123 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006124 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006125 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006126
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006127 /**
6128 * Check if data is enabled for a specific reason
6129 * @param subId Subscription index
6130 * @param reason the reason the data enable change is taking place
6131 * @return {@code true} if the overall data is enabled; {@code false} if not.
6132 */
6133 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006134 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006135 @TelephonyManager.DataEnabledReason int reason) {
6136 try {
6137 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6138 null);
6139 } catch (Exception e) {
6140 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006141 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006142 }
6143
6144
6145 final long identity = Binder.clearCallingIdentity();
6146 try {
6147 int phoneId = mSubscriptionController.getPhoneId(subId);
6148 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006149 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006150 + " reason=" + reason);
6151 }
6152 Phone phone = PhoneFactory.getPhone(phoneId);
6153 if (phone != null) {
6154 boolean retVal;
6155 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6156 retVal = phone.isUserDataEnabled();
6157 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006158 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006159 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006160 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006161 return retVal;
6162 } else {
6163 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006164 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006165 + subId + " retVal=false");
6166 }
6167 return false;
6168 }
6169 } finally {
6170 Binder.restoreCallingIdentity(identity);
6171 }
6172 }
6173
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006174 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006175 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006176 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6177 // Skip the check if it's one of these special uids
6178 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6179 }
6180
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006181 //load access rules from carrier configs, and check those as well: b/139133814
6182 SubscriptionController subController = SubscriptionController.getInstance();
6183 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6184 || subController == null) return privilegeFromSim;
6185
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006186 PackageManager pkgMgr = phone.getContext().getPackageManager();
6187 String[] packages = pkgMgr.getPackagesForUid(uid);
6188
6189 final long identity = Binder.clearCallingIdentity();
6190 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006191 int subId = phone.getSubId();
6192 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6193 // A test override is in place for the privileges for this subId, so don't try to
6194 // read the subscription privileges.
6195 return privilegeFromSim;
6196 }
6197 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006198 SubscriptionManager subManager = (SubscriptionManager)
6199 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6200 for (String pkg : packages) {
6201 if (subManager.canManageSubscription(subInfo, pkg)) {
6202 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6203 }
6204 }
6205 return privilegeFromSim;
6206 } finally {
6207 Binder.restoreCallingIdentity(identity);
6208 }
6209 }
6210
6211 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6212 String pkgName) {
6213 //load access rules from carrier configs, and check those as well: b/139133814
6214 SubscriptionController subController = SubscriptionController.getInstance();
6215 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6216 || subController == null) return privilegeFromSim;
6217
6218 final long identity = Binder.clearCallingIdentity();
6219 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006220 int subId = phone.getSubId();
6221 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6222 // A test override is in place for the privileges for this subId, so don't try to
6223 // read the subscription privileges.
6224 return privilegeFromSim;
6225 }
6226 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006227 SubscriptionManager subManager = (SubscriptionManager)
6228 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6229 return subManager.canManageSubscription(subInfo, pkgName)
6230 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6231 } finally {
6232 Binder.restoreCallingIdentity(identity);
6233 }
6234 }
6235
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006236 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006237 public int getCarrierPrivilegeStatus(int subId) {
6238 final Phone phone = getPhone(subId);
6239 if (phone == null) {
6240 loge("getCarrierPrivilegeStatus: Invalid subId");
6241 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6242 }
6243 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006244 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006245 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006246 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6247 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006248
6249 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6250 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006251 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006252 }
Junda Liu29340342014-07-10 15:23:27 -07006253
6254 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006255 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006256 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006257 final Phone phone = getPhone(subId);
6258 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006259 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006260 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6261 }
6262 UiccProfile profile =
6263 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6264 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006265 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006266 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6267 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006268 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006269 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006270 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006271 }
6272
6273 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006274 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6275 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006276 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006277 }
6278
6279 int phoneId = SubscriptionManager.getPhoneId(subId);
6280 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006281 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006282 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006283 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6284 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006285 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6286 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6287 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006288 }
6289
6290 @Override
6291 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006292 if (TextUtils.isEmpty(pkgName))
6293 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006294 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6295 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6296 UiccCard card = UiccController.getInstance().getUiccCard(i);
6297 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006298 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006299 continue;
6300 }
6301
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006302 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6303 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6304 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006305 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6306 break;
6307 }
6308 }
6309
6310 return result;
Junda Liu29340342014-07-10 15:23:27 -07006311 }
Derek Tan89e89d42014-07-08 17:00:10 -07006312
6313 @Override
Junda Liue64de782015-04-16 17:19:16 -07006314 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6315 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6316 loge("phoneId " + phoneId + " is not valid.");
6317 return null;
6318 }
6319 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006320 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006321 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006322 return null ;
6323 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006324 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006325 }
6326
Amith Yamasani6e118872016-02-19 12:53:51 -08006327 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006328 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006329 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006330 List<String> privilegedPackages = new ArrayList<>();
6331 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006332 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6333 // has UICC in that slot.
6334 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006335 if (card.hasCarrierPrivilegeRules()) {
6336 if (packages == null) {
6337 // Only check packages in user 0 for now
6338 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006339 PackageManager.MATCH_DISABLED_COMPONENTS
6340 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006341 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006342 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006343 }
6344 for (int p = packages.size() - 1; p >= 0; p--) {
6345 PackageInfo pkgInfo = packages.get(p);
6346 if (pkgInfo != null && pkgInfo.packageName != null
6347 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006348 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006349 privilegedPackages.add(pkgInfo.packageName);
6350 }
6351 }
6352 }
6353 }
6354 return privilegedPackages;
6355 }
6356
chen xuf7e9fe82019-05-09 19:31:02 -07006357 @Override
6358 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006359 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6360
6361 final long identity = Binder.clearCallingIdentity();
6362
chen xuf7e9fe82019-05-09 19:31:02 -07006363 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006364 try {
6365 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6366 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6367 }
6368 } finally {
6369 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006370 }
6371 return privilegedPackages;
6372 }
6373
Wink Savilleb564aae2014-10-23 10:18:09 -07006374 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006375 final Phone phone = getPhone(subId);
6376 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006377 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006378 return null;
6379 }
6380 String iccId = card.getIccId();
6381 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006382 return null;
6383 }
6384 return iccId;
6385 }
6386
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006387 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006388 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6389 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006390 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006391 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006392
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006393 final long identity = Binder.clearCallingIdentity();
6394 try {
6395 final String iccId = getIccId(subId);
6396 final Phone phone = getPhone(subId);
6397 if (phone == null) {
6398 return false;
6399 }
6400 final String subscriberId = phone.getSubscriberId();
6401
6402 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006403 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006404 + subscriberId + " to " + number);
6405 }
6406
6407 if (TextUtils.isEmpty(iccId)) {
6408 return false;
6409 }
6410
6411 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6412
6413 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6414 if (alphaTag == null) {
6415 editor.remove(alphaTagPrefKey);
6416 } else {
6417 editor.putString(alphaTagPrefKey, alphaTag);
6418 }
6419
6420 // Record both the line number and IMSI for this ICCID, since we need to
6421 // track all merged IMSIs based on line number
6422 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6423 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6424 if (number == null) {
6425 editor.remove(numberPrefKey);
6426 editor.remove(subscriberPrefKey);
6427 } else {
6428 editor.putString(numberPrefKey, number);
6429 editor.putString(subscriberPrefKey, subscriberId);
6430 }
6431
6432 editor.commit();
6433 return true;
6434 } finally {
6435 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006436 }
Derek Tan7226c842014-07-02 17:42:23 -07006437 }
6438
6439 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006440 public String getLine1NumberForDisplay(int subId, String callingPackage,
6441 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006442 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006443 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006444 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006445 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006446 return null;
6447 }
Derek Tan97ebb422014-09-05 16:55:38 -07006448
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006449 final long identity = Binder.clearCallingIdentity();
6450 try {
6451 String iccId = getIccId(subId);
6452 if (iccId != null) {
6453 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6454 if (DBG_MERGE) {
6455 log("getLine1NumberForDisplay returning "
6456 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6457 }
6458 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006459 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006460 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6461 return null;
6462 } finally {
6463 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006464 }
Derek Tan7226c842014-07-02 17:42:23 -07006465 }
6466
6467 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006468 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6469 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006471 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006472 return null;
6473 }
Derek Tan97ebb422014-09-05 16:55:38 -07006474
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006475 final long identity = Binder.clearCallingIdentity();
6476 try {
6477 String iccId = getIccId(subId);
6478 if (iccId != null) {
6479 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6480 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6481 }
6482 return null;
6483 } finally {
6484 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006485 }
Derek Tan7226c842014-07-02 17:42:23 -07006486 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006487
6488 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006489 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6490 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006491 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6492 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006493 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006494 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006495 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006496 return null;
6497 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006498
Jordan Liub49b04b2019-05-06 14:45:15 -07006499 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6500 // the process, where TelephonyManager was instantiated.
6501 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006502 final long identity = Binder.clearCallingIdentity();
6503 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006504 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006505 final TelephonyManager tele = TelephonyManager.from(context);
6506 final SubscriptionManager sub = SubscriptionManager.from(context);
6507
6508 // Figure out what subscribers are currently active
6509 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006510
Jordan Liub49b04b2019-05-06 14:45:15 -07006511 // Only consider subs which match the current subId
6512 // This logic can be simplified. See b/131189269 for progress.
6513 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006514 activeSubscriberIds.add(tele.getSubscriberId(subId));
6515 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006516
6517 // First pass, find a number override for an active subscriber
6518 String mergeNumber = null;
6519 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6520 for (String key : prefs.keySet()) {
6521 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6522 final String subscriberId = (String) prefs.get(key);
6523 if (activeSubscriberIds.contains(subscriberId)) {
6524 final String iccId = key.substring(
6525 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6526 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6527 mergeNumber = (String) prefs.get(numberKey);
6528 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006529 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006530 + " for active subscriber " + subscriberId);
6531 }
6532 if (!TextUtils.isEmpty(mergeNumber)) {
6533 break;
6534 }
6535 }
6536 }
6537 }
6538
6539 // Shortcut when no active merged subscribers
6540 if (TextUtils.isEmpty(mergeNumber)) {
6541 return null;
6542 }
6543
6544 // Second pass, find all subscribers under that line override
6545 final ArraySet<String> result = new ArraySet<>();
6546 for (String key : prefs.keySet()) {
6547 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6548 final String number = (String) prefs.get(key);
6549 if (mergeNumber.equals(number)) {
6550 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6551 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6552 final String subscriberId = (String) prefs.get(subscriberKey);
6553 if (!TextUtils.isEmpty(subscriberId)) {
6554 result.add(subscriberId);
6555 }
6556 }
6557 }
6558 }
6559
6560 final String[] resultArray = result.toArray(new String[result.size()]);
6561 Arrays.sort(resultArray);
6562 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006563 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006564 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6565 }
6566 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006567 } finally {
6568 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006569 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006570 }
6571
6572 @Override
zoey chen38003472019-12-13 17:16:31 +08006573 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6574 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006575
6576 final long identity = Binder.clearCallingIdentity();
6577 try {
6578 final TelephonyManager telephonyManager = mApp.getSystemService(
6579 TelephonyManager.class);
6580 String subscriberId = telephonyManager.getSubscriberId(subId);
6581 if (subscriberId == null) {
6582 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006583 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006584 + subId);
6585 }
6586 return null;
6587 }
6588
6589 final SubscriptionInfo info = SubscriptionController.getInstance()
6590 .getSubscriptionInfo(subId);
6591 final ParcelUuid groupUuid = info.getGroupUuid();
6592 // If it doesn't belong to any group, return just subscriberId of itself.
6593 if (groupUuid == null) {
6594 return new String[]{subscriberId};
6595 }
6596
6597 // Get all subscriberIds from the group.
6598 final List<String> mergedSubscriberIds = new ArrayList<>();
6599 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006600 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006601 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006602 for (SubscriptionInfo subInfo : groupInfos) {
6603 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6604 if (subscriberId != null) {
6605 mergedSubscriberIds.add(subscriberId);
6606 }
6607 }
6608
6609 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6610 } finally {
6611 Binder.restoreCallingIdentity(identity);
6612
6613 }
6614 }
6615
6616 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006617 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006618 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006619 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006620
6621 final long identity = Binder.clearCallingIdentity();
6622 try {
6623 final Phone phone = getPhone(subId);
6624 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6625 } finally {
6626 Binder.restoreCallingIdentity(identity);
6627 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006628 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006629
6630 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006631 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006632 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6633 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006634 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6635 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006636
6637 final long identity = Binder.clearCallingIdentity();
6638 try {
6639 final Phone phone = getPhone(subId);
6640 if (phone == null) {
6641 return false;
6642 }
6643 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6644 cdmaNonRoamingList);
6645 } finally {
6646 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006647 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006648 }
6649
6650 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006651 @Deprecated
6652 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6653 enforceModifyPermission();
6654
6655 int returnValue = 0;
6656 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006657 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006658 if(result.exception == null) {
6659 if (result.result != null) {
6660 byte[] responseData = (byte[])(result.result);
6661 if(responseData.length > oemResp.length) {
6662 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6663 responseData.length + "bytes. Buffer Size is " +
6664 oemResp.length + "bytes.");
6665 }
6666 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6667 returnValue = responseData.length;
6668 }
6669 } else {
6670 CommandException ex = (CommandException) result.exception;
6671 returnValue = ex.getCommandError().ordinal();
6672 if(returnValue > 0) returnValue *= -1;
6673 }
6674 } catch (RuntimeException e) {
6675 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6676 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6677 if(returnValue > 0) returnValue *= -1;
6678 }
6679
6680 return returnValue;
6681 }
6682
6683 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006684 public void setRadioCapability(RadioAccessFamily[] rafs) {
6685 try {
6686 ProxyController.getInstance().setRadioCapability(rafs);
6687 } catch (RuntimeException e) {
6688 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6689 }
6690 }
6691
6692 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006693 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006694 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006695 try {
6696 TelephonyPermissions
6697 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6698 mApp, phone.getSubId(), "getRadioAccessFamily");
6699 } catch (SecurityException e) {
6700 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6701 throw e;
6702 }
chen xub97461a2018-10-26 14:17:57 -07006703 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006704 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006705 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006706 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006707 final long identity = Binder.clearCallingIdentity();
6708 try {
chen xub97461a2018-10-26 14:17:57 -07006709 TelephonyPermissions
6710 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6711 mApp, phone.getSubId(), "getRadioAccessFamily");
6712 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006713 } finally {
6714 Binder.restoreCallingIdentity(identity);
6715 }
chen xub97461a2018-10-26 14:17:57 -07006716 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006717 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006718
6719 @Override
6720 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006721 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006722 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006723
6724 final long identity = Binder.clearCallingIdentity();
6725 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006726 ImsManager.getInstance(defaultPhone.getContext(),
6727 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006728 } finally {
6729 Binder.restoreCallingIdentity(identity);
6730 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006731 }
6732
6733 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006734 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006735 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006736 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6737 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006738 return false;
6739 }
Svet Ganovb320e182015-04-16 12:30:10 -07006740
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006741 final long identity = Binder.clearCallingIdentity();
6742 try {
6743 // Check the user preference and the system-level IMS setting. Even if the user has
6744 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6745 // In the long run, we may instead need to check if there exists a connection service
6746 // which can support video calling.
6747 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006748 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006749 return imsManager.isVtEnabledByPlatform()
6750 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6751 && imsManager.isVtEnabledByUser();
6752 } finally {
6753 Binder.restoreCallingIdentity(identity);
6754 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006755 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006756
Andrew Leea1239f22015-03-02 17:44:07 -08006757 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006758 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6759 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006760 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006761 mApp, subId, callingPackage, callingFeatureId,
6762 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006763 return false;
6764 }
6765
6766 final long identity = Binder.clearCallingIdentity();
6767 try {
6768 CarrierConfigManager configManager =
6769 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006770 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006771 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6772 } finally {
6773 Binder.restoreCallingIdentity(identity);
6774 }
Andrew Leea1239f22015-03-02 17:44:07 -08006775 }
6776
6777 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006778 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006779 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006780 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781 return false;
6782 }
6783
6784 final long identity = Binder.clearCallingIdentity();
6785 try {
6786 CarrierConfigManager configManager =
6787 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006788 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006789 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6790 } finally {
6791 Binder.restoreCallingIdentity(identity);
6792 }
Andrew Leea1239f22015-03-02 17:44:07 -08006793 }
6794
Andrew Lee9431b832015-03-09 18:46:45 -07006795 @Override
6796 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006797 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006798 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006799 }
6800
6801 @Override
6802 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006803 final long identity = Binder.clearCallingIdentity();
6804 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006805 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006806 } finally {
6807 Binder.restoreCallingIdentity(identity);
6808 }
Andrew Lee9431b832015-03-09 18:46:45 -07006809 }
6810
Hall Liuf6668912018-10-31 17:05:23 -07006811 /**
6812 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6813 * support for the feature and device firmware support.
6814 *
6815 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6816 */
6817 @Override
6818 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006819 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006820 final Phone phone = getPhone(subscriptionId);
6821 if (phone == null) {
6822 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6823 return false;
6824 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006825 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006826 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006827 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6828 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006829 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006830 return isCarrierSupported && isDeviceSupported;
6831 } finally {
6832 Binder.restoreCallingIdentity(identity);
6833 }
Hall Liu98187582018-01-22 19:15:32 -08006834 }
6835
Hall Liuf6668912018-10-31 17:05:23 -07006836 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006837 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6838 * RTT setting, will return true if the device and carrier both support RTT.
6839 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006840 */
6841 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006842 final long identity = Binder.clearCallingIdentity();
6843 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006844 boolean isRttSupported = isRttSupported(subscriptionId);
6845 boolean isUserRttSettingOn = Settings.Secure.getInt(
6846 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6847 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6848 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6849 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006850 } finally {
6851 Binder.restoreCallingIdentity(identity);
6852 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006853 }
6854
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006855 @Deprecated
6856 @Override
6857 public String getDeviceId(String callingPackage) {
6858 return getDeviceIdWithFeature(callingPackage, null);
6859 }
6860
Sanket Padawe7310cc72015-01-14 09:53:20 -08006861 /**
6862 * Returns the unique device ID of phone, for example, the IMEI for
6863 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6864 *
6865 * <p>Requires Permission:
6866 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6867 */
6868 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006869 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006870 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006871 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006872 return null;
6873 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006874 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006875 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006876 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006877 return null;
6878 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006879
6880 final long identity = Binder.clearCallingIdentity();
6881 try {
6882 return phone.getDeviceId();
6883 } finally {
6884 Binder.restoreCallingIdentity(identity);
6885 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006886 }
6887
Ping Sunc67b7c22016-03-02 19:16:45 +08006888 /**
6889 * {@hide}
6890 * Returns the IMS Registration Status on a particular subid
6891 *
6892 * @param subId
6893 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006894 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006895 Phone phone = getPhone(subId);
6896 if (phone != null) {
6897 return phone.isImsRegistered();
6898 } else {
6899 return false;
6900 }
6901 }
6902
Santos Cordon7a1885b2015-02-03 11:15:19 -08006903 @Override
6904 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006905 final long identity = Binder.clearCallingIdentity();
6906 try {
6907 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6908 } finally {
6909 Binder.restoreCallingIdentity(identity);
6910 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006911 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006912
Tyler Gunnf70ed162019-04-03 15:28:53 -07006913 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006914 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006915 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006916 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006917 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006918 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6919 }
6920 final long identity = Binder.clearCallingIdentity();
6921 try {
6922 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6923 } finally {
6924 Binder.restoreCallingIdentity(identity);
6925 }
6926 }
6927
6928 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006929 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006930 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6931 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006932 final long identity = Binder.clearCallingIdentity();
6933 try {
6934 Phone phone = getPhone(subscriptionId);
6935 if (phone == null) {
6936 return null;
6937 }
6938 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6939 } finally {
6940 Binder.restoreCallingIdentity(identity);
6941 }
6942 }
6943
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006944 /**
6945 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006946 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006947 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006948 final long identity = Binder.clearCallingIdentity();
6949 try {
6950 Phone phone = getPhone(subId);
6951 if (phone != null) {
6952 return phone.isWifiCallingEnabled();
6953 } else {
6954 return false;
6955 }
6956 } finally {
6957 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006958 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006959 }
6960
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006961 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006962 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006963 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006964 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006965 final long identity = Binder.clearCallingIdentity();
6966 try {
6967 Phone phone = getPhone(subId);
6968 if (phone != null) {
6969 return phone.isVideoEnabled();
6970 } else {
6971 return false;
6972 }
6973 } finally {
6974 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006975 }
6976 }
6977
6978 /**
6979 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6980 * defined in {@link ImsRegistrationImplBase}.
6981 */
6982 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006983 final long identity = Binder.clearCallingIdentity();
6984 try {
6985 Phone phone = getPhone(subId);
6986 if (phone != null) {
6987 return phone.getImsRegistrationTech();
6988 } else {
6989 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6990 }
6991 } finally {
6992 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006993 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006994 }
6995
Stuart Scott8eef64f2015-04-08 15:13:54 -07006996 @Override
6997 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006998 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006999 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7000 return;
7001 }
7002
Svet Ganovcc087f82015-05-12 20:35:54 -07007003 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007004
Svet Ganovcc087f82015-05-12 20:35:54 -07007005 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007006 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7007 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007008 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007009 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007010 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007011 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007012 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7013 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007014 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007015 // There has been issues when Sms raw table somehow stores orphan
7016 // fragments. They lead to garbled message when new fragments come
7017 // in and combined with those stale ones. In case this happens again,
7018 // user can reset all network settings which will clean up this table.
7019 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007020 // Clean up IMS settings as well here.
7021 int slotId = getSlotIndex(subId);
7022 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7023 ImsManager.getInstance(mApp, slotId).factoryReset();
7024 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007025
7026 // Erase modem config if erase modem on network setting is enabled.
7027 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7028 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7029 if (configValue != null && Boolean.parseBoolean(configValue)) {
7030 sendEraseModemConfig(getDefaultPhone());
7031 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007032 } finally {
7033 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007034 }
7035 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007036
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007037 private void cleanUpSmsRawTable(Context context) {
7038 ContentResolver resolver = context.getContentResolver();
7039 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7040 resolver.delete(uri, null, null);
7041 }
7042
Narayan Kamath1c496c22015-04-16 14:40:19 +01007043 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007044 public String getSimLocaleForSubscriber(int subId) {
7045 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7046 final Phone phone = getPhone(subId);
7047 if (phone == null) {
7048 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007049 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007050 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 final long identity = Binder.clearCallingIdentity();
7052 try {
chen xu5d3637b2019-01-21 23:31:38 -08007053 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007054 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007055 if (info == null) {
7056 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7057 return null;
7058 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007059 // Try and fetch the locale from the carrier properties or from the SIM language
7060 // preferences (EF-PL and EF-LI)...
7061 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007062 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007063 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7064 if (localeFromDefaultSim != null) {
7065 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7066 if (DBG) log("Using locale from subId: " + subId + " locale: "
7067 + localeFromDefaultSim);
7068 return localeFromDefaultSim.toLanguageTag();
7069 } else {
7070 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007071 }
7072 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007073
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007074 // The SIM language preferences only store a language (e.g. fr = French), not an
7075 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7076 // the SIM and carrier preferences does not include a country we add the country
7077 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007078 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007080 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007081 return mccLocale.toLanguageTag();
7082 }
7083
7084 if (DBG) log("No locale found - returning null");
7085 return null;
7086 } finally {
7087 Binder.restoreCallingIdentity(identity);
7088 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007089 }
7090
7091 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007092 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007093 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007094 }
7095
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007096 /**
7097 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7098 */
7099 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007100 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007101 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007102 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007103
Chenjie Yu1ba97252018-01-11 18:16:20 -08007104 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007105 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007106
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007107 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007108 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7109 * representing the state of the modem.
7110 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007111 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7112 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007113 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007114 */
7115 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007116 public void requestModemActivityInfo(ResultReceiver result) {
7117 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007118 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007119
7120 final long identity = Binder.clearCallingIdentity();
7121 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007122 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007123 } finally {
7124 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007125 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007126 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007127
Siddharth Rayb8114062018-06-17 15:02:38 -07007128 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7129 // less than total activity duration.
7130 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7131 if (info == null) {
7132 return false;
7133 }
7134 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007135 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7136 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7137
Siddharth Rayb8114062018-06-17 15:02:38 -07007138 return (info.isValid()
7139 && (info.getSleepTimeMillis() <= activityDurationMs)
7140 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007141 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007142 && (totalTxTimeMs <= activityDurationMs));
7143 }
7144
Jack Yu85bd38a2015-11-09 11:34:32 -08007145 /**
7146 * {@hide}
7147 * Returns the service state information on specified subscription.
7148 */
7149 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007150 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7151 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007152 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007153 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007154 return null;
7155 }
7156
Hall Liuf19c44f2018-11-27 14:38:17 -08007157 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7158 LocationAccessPolicy.checkLocationPermission(mApp,
7159 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7160 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007161 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007162 .setCallingPid(Binder.getCallingPid())
7163 .setCallingUid(Binder.getCallingUid())
7164 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007165 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007166 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007167 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7168 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007169 .build());
7170
7171 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7172 LocationAccessPolicy.checkLocationPermission(mApp,
7173 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7174 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007175 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007176 .setCallingPid(Binder.getCallingPid())
7177 .setCallingUid(Binder.getCallingUid())
7178 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007179 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007180 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007181 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7182 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007183 .build());
7184 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7185 boolean hasFinePermission =
7186 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7187 boolean hasCoarsePermission =
7188 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7189
Jack Yu479f40e2020-10-27 21:29:25 -07007190 final Phone phone = getPhone(subId);
7191 if (phone == null) {
7192 return null;
7193 }
7194
7195 boolean isCallingPackageDataService = phone.getDataServicePackages()
7196 .contains(callingPackage);
7197
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007198 final long identity = Binder.clearCallingIdentity();
7199 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007200 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7201 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7202 Rlog.d(LOG_TAG,
7203 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7204 return null;
7205 }
7206
Hall Liuf19c44f2018-11-27 14:38:17 -08007207 ServiceState ss = phone.getServiceState();
7208
7209 // Scrub out the location info in ServiceState depending on what level of access
7210 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007211 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007212 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7213 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007214 } finally {
7215 Binder.restoreCallingIdentity(identity);
7216 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007217 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007218
7219 /**
7220 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7221 *
7222 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7223 * voicemail ringtone.
7224 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7225 * PhoneAccount.
7226 */
7227 @Override
7228 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007229 final long identity = Binder.clearCallingIdentity();
7230 try {
7231 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7232 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007233 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007234 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007236 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7237 } finally {
7238 Binder.restoreCallingIdentity(identity);
7239 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007240 }
7241
7242 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007243 * Sets the per-account voicemail ringtone.
7244 *
7245 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7246 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7247 *
7248 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7249 * voicemail ringtone.
7250 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7251 * PhoneAccount.
7252 */
7253 @Override
7254 public void setVoicemailRingtoneUri(String callingPackage,
7255 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007256 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007257 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007258 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7259 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7261 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7262 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007263 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007264
7265 final long identity = Binder.clearCallingIdentity();
7266 try {
7267 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7268 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007269 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007270 }
7271 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7272 } finally {
7273 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007274 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007275 }
7276
7277 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007278 * Returns whether vibration is set for voicemail notification in Phone settings.
7279 *
7280 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7281 * voicemail vibration setting.
7282 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7283 */
7284 @Override
7285 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007286 final long identity = Binder.clearCallingIdentity();
7287 try {
7288 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7289 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007290 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007291 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007293 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7294 } finally {
7295 Binder.restoreCallingIdentity(identity);
7296 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007297 }
7298
Youhan Wange64578a2016-05-02 15:32:42 -07007299 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007300 * Sets the per-account voicemail vibration.
7301 *
7302 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7303 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7304 *
7305 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7306 * voicemail vibration setting.
7307 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7308 * specific PhoneAccount.
7309 */
7310 @Override
7311 public void setVoicemailVibrationEnabled(String callingPackage,
7312 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007313 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007314 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007315 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7316 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7318 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7319 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007320 }
7321
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007322 final long identity = Binder.clearCallingIdentity();
7323 try {
7324 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7325 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007326 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327 }
7328 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7329 } finally {
7330 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007331 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007332 }
7333
7334 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007335 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7336 *
7337 * @throws SecurityException if the caller does not have the required permission
7338 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007339 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007340 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007341 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007342 }
7343
7344 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007345 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7346 * permission.
7347 *
7348 * @throws SecurityException if the caller does not have the required permission
7349 */
7350 private void enforceSendSmsPermission() {
7351 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7352 }
7353
7354 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007355 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007356 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007357 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007358 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007359 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007360 final long identity = Binder.clearCallingIdentity();
7361 try {
7362 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007363 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007364 if (componentName == null) {
7365 throw new SecurityException(
7366 "Caller not current active visual voicemail package[null]");
7367 }
7368 String vvmPackage = componentName.getPackageName();
7369 if (!callingPackage.equals(vvmPackage)) {
7370 throw new SecurityException("Caller not current active visual voicemail package["
7371 + vvmPackage + "]");
7372 }
7373 } finally {
7374 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007375 }
7376 }
7377
7378 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007379 * Return the application ID for the app type.
7380 *
7381 * @param subId the subscription ID that this request applies to.
7382 * @param appType the uicc app type.
7383 * @return Application ID for specificied app type, or null if no uicc.
7384 */
7385 @Override
7386 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007387 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007388 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389
7390 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007391 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007392 if (phone == null) {
7393 return null;
7394 }
7395 String aid = null;
7396 try {
7397 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7398 .getApplicationByType(appType).getAid();
7399 } catch (Exception e) {
7400 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7401 }
7402 return aid;
7403 } finally {
7404 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007405 }
Youhan Wange64578a2016-05-02 15:32:42 -07007406 }
7407
Youhan Wang4001d252016-05-11 10:29:41 -07007408 /**
7409 * Return the Electronic Serial Number.
7410 *
7411 * @param subId the subscription ID that this request applies to.
7412 * @return ESN or null if error.
7413 */
7414 @Override
7415 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007416 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007417 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007418
7419 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007420 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007421 if (phone == null) {
7422 return null;
7423 }
7424 String esn = null;
7425 try {
7426 esn = phone.getEsn();
7427 } catch (Exception e) {
7428 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7429 }
7430 return esn;
7431 } finally {
7432 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007433 }
Youhan Wang4001d252016-05-11 10:29:41 -07007434 }
7435
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007436 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007437 * Return the Preferred Roaming List Version.
7438 *
7439 * @param subId the subscription ID that this request applies to.
7440 * @return PRLVersion or null if error.
7441 */
7442 @Override
7443 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007444 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007445 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446
7447 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007448 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007449 if (phone == null) {
7450 return null;
7451 }
7452 String cdmaPrlVersion = null;
7453 try {
7454 cdmaPrlVersion = phone.getCdmaPrlVersion();
7455 } catch (Exception e) {
7456 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7457 }
7458 return cdmaPrlVersion;
7459 } finally {
7460 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007461 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007462 }
7463
7464 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007465 * Get snapshot of Telephony histograms
7466 * @return List of Telephony histograms
7467 * @hide
7468 */
7469 @Override
7470 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7472 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007473
7474 final long identity = Binder.clearCallingIdentity();
7475 try {
7476 return RIL.getTelephonyRILTimingHistograms();
7477 } finally {
7478 Binder.restoreCallingIdentity(identity);
7479 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007480 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007481
7482 /**
7483 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007484 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7485 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007486 * Require system privileges. In the future we may add this to carrier APIs.
7487 *
Michele Berionne482f8202018-11-27 18:57:59 -08007488 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007489 */
7490 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007491 @TelephonyManager.SetCarrierRestrictionResult
7492 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007493 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007494 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007495
Michele Berionne482f8202018-11-27 18:57:59 -08007496 if (carrierRestrictionRules == null) {
7497 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007498 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500 final long identity = Binder.clearCallingIdentity();
7501 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007502 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007503 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504 } finally {
7505 Binder.restoreCallingIdentity(identity);
7506 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007507 }
7508
7509 /**
7510 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007511 * Get the allowed carrier list and the excluded carrier list, including the priority between
7512 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007513 * Require system privileges. In the future we may add this to carrier APIs.
7514 *
Michele Berionne482f8202018-11-27 18:57:59 -08007515 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007516 */
7517 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007518 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007519 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007520 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521
7522 final long identity = Binder.clearCallingIdentity();
7523 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007524 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7525 if (response instanceof CarrierRestrictionRules) {
7526 return (CarrierRestrictionRules) response;
7527 }
7528 // Response is an Exception of some kind,
7529 // which is signalled to the user as a NULL retval
7530 return null;
7531 } catch (Exception e) {
7532 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7533 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 } finally {
7535 Binder.restoreCallingIdentity(identity);
7536 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007537 }
7538
fionaxu59545b42016-05-25 15:53:37 -07007539 /**
fionaxu59545b42016-05-25 15:53:37 -07007540 * Action set from carrier signalling broadcast receivers to enable/disable radio
7541 * @param subId the subscription ID that this action applies to.
7542 * @param enabled control enable or disable radio.
7543 * {@hide}
7544 */
7545 @Override
7546 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7547 enforceModifyPermission();
7548 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007549
7550 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007551 if (phone == null) {
7552 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7553 return;
7554 }
7555 try {
7556 phone.carrierActionSetRadioEnabled(enabled);
7557 } catch (Exception e) {
7558 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007559 } finally {
7560 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007561 }
7562 }
7563
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007564 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007565 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7566 * network status based on which carrier apps could apply actions accordingly,
7567 * enable/disable default url handler for example.
7568 *
7569 * @param subId the subscription ID that this action applies to.
7570 * @param report control start/stop reporting the default network status.
7571 * {@hide}
7572 */
7573 @Override
7574 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7575 enforceModifyPermission();
7576 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007577
7578 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007579 if (phone == null) {
7580 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7581 return;
7582 }
7583 try {
7584 phone.carrierActionReportDefaultNetworkStatus(report);
7585 } catch (Exception e) {
7586 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007587 } finally {
7588 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007589 }
7590 }
7591
7592 /**
fionaxud9622282017-07-17 17:51:30 -07007593 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7594 * @param subId the subscription ID that this action applies to.
7595 * {@hide}
7596 */
7597 @Override
7598 public void carrierActionResetAll(int subId) {
7599 enforceModifyPermission();
7600 final Phone phone = getPhone(subId);
7601 if (phone == null) {
7602 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7603 return;
7604 }
7605 try {
7606 phone.carrierActionResetAll();
7607 } catch (Exception e) {
7608 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7609 }
7610 }
7611
7612 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007613 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7614 * bug report is being generated.
7615 */
7616 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007617 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007618 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7619 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007620 writer.println("Permission Denial: can't dump Phone from pid="
7621 + Binder.getCallingPid()
7622 + ", uid=" + Binder.getCallingUid()
7623 + "without permission "
7624 + android.Manifest.permission.DUMP);
7625 return;
7626 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007627 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007628 }
Jack Yueb89b242016-06-22 13:27:47 -07007629
Brad Ebingerdac2f002018-04-03 15:17:52 -07007630 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007631 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7632 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7633 @NonNull String[] args) {
7634 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7635 this, in.getFileDescriptor(), out.getFileDescriptor(),
7636 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007637 }
7638
Jack Yueb89b242016-06-22 13:27:47 -07007639 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007640 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007641 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007642 * @param reason the reason the data enable change is taking place
7643 * @param enabled True if enabling the data, otherwise disabling.
7644 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007645 */
7646 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007647 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007648 boolean enabled) {
7649 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7650 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7651 try {
7652 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007653 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007654 } catch (SecurityException se) {
7655 enforceModifyPermission();
7656 }
7657 } else {
7658 enforceModifyPermission();
7659 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007660
7661 final long identity = Binder.clearCallingIdentity();
7662 try {
7663 Phone phone = getPhone(subId);
7664 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007665 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7666 phone.carrierActionSetMeteredApnsEnabled(enabled);
7667 } else {
7668 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7669 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007670 }
7671 } finally {
7672 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007673 }
7674 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007675
7676 /**
7677 * Get Client request stats
7678 * @return List of Client Request Stats
7679 * @hide
7680 */
7681 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007682 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7683 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007684 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007685 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007686 return null;
7687 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007688 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007689
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690 final long identity = Binder.clearCallingIdentity();
7691 try {
7692 if (phone != null) {
7693 return phone.getClientRequestStats();
7694 }
7695
7696 return null;
7697 } finally {
7698 Binder.restoreCallingIdentity(identity);
7699 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007700 }
7701
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007702 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007703 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007704 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007705 }
Jack Yueb4124c2017-02-16 15:32:43 -08007706
7707 /**
Grace Chen70990072017-03-24 17:21:30 -07007708 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007709 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007710 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007711 * @param state State of SIM (power down, power up, pass through)
7712 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7713 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7714 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007715 *
7716 **/
7717 @Override
Grace Chen70990072017-03-24 17:21:30 -07007718 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007719 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007720 Phone phone = PhoneFactory.getPhone(slotIndex);
7721
vagdeviaf9a5b92018-08-15 16:01:53 -07007722 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7723
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007724 final long identity = Binder.clearCallingIdentity();
7725 try {
7726 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007727 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007728 }
7729 } finally {
7730 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007731 }
7732 }
Shuo Qiandd210312017-04-12 22:11:33 +00007733
Tyler Gunn65d45c22017-06-05 11:22:26 -07007734 private boolean isUssdApiAllowed(int subId) {
7735 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007736 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007737 if (configManager == null) {
7738 return false;
7739 }
7740 PersistableBundle pb = configManager.getConfigForSubId(subId);
7741 if (pb == null) {
7742 return false;
7743 }
7744 return pb.getBoolean(
7745 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7746 }
7747
Shuo Qiandd210312017-04-12 22:11:33 +00007748 /**
7749 * Check if phone is in emergency callback mode
7750 * @return true if phone is in emergency callback mode
7751 * @param subId sub id
7752 */
goneil9c5f4872017-12-05 14:07:56 -08007753 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007754 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007755 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007756 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007757
7758 final long identity = Binder.clearCallingIdentity();
7759 try {
7760 if (phone != null) {
7761 return phone.isInEcm();
7762 } else {
7763 return false;
7764 }
7765 } finally {
7766 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007767 }
7768 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007769
7770 /**
7771 * Get the current signal strength information for the given subscription.
7772 * Because this information is not updated when the device is in a low power state
7773 * it should not be relied-upon to be current.
7774 * @param subId Subscription index
7775 * @return the most recent cached signal strength info from the modem
7776 */
7777 @Override
7778 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007779 final long identity = Binder.clearCallingIdentity();
7780 try {
7781 Phone p = getPhone(subId);
7782 if (p == null) {
7783 return null;
7784 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007786 return p.getSignalStrength();
7787 } finally {
7788 Binder.restoreCallingIdentity(identity);
7789 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007790 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007791
Pengquan Meng77b7f132018-08-22 14:49:57 -07007792 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007793 * Get the current modem radio state for the given slot.
7794 * @param slotIndex slot index.
7795 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007796 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007797 * @return the current radio power state from the modem
7798 */
7799 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007800 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007801 Phone phone = PhoneFactory.getPhone(slotIndex);
7802 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7804 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007805 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7806 }
7807
7808 final long identity = Binder.clearCallingIdentity();
7809 try {
7810 return phone.getRadioPowerState();
7811 } finally {
7812 Binder.restoreCallingIdentity(identity);
7813 }
7814 }
7815 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7816 }
7817
7818 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007819 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7820 *
7821 * <p>Requires one of the following permissions:
7822 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7823 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7824 * privileges.
7825 *
7826 * @param subId subscription id
7827 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7828 * {@code false}.
7829 */
7830 @Override
7831 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07007832 try {
7833 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7834 null);
7835 } catch (Exception e) {
7836 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7837 mApp, subId, "isDataRoamingEnabled");
7838 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007839
Pengquan Menga1bb6272018-09-06 09:59:22 -07007840 boolean isEnabled = false;
7841 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007842 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007843 Phone phone = getPhone(subId);
7844 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007845 } finally {
7846 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007847 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007848 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007849 }
7850
7851
7852 /**
7853 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7854 *
7855 * <p> Requires permission:
7856 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7857 * privileges.
7858 *
7859 * @param subId subscription id
7860 * @param isEnabled {@code true} means enable, {@code false} means disable.
7861 */
7862 @Override
7863 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7865 mApp, subId, "setDataRoamingEnabled");
7866
Pengquan Menga1bb6272018-09-06 09:59:22 -07007867 final long identity = Binder.clearCallingIdentity();
7868 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007869 Phone phone = getPhone(subId);
7870 if (phone != null) {
7871 phone.setDataRoamingEnabled(isEnabled);
7872 }
7873 } finally {
7874 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007875 }
7876 }
7877
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007878 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007879 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007880 TelephonyPermissions
7881 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007882 mApp, subId, "isManualNetworkSelectionAllowed");
7883
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007884 boolean isAllowed = true;
7885 final long identity = Binder.clearCallingIdentity();
7886 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007887 Phone phone = getPhone(subId);
7888 if (phone != null) {
7889 isAllowed = phone.isCspPlmnEnabled();
7890 }
7891 } finally {
7892 Binder.restoreCallingIdentity(identity);
7893 }
7894 return isAllowed;
7895 }
7896
7897 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007898 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007899 // Verify that tha callingPackage belongs to the calling UID
7900 mApp.getSystemService(AppOpsManager.class)
7901 .checkPackage(Binder.getCallingUid(), callingPackage);
7902
Jordan Liu1e142fc2019-04-22 15:10:43 -07007903 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007904 try {
7905 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007906 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007907 } catch (SecurityException e) {
7908 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7909 // has carrier privileges on an active UICC
7910 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7911 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007912 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007913 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007914 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007915
7916 final long identity = Binder.clearCallingIdentity();
7917 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007918 UiccController uiccController = UiccController.getInstance();
7919 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007920 if (hasReadPermission) {
7921 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007922 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007923
7924 // Remove private info if the caller doesn't have access
7925 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7926 for (UiccCardInfo cardInfo : cardInfos) {
7927 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7928 // is available
7929 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7930 if (card == null || card.getUiccProfile() == null) {
7931 // assume no access if the card or profile is unavailable
7932 filteredInfos.add(cardInfo.getUnprivileged());
7933 continue;
7934 }
7935 UiccProfile profile = card.getUiccProfile();
7936 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7937 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7938 filteredInfos.add(cardInfo);
7939 } else {
7940 filteredInfos.add(cardInfo.getUnprivileged());
7941 }
7942 }
7943 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007944 } finally {
7945 Binder.restoreCallingIdentity(identity);
7946 }
7947 }
7948
7949 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007950 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007951 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007952
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007953 final long identity = Binder.clearCallingIdentity();
7954 try {
7955 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7956 if (slots == null) {
7957 Rlog.i(LOG_TAG, "slots is null.");
7958 return null;
7959 }
7960
7961 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7962 for (int i = 0; i < slots.length; i++) {
7963 UiccSlot slot = slots[i];
7964 if (slot == null) {
7965 continue;
7966 }
7967
Jordan Liu7be7e652019-05-06 18:55:02 +00007968 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007969 UiccCard card = slot.getUiccCard();
7970 if (card != null) {
7971 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007972 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007973 cardId = slot.getEid();
7974 if (TextUtils.isEmpty(cardId)) {
7975 cardId = slot.getIccId();
7976 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007977 }
7978
Jordan Liu857451f2019-05-09 16:35:35 -07007979 if (cardId != null) {
7980 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7981 // if cardId is an EID, it's all digits so this is fine
7982 cardId = IccUtils.stripTrailingFs(cardId);
7983 }
7984
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007985 int cardState = 0;
7986 switch (slot.getCardState()) {
7987 case CARDSTATE_ABSENT:
7988 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7989 break;
7990 case CARDSTATE_PRESENT:
7991 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7992 break;
7993 case CARDSTATE_ERROR:
7994 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7995 break;
7996 case CARDSTATE_RESTRICTED:
7997 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7998 break;
7999 default:
8000 break;
8001
8002 }
8003
8004 infos[i] = new UiccSlotInfo(
8005 slot.isActive(),
8006 slot.isEuicc(),
8007 cardId,
8008 cardState,
8009 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008010 slot.isExtendedApduSupported(),
8011 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008012 }
8013 return infos;
8014 } finally {
8015 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008016 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008017 }
8018
8019 @Override
8020 public boolean switchSlots(int[] physicalSlots) {
8021 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008022
8023 final long identity = Binder.clearCallingIdentity();
8024 try {
8025 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8026 } finally {
8027 Binder.restoreCallingIdentity(identity);
8028 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008029 }
Jack Yu4c988042018-02-27 15:30:01 -08008030
8031 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008032 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008033 final long identity = Binder.clearCallingIdentity();
8034 try {
8035 return UiccController.getInstance().getCardIdForDefaultEuicc();
8036 } finally {
8037 Binder.restoreCallingIdentity(identity);
8038 }
8039 }
8040
Pengquan Meng85728fb2018-03-12 16:31:21 -07008041 /**
goneil47ffb6e2018-04-06 15:40:58 -07008042 * A test API to reload the UICC profile.
8043 *
8044 * <p>Requires that the calling app has permission
8045 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8046 * @hide
8047 */
8048 @Override
8049 public void refreshUiccProfile(int subId) {
8050 enforceModifyPermission();
8051
8052 final long identity = Binder.clearCallingIdentity();
8053 try {
8054 Phone phone = getPhone(subId);
8055 if (phone == null) {
8056 return;
8057 }
8058 UiccCard uiccCard = phone.getUiccCard();
8059 if (uiccCard == null) {
8060 return;
8061 }
8062 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8063 if (uiccProfile == null) {
8064 return;
8065 }
8066 uiccProfile.refresh();
8067 } finally {
8068 Binder.restoreCallingIdentity(identity);
8069 }
8070 }
8071
8072 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008073 * Returns false if the mobile data is disabled by default, otherwise return true.
8074 */
8075 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008076 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008077 }
8078
8079 /**
8080 * Returns true if the data roaming is enabled by default, i.e the system property
8081 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8082 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8083 */
8084 private boolean getDefaultDataRoamingEnabled(int subId) {
8085 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008086 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008087 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008088 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8089 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8090 return isDataRoamingEnabled;
8091 }
8092
8093 /**
8094 * Returns the default network type for the given {@code subId}, if the default network type is
8095 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8096 */
8097 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008098 List<Integer> list = TelephonyProperties.default_network();
8099 int phoneId = mSubscriptionController.getPhoneId(subId);
8100 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8101 return list.get(phoneId);
8102 }
8103 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008104 }
fionaxua13278b2018-03-21 00:08:13 -07008105
8106 @Override
8107 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008108 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008109 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008110
8111 final long identity = Binder.clearCallingIdentity();
8112 try {
8113 final Phone phone = getPhone(subId);
8114 if (phone == null) {
8115 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8116 return;
8117 }
chen xueaba88a2019-03-15 13:15:10 -07008118 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8119 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008120 if (carrierPrivilegeRules == null) {
8121 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8122 } else {
8123 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8124 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008125 } finally {
8126 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008127 }
fionaxua13278b2018-03-21 00:08:13 -07008128 }
8129
8130 @Override
8131 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008132 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008133
8134 final long identity = Binder.clearCallingIdentity();
8135 try {
8136 final Phone phone = getPhone(subId);
8137 if (phone == null) {
8138 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8139 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8140 }
8141 return phone.getCarrierIdListVersion();
8142 } finally {
8143 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008144 }
fionaxua13278b2018-03-21 00:08:13 -07008145 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008146
8147 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008148 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8149 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008150 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008151 mApp, subId, callingPackage, callingFeatureId,
8152 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008153 return -1;
8154 }
8155
8156 final long identity = Binder.clearCallingIdentity();
8157 try {
8158 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8159 } finally {
8160 Binder.restoreCallingIdentity(identity);
8161 }
8162 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008163
8164 @Override
8165 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008166 TelephonyPermissions
8167 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008168 mApp, subId, "getCdmaRoamingMode");
8169
8170 final long identity = Binder.clearCallingIdentity();
8171 try {
8172 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8173 } finally {
8174 Binder.restoreCallingIdentity(identity);
8175 }
8176 }
8177
8178 @Override
8179 public boolean setCdmaRoamingMode(int subId, int mode) {
8180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8181 mApp, subId, "setCdmaRoamingMode");
8182
8183 final long identity = Binder.clearCallingIdentity();
8184 try {
8185 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8186 } finally {
8187 Binder.restoreCallingIdentity(identity);
8188 }
8189 }
8190
8191 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008192 public int getCdmaSubscriptionMode(int subId) {
8193 TelephonyPermissions
8194 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8195 mApp, subId, "getCdmaSubscriptionMode");
8196
8197 final long identity = Binder.clearCallingIdentity();
8198 try {
8199 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8200 } finally {
8201 Binder.restoreCallingIdentity(identity);
8202 }
8203 }
8204
8205 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008206 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8208 mApp, subId, "setCdmaSubscriptionMode");
8209
8210 final long identity = Binder.clearCallingIdentity();
8211 try {
8212 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8213 } finally {
8214 Binder.restoreCallingIdentity(identity);
8215 }
8216 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008217
sqianc5eccab2018-10-19 18:46:41 -07008218 @Override
sqian8c685422019-02-22 15:55:18 -08008219 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008220 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008221 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008222 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8223 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008224 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8225 }
8226 final long identity = Binder.clearCallingIdentity();
8227 try {
sqian854d44b2018-12-12 16:48:18 -08008228 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8229 for (Phone phone: PhoneFactory.getPhones()) {
8230 if (phone.getEmergencyNumberTracker() != null
8231 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8232 emergencyNumberListInternal.put(
8233 phone.getSubId(),
8234 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8235 }
sqian11b7a0e2018-12-05 18:48:28 -08008236 }
sqian854d44b2018-12-12 16:48:18 -08008237 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008238 } finally {
8239 Binder.restoreCallingIdentity(identity);
8240 }
sqianc5eccab2018-10-19 18:46:41 -07008241 }
8242
8243 @Override
sqian8c685422019-02-22 15:55:18 -08008244 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008245 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008246 if (!exactMatch) {
8247 TelephonyPermissions
8248 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008249 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008250 }
8251 final long identity = Binder.clearCallingIdentity();
8252 try {
sqian854d44b2018-12-12 16:48:18 -08008253 for (Phone phone: PhoneFactory.getPhones()) {
8254 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008255 && phone.getEmergencyNumberTracker()
8256 .isEmergencyNumber(number, exactMatch)) {
8257 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008258 }
sqian11b7a0e2018-12-05 18:48:28 -08008259 }
8260 return false;
8261 } finally {
8262 Binder.restoreCallingIdentity(identity);
8263 }
8264 }
8265
sqianf4ca7ed2019-01-15 18:32:07 -08008266 /**
8267 * Update emergency number list for test mode.
8268 */
8269 @Override
8270 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8271 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8272 "updateEmergencyNumberListTestMode");
8273
8274 final long identity = Binder.clearCallingIdentity();
8275 try {
8276 for (Phone phone: PhoneFactory.getPhones()) {
8277 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8278 if (tracker != null) {
8279 tracker.executeEmergencyNumberTestModeCommand(action, num);
8280 }
8281 }
8282 } finally {
8283 Binder.restoreCallingIdentity(identity);
8284 }
8285 }
8286
8287 /**
8288 * Get the full emergency number list for test mode.
8289 */
8290 @Override
8291 public List<String> getEmergencyNumberListTestMode() {
8292 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8293 "getEmergencyNumberListTestMode");
8294
8295 final long identity = Binder.clearCallingIdentity();
8296 try {
8297 Set<String> emergencyNumbers = new HashSet<>();
8298 for (Phone phone: PhoneFactory.getPhones()) {
8299 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8300 if (tracker != null) {
8301 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8302 emergencyNumbers.add(num.getNumber());
8303 }
8304 }
8305 }
8306 return new ArrayList<>(emergencyNumbers);
8307 } finally {
8308 Binder.restoreCallingIdentity(identity);
8309 }
8310 }
8311
chen xud6b45bd2018-10-30 22:27:10 -07008312 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008313 public int getEmergencyNumberDbVersion(int subId) {
8314 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8315
8316 final long identity = Binder.clearCallingIdentity();
8317 try {
8318 final Phone phone = getPhone(subId);
8319 if (phone == null) {
8320 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8321 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8322 }
8323 return phone.getEmergencyNumberDbVersion();
8324 } finally {
8325 Binder.restoreCallingIdentity(identity);
8326 }
8327 }
8328
8329 @Override
8330 public void notifyOtaEmergencyNumberDbInstalled() {
8331 enforceModifyPermission();
8332
8333 final long identity = Binder.clearCallingIdentity();
8334 try {
8335 for (Phone phone: PhoneFactory.getPhones()) {
8336 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8337 if (tracker != null) {
8338 tracker.updateOtaEmergencyNumberDatabase();
8339 }
8340 }
8341 } finally {
8342 Binder.restoreCallingIdentity(identity);
8343 }
8344 }
8345
8346 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008347 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008348 enforceActiveEmergencySessionPermission();
8349
8350 final long identity = Binder.clearCallingIdentity();
8351 try {
8352 for (Phone phone: PhoneFactory.getPhones()) {
8353 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8354 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008355 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8356 }
8357 }
8358 } finally {
8359 Binder.restoreCallingIdentity(identity);
8360 }
8361 }
8362
8363 @Override
8364 public void resetOtaEmergencyNumberDbFilePath() {
8365 enforceActiveEmergencySessionPermission();
8366
8367 final long identity = Binder.clearCallingIdentity();
8368 try {
8369 for (Phone phone: PhoneFactory.getPhones()) {
8370 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8371 if (tracker != null) {
8372 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008373 }
8374 }
8375 } finally {
8376 Binder.restoreCallingIdentity(identity);
8377 }
8378 }
8379
8380 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008381 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8382 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8383 Phone phone = getPhone(subId);
8384 if (phone == null) {
8385 return null;
8386 }
8387 final long identity = Binder.clearCallingIdentity();
8388 try {
8389 UiccProfile profile = UiccController.getInstance()
8390 .getUiccProfileForPhone(phone.getPhoneId());
8391 if (profile != null) {
8392 return profile.getCertsFromCarrierPrivilegeAccessRules();
8393 }
8394 } finally {
8395 Binder.restoreCallingIdentity(identity);
8396 }
8397 return null;
8398 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008399
8400 /**
8401 * Enable or disable a modem stack.
8402 */
8403 @Override
8404 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8405 enforceModifyPermission();
8406
8407 final long identity = Binder.clearCallingIdentity();
8408 try {
8409 Phone phone = PhoneFactory.getPhone(slotIndex);
8410 if (phone == null) {
8411 return false;
8412 } else {
8413 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8414 }
8415 } finally {
8416 Binder.restoreCallingIdentity(identity);
8417 }
8418 }
Michelecea4cf22018-12-21 15:00:11 -08008419
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008420 /**
8421 * Whether a modem stack is enabled or not.
8422 */
8423 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008424 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8425 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008426 Phone phone = PhoneFactory.getPhone(slotIndex);
8427 if (phone == null) return false;
8428
8429 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008430 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8431 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008432 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8433 }
8434
8435 final long identity = Binder.clearCallingIdentity();
8436 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008437 try {
8438 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8439 } catch (NoSuchElementException ex) {
8440 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8441 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008442 } finally {
8443 Binder.restoreCallingIdentity(identity);
8444 }
8445 }
8446
Michelecea4cf22018-12-21 15:00:11 -08008447 @Override
Michele0ea7d782019-03-19 14:58:42 -07008448 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008449 enforceModifyPermission();
8450
8451 final long identity = Binder.clearCallingIdentity();
8452 try {
8453 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008454 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008455 .commit();
8456 } finally {
8457 Binder.restoreCallingIdentity(identity);
8458 }
8459 }
8460
8461 @Override
Michele0ea7d782019-03-19 14:58:42 -07008462 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008463 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008464 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008465 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8466 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008467 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008468 }
Michelecea4cf22018-12-21 15:00:11 -08008469
8470 final long identity = Binder.clearCallingIdentity();
8471 try {
Michele0ea7d782019-03-19 14:58:42 -07008472 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008473 } finally {
8474 Binder.restoreCallingIdentity(identity);
8475 }
8476 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008477
Michele0ea7d782019-03-19 14:58:42 -07008478 @TelephonyManager.IsMultiSimSupportedResult
8479 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008480 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8481 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8482 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008483 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8484 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008485 }
8486 // Check if the hardware supports multisim functionality. If usage of multisim is not
8487 // supported by the modem, indicate that it is restricted.
8488 PhoneCapability staticCapability =
8489 mPhoneConfigurationManager.getStaticPhoneCapability();
8490 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008491 loge("isMultiSimSupportedInternal: no static configuration available");
8492 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008493 }
Sarah Chin7caee492020-02-18 20:49:02 +00008494 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008495 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8496 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008497 }
8498 // Check if support of multiple SIMs is restricted by carrier
8499 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008500 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008501 }
8502
Michele0ea7d782019-03-19 14:58:42 -07008503 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008504 }
8505
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008506 /**
8507 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008508 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8509 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8510 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008511 * @param numOfSims number of active sims we want to switch to
8512 */
8513 @Override
8514 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008515 if (numOfSims == 1) {
8516 enforceModifyPermission();
8517 } else {
8518 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8519 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8520 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008521 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008522
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008523 try {
Michele30b57b22019-03-01 12:01:14 -08008524 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008525 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008526 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8527 return;
8528 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008529 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8530 } finally {
8531 Binder.restoreCallingIdentity(identity);
8532 }
8533 }
8534
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008535 @Override
8536 public boolean isApplicationOnUicc(int subId, int appType) {
8537 enforceReadPrivilegedPermission("isApplicationOnUicc");
8538 Phone phone = getPhone(subId);
8539 if (phone == null) {
8540 return false;
8541 }
8542 final long identity = Binder.clearCallingIdentity();
8543 try {
8544 UiccCard uiccCard = phone.getUiccCard();
8545 if (uiccCard == null) {
8546 return false;
8547 }
8548 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8549 if (uiccProfile == null) {
8550 return false;
8551 }
8552 if (TelephonyManager.APPTYPE_SIM <= appType
8553 && appType <= TelephonyManager.APPTYPE_ISIM) {
8554 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8555 }
8556 return false;
8557 } finally {
8558 Binder.restoreCallingIdentity(identity);
8559 }
8560 }
8561
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008562 /**
chen xub4baa772019-04-03 10:23:41 -07008563 * Get whether making changes to modem configurations will trigger reboot.
8564 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008565 */
8566 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008567 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8568 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008569 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008570 mApp, subId, callingPackage, callingFeatureId,
8571 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008572 return false;
8573 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008574 final long identity = Binder.clearCallingIdentity();
8575 try {
8576 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8577 } finally {
8578 Binder.restoreCallingIdentity(identity);
8579 }
8580 }
8581
Nathan Harold29f5f052019-02-15 13:41:57 -08008582 private void updateModemStateMetrics() {
8583 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8584 // TODO: check the state for each modem if the api is ready.
8585 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8586 }
8587
Pengquan Meng3889a572019-01-23 11:16:29 -08008588 @Override
8589 public int[] getSlotsMapping() {
8590 enforceReadPrivilegedPermission("getSlotsMapping");
8591
8592 final long identity = Binder.clearCallingIdentity();
8593 try {
8594 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8595 // All logical slots should have a mapping to a physical slot.
8596 int[] logicalSlotsMapping = new int[phoneCount];
8597 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8598 for (int i = 0; i < slotInfos.length; i++) {
8599 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8600 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8601 }
8602 }
8603 return logicalSlotsMapping;
8604 } finally {
8605 Binder.restoreCallingIdentity(identity);
8606 }
8607 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008608
8609 /**
8610 * Get the IRadio HAL Version
8611 */
8612 @Override
8613 public int getRadioHalVersion() {
8614 Phone phone = getDefaultPhone();
8615 if (phone == null) return -1;
8616 HalVersion hv = phone.getHalVersion();
8617 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8618 return hv.major * 100 + hv.minor;
8619 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008620
8621 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008622 * Get the current calling package name.
8623 * @return the current calling package name
8624 */
8625 @Override
8626 public String getCurrentPackageName() {
8627 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8628 }
8629
8630 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008631 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8632 * corresponding network requests on a subId.
8633 *
8634 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008635 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008636 * 2) APN is un-metered for this subscription, or
8637 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07008638 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008639 *
8640 * @return whether data is allowed for a apn type.
8641 *
8642 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008643 */
8644 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008645 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008646 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8647 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008648
8649 // Now that all security checks passes, perform the operation as ourselves.
8650 final long identity = Binder.clearCallingIdentity();
8651 try {
8652 Phone phone = getPhone(subId);
8653 if (phone == null) return false;
8654
Jack Yu41407ee2019-05-13 16:54:09 -07008655 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008656 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8657 } finally {
8658 Binder.restoreCallingIdentity(identity);
8659 }
8660 }
8661
8662 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008663 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008664 enforceReadPrivilegedPermission("isApnMetered");
8665
8666 // Now that all security checks passes, perform the operation as ourselves.
8667 final long identity = Binder.clearCallingIdentity();
8668 try {
8669 Phone phone = getPhone(subId);
8670 if (phone == null) return true; // By default return true.
8671
Jack Yu41407ee2019-05-13 16:54:09 -07008672 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008673 } finally {
8674 Binder.restoreCallingIdentity(identity);
8675 }
8676 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008677
8678 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008679 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8680 int subscriptionId, IBooleanConsumer resultCallback) {
8681 enforceModifyPermission();
8682 long token = Binder.clearCallingIdentity();
8683 try {
8684 Phone phone = getPhone(subscriptionId);
8685 if (phone == null) {
8686 try {
8687 if (resultCallback != null) {
8688 resultCallback.accept(false);
8689 }
8690 } catch (RemoteException e) {
8691 // ignore
8692 }
8693 return;
8694 }
8695 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8696 Pair.create(specifiers, (x) -> {
8697 try {
8698 if (resultCallback != null) {
8699 resultCallback.accept(x);
8700 }
8701 } catch (RemoteException e) {
8702 // ignore
8703 }
8704 });
8705 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8706 } finally {
8707 Binder.restoreCallingIdentity(token);
8708 }
8709 }
8710
8711 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008712 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008713 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008714 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8715 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8716 if (iccRecords == null) {
8717 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8718 return false;
8719 }
8720 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8721 }
8722
8723 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008724 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8725 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008726 if (callingPackage == null) {
8727 callingPackage = getCurrentPackageName();
8728 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008729 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8730 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008731 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8732 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008733 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8734 }
8735 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8736 Intent intent = new Intent();
8737 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8738 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8739 // Bring up choose default SMS subscription dialog right now
8740 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8741 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8742 mApp.startActivity(intent);
8743 }
chen xud5ca2d52019-05-28 15:20:57 -07008744
8745 @Override
8746 public String getMmsUAProfUrl(int subId) {
8747 //TODO investigate if this API should require proper permission check in R b/133791609
8748 final long identity = Binder.clearCallingIdentity();
8749 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008750 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8751 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8752 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8753 return carrierUAProfUrl;
8754 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008755 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8756 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008757 } finally {
8758 Binder.restoreCallingIdentity(identity);
8759 }
8760 }
8761
8762 @Override
8763 public String getMmsUserAgent(int subId) {
8764 //TODO investigate if this API should require proper permission check in R b/133791609
8765 final long identity = Binder.clearCallingIdentity();
8766 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008767 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8768 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8769 if (!TextUtils.isEmpty(carrierUserAgent)) {
8770 return carrierUserAgent;
8771 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008772 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8773 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008774 } finally {
8775 Binder.restoreCallingIdentity(identity);
8776 }
8777 }
Jack Yub07d4972019-05-28 16:12:25 -07008778
8779 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008780 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8781 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07008782
Jack Yub07d4972019-05-28 16:12:25 -07008783 final long identity = Binder.clearCallingIdentity();
8784 try {
Hall Liua62f5da2020-09-25 10:42:19 -07008785 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07008786 if (phone == null) return false;
8787
Hall Liua62f5da2020-09-25 10:42:19 -07008788 switch (policy) {
8789 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8790 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8791 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8792 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8793 default:
8794 throw new IllegalArgumentException(policy + " is not a valid policy");
8795 }
Jack Yub07d4972019-05-28 16:12:25 -07008796 } finally {
8797 Binder.restoreCallingIdentity(identity);
8798 }
8799 }
8800
8801 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008802 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8803 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08008804 enforceModifyPermission();
8805
changbettyd5c246e2019-12-24 15:40:37 +08008806 final long identity = Binder.clearCallingIdentity();
8807 try {
Hall Liua62f5da2020-09-25 10:42:19 -07008808 Phone phone = getPhone(subscriptionId);
8809 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08008810
Hall Liua62f5da2020-09-25 10:42:19 -07008811 switch (policy) {
8812 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8813 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8814 break;
8815 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8816 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
8817 break;
8818 default:
8819 throw new IllegalArgumentException(policy + " is not a valid policy");
8820 }
changbettyd5c246e2019-12-24 15:40:37 +08008821 } finally {
8822 Binder.restoreCallingIdentity(identity);
8823 }
8824 }
8825
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008826 /**
Hall Liu746e03c2020-09-25 11:13:49 -07008827 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008828 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8829 * otherwise.
8830 */
8831 @Override
8832 public void setCepEnabled(boolean isCepEnabled) {
8833 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8834
8835 final long identity = Binder.clearCallingIdentity();
8836 try {
8837 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8838 for (Phone phone : PhoneFactory.getPhones()) {
8839 Phone defaultPhone = phone.getImsPhone();
8840 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8841 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8842 ImsPhoneCallTracker imsPhoneCallTracker =
8843 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8844 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8845 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8846 + imsPhone.getMsisdn());
8847 }
8848 }
8849 } finally {
8850 Binder.restoreCallingIdentity(identity);
8851 }
8852 }
allenwtsu46dcc572020-01-08 18:24:03 +08008853
8854 /**
8855 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8856 *
8857 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8858 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8859 * before being read.
8860 */
8861 @Override
8862 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8863 isCompressed) {
8864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8865 mApp, subId, "notifyRcsAutoConfigurationReceived");
8866 try {
8867 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8868 if (configBinder == null) {
8869 Rlog.e(LOG_TAG, "null result for getImsConfig");
8870 } else {
8871 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8872 }
8873 } catch (RemoteException e) {
8874 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8875 }
8876 }
zoey chene02881a2019-12-30 16:11:23 +08008877
8878 @Override
8879 public boolean isIccLockEnabled(int subId) {
8880 enforceReadPrivilegedPermission("isIccLockEnabled");
8881
8882 // Now that all security checks passes, perform the operation as ourselves.
8883 final long identity = Binder.clearCallingIdentity();
8884 try {
8885 Phone phone = getPhone(subId);
8886 if (phone != null && phone.getIccCard() != null) {
8887 return phone.getIccCard().getIccLockEnabled();
8888 } else {
8889 return false;
8890 }
8891 } finally {
8892 Binder.restoreCallingIdentity(identity);
8893 }
8894 }
8895
8896 /**
8897 * Set the ICC pin lock enabled or disabled.
8898 *
8899 * @return an integer representing the status of IccLock enabled or disabled in the following
8900 * three cases:
8901 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8902 * successfully.
8903 * - Positive number and zero for remaining password attempts.
8904 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8905 *
8906 */
8907 @Override
8908 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8909 enforceModifyPermission();
8910
8911 Phone phone = getPhone(subId);
8912 if (phone == null) {
8913 return 0;
8914 }
8915 // Now that all security checks passes, perform the operation as ourselves.
8916 final long identity = Binder.clearCallingIdentity();
8917 try {
8918 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8919 new Pair<Boolean, String>(enabled, password), phone, null);
8920 return attemptsRemaining;
8921
8922 } catch (Exception e) {
8923 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8924 } finally {
8925 Binder.restoreCallingIdentity(identity);
8926 }
8927 return 0;
8928 }
8929
8930 /**
8931 * Change the ICC password used in ICC pin lock.
8932 *
8933 * @return an integer representing the status of IccLock changed in the following three cases:
8934 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8935 * - Positive number and zero for remaining password attempts.
8936 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8937 *
8938 */
8939 @Override
8940 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8941 enforceModifyPermission();
8942
8943 Phone phone = getPhone(subId);
8944 if (phone == null) {
8945 return 0;
8946 }
8947 // Now that all security checks passes, perform the operation as ourselves.
8948 final long identity = Binder.clearCallingIdentity();
8949 try {
8950 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8951 new Pair<String, String>(oldPassword, newPassword), phone, null);
8952 return attemptsRemaining;
8953
8954 } catch (Exception e) {
8955 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8956 } finally {
8957 Binder.restoreCallingIdentity(identity);
8958 }
8959 return 0;
8960 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008961
8962 /**
8963 * Request for receiving user activity notification
8964 */
8965 @Override
8966 public void requestUserActivityNotification() {
8967 if (!mNotifyUserActivity.get()
8968 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8969 mNotifyUserActivity.set(true);
8970 }
8971 }
8972
8973 /**
8974 * Called when userActivity is signalled in the power manager.
8975 * This is safe to call from any thread, with any window manager locks held or not.
8976 */
8977 @Override
8978 public void userActivity() {
8979 // ***************************************
8980 // * Inherited from PhoneWindowManager *
8981 // ***************************************
8982 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8983 // WITH ITS LOCKS HELD.
8984 //
8985 // This code must be VERY careful about the locks
8986 // it acquires.
8987 // In fact, the current code acquires way too many,
8988 // and probably has lurking deadlocks.
8989
8990 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8991 throw new SecurityException("Only the OS may call notifyUserActivity()");
8992 }
8993
8994 if (mNotifyUserActivity.getAndSet(false)) {
8995 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8996 USER_ACTIVITY_NOTIFICATION_DELAY);
8997 }
8998 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008999
9000 @Override
9001 public boolean canConnectTo5GInDsdsMode() {
9002 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9003 }
Jack Yud10cdd42020-09-28 20:28:01 -07009004
9005 @Override
9006 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9007 String callingFeatureId) {
9008 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9009 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9010 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9011 }
9012
9013 Phone phone = getPhone(subId);
9014 if (phone == null) {
9015 throw new RuntimeException("phone is not available");
9016 }
9017 // Now that all security checks passes, perform the operation as ourselves.
9018 final long identity = Binder.clearCallingIdentity();
9019 try {
9020 return phone.getEquivalentHomePlmns();
9021 } finally {
9022 Binder.restoreCallingIdentity(identity);
9023 }
9024 }
Daniel Bright59e67312020-11-13 11:49:37 -08009025
9026 @Override
9027 public boolean isRadioInterfaceCapabilitySupported(
9028 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9029 RadioInterfaceCapabilities radioInterfaceCapabilities =
9030 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9031 if (radioInterfaceCapabilities == null) {
9032 throw new RuntimeException("radio interface capabilities are not available");
9033 } else {
9034 return radioInterfaceCapabilities.isSupported(capability);
9035 }
9036 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009037}