blob: 8bf31c11d7ad75a9bd78f50e79160debdec72eaa [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;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import 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;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700135import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800136import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800138import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700139import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700140import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700141import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700143import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800144import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700145import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700146import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700147import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700148import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700149import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700150import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700151import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700152import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800153import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800154import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800155import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700156import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800157import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700158import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800159import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700160import com.android.internal.telephony.imsphone.ImsPhone;
161import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800162import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700163import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800165import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700166import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800167import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700168import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800169import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700170import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800171import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000172import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800173import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700174import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800175import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700176import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700177import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800178import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700179import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700180import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800181import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800182
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700183import java.io.FileDescriptor;
184import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800187import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800189import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100190import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800191import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700192import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800193import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800194import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800195import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197/**
198 * Implementation of the ITelephony interface.
199 */
Santos Cordon117fee72014-05-16 17:56:12 -0700200public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201 private static final String LOG_TAG = "PhoneInterfaceManager";
202 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
203 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800204 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205
206 // Message codes used with mMainThreadHandler
207 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700208 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
209 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700210 private static final int CMD_OPEN_CHANNEL = 9;
211 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
212 private static final int CMD_CLOSE_CHANNEL = 11;
213 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800214 private static final int CMD_NV_READ_ITEM = 13;
215 private static final int EVENT_NV_READ_ITEM_DONE = 14;
216 private static final int CMD_NV_WRITE_ITEM = 15;
217 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
218 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
219 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700220 private static final int CMD_RESET_MODEM_CONFIG = 19;
221 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800222 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
223 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
224 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
225 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800226 private static final int CMD_SEND_ENVELOPE = 25;
227 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000228 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
229 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700230 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
231 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
232 private static final int CMD_EXCHANGE_SIM_IO = 31;
233 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800234 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
235 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700236 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
237 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700238 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
239 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700240 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
241 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
242 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
243 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700244 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
245 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
246 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
247 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700248 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800249 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
250 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000251 private static final int CMD_SWITCH_SLOTS = 50;
252 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700253 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
254 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
255 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
256 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
257 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
258 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
259 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
260 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700261 private static final int CMD_GET_ALL_CELL_INFO = 60;
262 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
263 private static final int CMD_GET_CELL_LOCATION = 62;
264 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700265 private static final int CMD_MODEM_REBOOT = 64;
266 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700267 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
268 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800269 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
270 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700271 private static final int CMD_GET_MODEM_STATUS = 70;
272 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700273 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
274 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700275 private static final int CMD_ERASE_MODEM_CONFIG = 74;
276 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800277 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
278 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
279 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
280 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800281 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
282 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800283 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800284 private static final int CMD_GET_CALL_FORWARDING = 83;
285 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
286 private static final int CMD_SET_CALL_FORWARDING = 85;
287 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
288 private static final int CMD_GET_CALL_WAITING = 87;
289 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
290 private static final int CMD_SET_CALL_WAITING = 89;
291 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800293 // Parameters of select command.
294 private static final int SELECT_COMMAND = 0xA4;
295 private static final int SELECT_P1 = 0x04;
296 private static final int SELECT_P2 = 0;
297 private static final int SELECT_P3 = 0x10;
298
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299 /** The singleton instance. */
300 private static PhoneInterfaceManager sInstance;
301
Wink Saville3ab207e2014-11-20 13:07:20 -0800302 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800303 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800304 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700305 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800306 private AppOpsManager mAppOps;
307 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800308 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800309 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700310 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311
Peter Wangdafb9ac2020-01-15 14:13:38 -0800312 /** User Activity */
313 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800314 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
315
Derek Tan97ebb422014-09-05 16:55:38 -0700316 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
317 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800318 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800319 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700320
Michelecea4cf22018-12-21 15:00:11 -0800321 // String to store multi SIM allowed
322 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
323
Derek Tan740e1672017-06-27 14:56:27 -0700324 // The AID of ISD-R.
325 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
326
yinxub1bed742017-04-17 11:45:04 -0700327 private NetworkScanRequestTracker mNetworkScanRequestTracker;
328
David Kelly5e06a7f2018-03-12 14:10:59 +0000329 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
330 private static final int MANUFACTURER_CODE_LENGTH = 8;
331
Derek Tan89e89d42014-07-08 17:00:10 -0700332 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700333 * Experiment flag to enable erase modem config on reset network, default value is false
334 */
335 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
336 "reset_network_erase_modem_config_enabled";
337
338 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700339 * A request object to use for transmitting data to an ICC.
340 */
341 private static final class IccAPDUArgument {
342 public int channel, cla, command, p1, p2, p3;
343 public String data;
344
345 public IccAPDUArgument(int channel, int cla, int command,
346 int p1, int p2, int p3, String data) {
347 this.channel = channel;
348 this.cla = cla;
349 this.command = command;
350 this.p1 = p1;
351 this.p2 = p2;
352 this.p3 = p3;
353 this.data = data;
354 }
355 }
356
357 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700358 * A request object to use for transmitting data to an ICC.
359 */
360 private static final class ManualNetworkSelectionArgument {
361 public OperatorInfo operatorInfo;
362 public boolean persistSelection;
363
364 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
365 this.operatorInfo = operatorInfo;
366 this.persistSelection = persistSelection;
367 }
368 }
369
370 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
372 * request after sending. The main thread will notify the request when it is complete.
373 */
374 private static final class MainThreadRequest {
375 /** The argument to use for the request */
376 public Object argument;
377 /** The result of the request that is run on the main thread */
378 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800379 // The subscriber id that this request applies to. Defaults to
380 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
381 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382
Nathan Harold92bed182018-10-12 18:16:49 -0700383 // In cases where subId is unavailable, the caller needs to specify the phone.
384 public Phone phone;
385
vagdeviaf9a5b92018-08-15 16:01:53 -0700386 public WorkSource workSource;
387
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 public MainThreadRequest(Object argument) {
389 this.argument = argument;
390 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800391
Nathan Harold92bed182018-10-12 18:16:49 -0700392 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
393 this.argument = argument;
394 if (phone != null) {
395 this.phone = phone;
396 }
397 this.workSource = workSource;
398 }
399
vagdeviaf9a5b92018-08-15 16:01:53 -0700400 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800401 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800402 if (subId != null) {
403 this.subId = subId;
404 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700405 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407 }
408
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800409 private static final class IncomingThirdPartyCallArgs {
410 public final ComponentName component;
411 public final String callId;
412 public final String callerDisplayName;
413
414 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
415 String callerDisplayName) {
416 this.component = component;
417 this.callId = callId;
418 this.callerDisplayName = callerDisplayName;
419 }
420 }
421
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422 /**
423 * A handler that processes messages on the main thread in the phone process. Since many
424 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
425 * inbound binder threads to the main thread in the phone process. The Binder thread
426 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
427 * on, which will be notified when the operation completes and will contain the result of the
428 * request.
429 *
430 * <p>If a MainThreadRequest object is provided in the msg.obj field,
431 * note that request.result must be set to something non-null for the calling thread to
432 * unblock.
433 */
434 private final class MainThreadHandler extends Handler {
435 @Override
436 public void handleMessage(Message msg) {
437 MainThreadRequest request;
438 Message onCompleted;
439 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800440 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700441 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800442 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443
444 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700445 case CMD_HANDLE_USSD_REQUEST: {
446 request = (MainThreadRequest) msg.obj;
447 final Phone phone = getPhoneFromRequest(request);
448 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
449 String ussdRequest = ussdObject.first;
450 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700451
Pengquan Menga1bb6272018-09-06 09:59:22 -0700452 if (!isUssdApiAllowed(request.subId)) {
453 // Carrier does not support use of this API, return failure.
454 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
455 UssdResponse response = new UssdResponse(ussdRequest, null);
456 Bundle returnData = new Bundle();
457 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
458 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700459
Pengquan Menga1bb6272018-09-06 09:59:22 -0700460 request.result = true;
461 notifyRequester(request);
462 return;
463 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700464
Pengquan Menga1bb6272018-09-06 09:59:22 -0700465 try {
466 request.result = phone != null
467 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
468 } catch (CallStateException cse) {
469 request.result = false;
470 }
471 // Wake up the requesting thread
472 notifyRequester(request);
473 break;
pkanwar32d516d2016-10-14 19:37:38 -0700474 }
475
Yorke Lee716f67e2015-06-17 15:39:16 -0700476 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700478 final Phone phone = getPhoneFromRequest(request);
479 request.result = phone != null ?
480 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
481 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700482 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700483 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800490 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700491 if (uiccCard == null) {
492 loge("iccTransmitApduLogicalChannel: No UICC");
493 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700494 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700495 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
497 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700498 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 iccArgument.channel, iccArgument.cla, iccArgument.command,
500 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700501 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700502 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 break;
504
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700505 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700506 ar = (AsyncResult) msg.obj;
507 request = (MainThreadRequest) ar.userObj;
508 if (ar.exception == null && ar.result != null) {
509 request.result = ar.result;
510 } else {
511 request.result = new IccIoResult(0x6F, 0, (byte[])null);
512 if (ar.result == null) {
513 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800514 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700515 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800516 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700517 } else {
518 loge("iccTransmitApduLogicalChannel: Unknown exception");
519 }
520 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700521 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700522 break;
523
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
525 request = (MainThreadRequest) msg.obj;
526 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800527 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 if (uiccCard == null) {
529 loge("iccTransmitApduBasicChannel: No UICC");
530 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 } else {
533 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
534 request);
535 uiccCard.iccTransmitApduBasicChannel(
536 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
537 iccArgument.p3, iccArgument.data, onCompleted);
538 }
539 break;
540
541 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
542 ar = (AsyncResult) msg.obj;
543 request = (MainThreadRequest) ar.userObj;
544 if (ar.exception == null && ar.result != null) {
545 request.result = ar.result;
546 } else {
547 request.result = new IccIoResult(0x6F, 0, (byte[])null);
548 if (ar.result == null) {
549 loge("iccTransmitApduBasicChannel: Empty response");
550 } else if (ar.exception instanceof CommandException) {
551 loge("iccTransmitApduBasicChannel: CommandException: " +
552 ar.exception);
553 } else {
554 loge("iccTransmitApduBasicChannel: Unknown exception");
555 }
556 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 break;
559
560 case CMD_EXCHANGE_SIM_IO:
561 request = (MainThreadRequest) msg.obj;
562 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800563 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 if (uiccCard == null) {
565 loge("iccExchangeSimIO: No UICC");
566 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700567 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 } else {
569 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
570 request);
571 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
572 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
573 iccArgument.data, onCompleted);
574 }
575 break;
576
577 case EVENT_EXCHANGE_SIM_IO_DONE:
578 ar = (AsyncResult) msg.obj;
579 request = (MainThreadRequest) ar.userObj;
580 if (ar.exception == null && ar.result != null) {
581 request.result = ar.result;
582 } else {
583 request.result = new IccIoResult(0x6f, 0, (byte[])null);
584 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 break;
587
Derek Tan4d5e5c12014-02-04 11:54:58 -0800588 case CMD_SEND_ENVELOPE:
589 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800590 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 if (uiccCard == null) {
592 loge("sendEnvelopeWithStatus: No UICC");
593 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 } else {
596 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
597 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
598 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800599 break;
600
601 case EVENT_SEND_ENVELOPE_DONE:
602 ar = (AsyncResult) msg.obj;
603 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700604 if (ar.exception == null && ar.result != null) {
605 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800606 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700607 request.result = new IccIoResult(0x6F, 0, (byte[])null);
608 if (ar.result == null) {
609 loge("sendEnvelopeWithStatus: Empty response");
610 } else if (ar.exception instanceof CommandException) {
611 loge("sendEnvelopeWithStatus: CommandException: " +
612 ar.exception);
613 } else {
614 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
615 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800616 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800618 break;
619
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 case CMD_OPEN_CHANNEL:
621 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800622 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800623 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700624 if (uiccCard == null) {
625 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800626 request.result = new IccOpenLogicalChannelResponse(-1,
627 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700629 } else {
630 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800631 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
632 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700633 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 break;
635
636 case EVENT_OPEN_CHANNEL_DONE:
637 ar = (AsyncResult) msg.obj;
638 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 int[] result = (int[]) ar.result;
642 int channelId = result[0];
643 byte[] selectResponse = null;
644 if (result.length > 1) {
645 selectResponse = new byte[result.length - 1];
646 for (int i = 1; i < result.length; ++i) {
647 selectResponse[i - 1] = (byte) result[i];
648 }
649 }
650 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700651 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 if (ar.result == null) {
654 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700656 if (ar.exception != null) {
657 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
658 }
659
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700660 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700661 if (ar.exception instanceof CommandException) {
662 CommandException.Error error =
663 ((CommandException) (ar.exception)).getCommandError();
664 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700665 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700666 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700667 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 }
669 }
670 openChannelResp = new IccOpenLogicalChannelResponse(
671 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700673 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700674 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 break;
676
677 case CMD_CLOSE_CHANNEL:
678 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800679 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700680 if (uiccCard == null) {
681 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900682 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700684 } else {
685 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
686 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
687 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 break;
689
690 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800691 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
692 break;
693
694 case CMD_NV_READ_ITEM:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800697 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
698 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800699 break;
700
701 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 ar = (AsyncResult) msg.obj;
703 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800704 if (ar.exception == null && ar.result != null) {
705 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800707 request.result = "";
708 if (ar.result == null) {
709 loge("nvReadItem: Empty response");
710 } else if (ar.exception instanceof CommandException) {
711 loge("nvReadItem: CommandException: " +
712 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800714 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 }
716 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700717 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700718 break;
719
Jake Hambye994d462014-02-03 13:10:13 -0800720 case CMD_NV_WRITE_ITEM:
721 request = (MainThreadRequest) msg.obj;
722 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
723 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800724 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700725 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800726 break;
727
728 case EVENT_NV_WRITE_ITEM_DONE:
729 handleNullReturnEvent(msg, "nvWriteItem");
730 break;
731
732 case CMD_NV_WRITE_CDMA_PRL:
733 request = (MainThreadRequest) msg.obj;
734 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800735 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800736 break;
737
738 case EVENT_NV_WRITE_CDMA_PRL_DONE:
739 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
740 break;
741
chen xu6dac5ab2018-10-26 17:39:23 -0700742 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800743 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700744 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800745 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800746 break;
747
chen xu6dac5ab2018-10-26 17:39:23 -0700748 case EVENT_RESET_MODEM_CONFIG_DONE:
749 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800750 break;
751
Jake Hamby7c27be32014-03-03 13:25:59 -0800752 case CMD_GET_PREFERRED_NETWORK_TYPE:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700755 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800756 break;
757
758 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
759 ar = (AsyncResult) msg.obj;
760 request = (MainThreadRequest) ar.userObj;
761 if (ar.exception == null && ar.result != null) {
762 request.result = ar.result; // Integer
763 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800764 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800765 if (ar.result == null) {
766 loge("getPreferredNetworkType: Empty response");
767 } else if (ar.exception instanceof CommandException) {
768 loge("getPreferredNetworkType: CommandException: " +
769 ar.exception);
770 } else {
771 loge("getPreferredNetworkType: Unknown exception");
772 }
773 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700774 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800775 break;
776
777 case CMD_SET_PREFERRED_NETWORK_TYPE:
778 request = (MainThreadRequest) msg.obj;
779 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
780 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700781 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800782 break;
783
784 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
785 handleNullReturnEvent(msg, "setPreferredNetworkType");
786 break;
787
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000788 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
789 request = (MainThreadRequest)msg.obj;
790 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800791 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000792 break;
793
794 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
795 ar = (AsyncResult)msg.obj;
796 request = (MainThreadRequest)ar.userObj;
797 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700798 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000799 break;
800
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800801 case CMD_SET_VOICEMAIL_NUMBER:
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
804 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800805 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
806 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800807 break;
808
809 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
810 handleNullReturnEvent(msg, "setVoicemailNumber");
811 break;
812
Stuart Scott54788802015-03-30 13:18:01 -0700813 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
814 request = (MainThreadRequest) msg.obj;
815 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
816 request);
817 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
818 break;
819
820 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
821 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
822 break;
823
Shishir Agrawal302c8692015-06-19 13:49:39 -0700824 case CMD_PERFORM_NETWORK_SCAN:
825 request = (MainThreadRequest) msg.obj;
826 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
827 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
828 break;
829
Shuo Qian4a594052020-01-23 11:59:30 -0800830 case CMD_GET_CALL_FORWARDING:
831 request = (MainThreadRequest) msg.obj;
832 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
833 int callForwardingReason = (Integer) request.argument;
834 getPhoneFromRequest(request).getCallForwardingOption(
835 callForwardingReason, onCompleted);
836 break;
837
838 case EVENT_GET_CALL_FORWARDING_DONE:
839 ar = (AsyncResult) msg.obj;
840 request = (MainThreadRequest) ar.userObj;
841 CallForwardingInfo callForwardingInfo = null;
842 if (ar.exception == null && ar.result != null) {
843 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
844 for (CallForwardInfo callForwardInfo : callForwardInfos) {
845 // Service Class is a bit mask per 3gpp 27.007. Search for
846 // any service for voice call.
847 if ((callForwardInfo.serviceClass
848 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
849 callForwardingInfo = new CallForwardingInfo(
850 callForwardInfo.serviceClass, callForwardInfo.reason,
851 callForwardInfo.number,
852 callForwardInfo.timeSeconds);
853 break;
854 }
855 }
856 // Didn't find a call forward info for voice call.
857 if (callForwardingInfo == null) {
858 callForwardingInfo = new CallForwardingInfo(
859 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
860 0 /* reason */, null /* number */, 0 /* timeout */);
861 }
862 } else {
863 if (ar.result == null) {
864 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
865 }
866 if (ar.exception != null) {
867 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
868 }
869 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
870 if (ar.exception instanceof CommandException) {
871 CommandException.Error error =
872 ((CommandException) (ar.exception)).getCommandError();
873 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
874 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
875 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
876 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
877 }
878 }
879 callForwardingInfo = new CallForwardingInfo(
880 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
881 }
882 request.result = callForwardingInfo;
883 notifyRequester(request);
884 break;
885
886 case CMD_SET_CALL_FORWARDING:
887 request = (MainThreadRequest) msg.obj;
888 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
889 CallForwardingInfo callForwardingInfoToSet =
890 (CallForwardingInfo) request.argument;
891 getPhoneFromRequest(request).setCallForwardingOption(
892 callForwardingInfoToSet.getStatus(),
893 callForwardingInfoToSet.getReason(),
894 callForwardingInfoToSet.getNumber(),
895 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
896 break;
897
898 case EVENT_SET_CALL_FORWARDING_DONE:
899 ar = (AsyncResult) msg.obj;
900 request = (MainThreadRequest) ar.userObj;
901 if (ar.exception == null) {
902 request.result = true;
903 } else {
904 request.result = false;
905 loge("setCallForwarding exception: " + ar.exception);
906 }
907 notifyRequester(request);
908 break;
909
910 case CMD_GET_CALL_WAITING:
911 request = (MainThreadRequest) msg.obj;
912 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
913 getPhoneFromRequest(request).getCallWaiting(onCompleted);
914 break;
915
916 case EVENT_GET_CALL_WAITING_DONE:
917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
919 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
920 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800921 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -0800922 // Service Class is a bit mask per 3gpp 27.007.
923 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800924 if (callForwardResults.length > 1
925 && ((callForwardResults[1]
926 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
927 callForwardingStatus = callForwardResults[0] == 0
Shuo Qian4a594052020-01-23 11:59:30 -0800928 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
929 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
930 } else {
931 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
932 }
933 } else {
934 if (ar.result == null) {
935 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
936 }
937 if (ar.exception != null) {
938 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
939 }
940 if (ar.exception instanceof CommandException) {
941 CommandException.Error error =
942 ((CommandException) (ar.exception)).getCommandError();
943 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
944 callForwardingStatus =
945 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
946 }
947 }
948 }
949 request.result = callForwardingStatus;
950 notifyRequester(request);
951 break;
952
953 case CMD_SET_CALL_WAITING:
954 request = (MainThreadRequest) msg.obj;
955 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
956 boolean isEnable = (Boolean) request.argument;
957 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
958 break;
959
960 case EVENT_SET_CALL_WAITING_DONE:
961 ar = (AsyncResult) msg.obj;
962 request = (MainThreadRequest) ar.userObj;
963 if (ar.exception == null) {
964 request.result = true;
965 } else {
966 request.result = false;
967 loge("setCallWaiting exception: " + ar.exception);
968 }
969 notifyRequester(request);
970 break;
971
Shishir Agrawal302c8692015-06-19 13:49:39 -0700972 case EVENT_PERFORM_NETWORK_SCAN_DONE:
973 ar = (AsyncResult) msg.obj;
974 request = (MainThreadRequest) ar.userObj;
975 CellNetworkScanResult cellScanResult;
976 if (ar.exception == null && ar.result != null) {
977 cellScanResult = new CellNetworkScanResult(
978 CellNetworkScanResult.STATUS_SUCCESS,
979 (List<OperatorInfo>) ar.result);
980 } else {
981 if (ar.result == null) {
982 loge("getCellNetworkScanResults: Empty response");
983 }
984 if (ar.exception != null) {
985 loge("getCellNetworkScanResults: Exception: " + ar.exception);
986 }
987 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
988 if (ar.exception instanceof CommandException) {
989 CommandException.Error error =
990 ((CommandException) (ar.exception)).getCommandError();
991 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
992 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
993 } else if (error == CommandException.Error.GENERIC_FAILURE) {
994 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
995 }
996 }
997 cellScanResult = new CellNetworkScanResult(errorCode, null);
998 }
999 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001000 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001001 break;
1002
1003 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1004 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001005 ManualNetworkSelectionArgument selArg =
1006 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001007 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1008 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001009 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1010 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001011 break;
1012
1013 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001014 ar = (AsyncResult) msg.obj;
1015 request = (MainThreadRequest) ar.userObj;
1016 if (ar.exception == null) {
1017 request.result = true;
1018 } else {
1019 request.result = false;
1020 loge("setNetworkSelectionModeManual " + ar.exception);
1021 }
1022 notifyRequester(request);
1023 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001024 break;
1025
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001026 case CMD_GET_MODEM_ACTIVITY_INFO:
1027 request = (MainThreadRequest) msg.obj;
1028 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001029 if (defaultPhone != null) {
1030 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian1d931ee2020-02-20 17:12:10 -08001031 } else {
1032 ResultReceiver result = (ResultReceiver) request.argument;
1033 Bundle bundle = new Bundle();
1034 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1035 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1036 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001037 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001038 break;
1039
1040 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
Shuo Qian1d931ee2020-02-20 17:12:10 -08001043 ResultReceiver result = (ResultReceiver) request.argument;
1044
1045 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001046 if (ar.exception == null && ar.result != null) {
Shuo Qian1d931ee2020-02-20 17:12:10 -08001047 // Update the last modem activity info and the result of the request.
1048 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1049 if (isModemActivityInfoValid(info)) {
1050 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1051 int[] txTimeMs = info.getTransmitTimeMillis();
1052 int[] lastModemTxTimeMs = mLastModemActivityInfo
1053 .getTransmitTimeMillis();
1054 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1055 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1056 }
1057 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1058 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1059 + mLastModemActivityInfo.getSleepTimeMillis());
1060 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1061 + mLastModemActivityInfo.getIdleTimeMillis());
1062 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1063 mLastModemActivityInfo.setReceiveTimeMillis(
1064 info.getReceiveTimeMillis()
1065 + mLastModemActivityInfo.getReceiveTimeMillis());
1066 }
1067 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1068 mLastModemActivityInfo.getSleepTimeMillis(),
1069 mLastModemActivityInfo.getIdleTimeMillis(),
1070 mLastModemActivityInfo.getTransmitTimeMillis(),
1071 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001072 } else {
1073 if (ar.result == null) {
1074 loge("queryModemActivityInfo: Empty response");
1075 } else if (ar.exception instanceof CommandException) {
1076 loge("queryModemActivityInfo: CommandException: " +
1077 ar.exception);
1078 } else {
1079 loge("queryModemActivityInfo: Unknown exception");
1080 }
1081 }
Shuo Qian1d931ee2020-02-20 17:12:10 -08001082 Bundle bundle = new Bundle();
1083 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1084 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001085 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001086 break;
1087
Meng Wang1a7c35a2016-05-05 20:56:15 -07001088 case CMD_SET_ALLOWED_CARRIERS:
1089 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001090 CarrierRestrictionRules argument =
1091 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001092 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001093 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001094 break;
1095
1096 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1097 ar = (AsyncResult) msg.obj;
1098 request = (MainThreadRequest) ar.userObj;
1099 if (ar.exception == null && ar.result != null) {
1100 request.result = ar.result;
1101 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001102 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1103 if (ar.exception instanceof CommandException) {
1104 loge("setAllowedCarriers: CommandException: " + ar.exception);
1105 CommandException.Error error =
1106 ((CommandException) (ar.exception)).getCommandError();
1107 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1108 request.result =
1109 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1110 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001111 } else {
1112 loge("setAllowedCarriers: Unknown exception");
1113 }
1114 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001115 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001116 break;
1117
1118 case CMD_GET_ALLOWED_CARRIERS:
1119 request = (MainThreadRequest) msg.obj;
1120 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001121 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001122 break;
1123
1124 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1125 ar = (AsyncResult) msg.obj;
1126 request = (MainThreadRequest) ar.userObj;
1127 if (ar.exception == null && ar.result != null) {
1128 request.result = ar.result;
1129 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001130 request.result = new IllegalStateException(
1131 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001132 if (ar.result == null) {
1133 loge("getAllowedCarriers: Empty response");
1134 } else if (ar.exception instanceof CommandException) {
1135 loge("getAllowedCarriers: CommandException: " +
1136 ar.exception);
1137 } else {
1138 loge("getAllowedCarriers: Unknown exception");
1139 }
1140 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001141 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001142 break;
1143
Nathan Haroldb3014052017-01-25 15:57:32 -08001144 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1145 ar = (AsyncResult) msg.obj;
1146 request = (MainThreadRequest) ar.userObj;
1147 if (ar.exception == null && ar.result != null) {
1148 request.result = ar.result;
1149 } else {
1150 request.result = new IllegalArgumentException(
1151 "Failed to retrieve Forbidden Plmns");
1152 if (ar.result == null) {
1153 loge("getForbiddenPlmns: Empty response");
1154 } else {
1155 loge("getForbiddenPlmns: Unknown exception");
1156 }
1157 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001158 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001159 break;
1160
1161 case CMD_GET_FORBIDDEN_PLMNS:
1162 request = (MainThreadRequest) msg.obj;
1163 uiccCard = getUiccCardFromRequest(request);
1164 if (uiccCard == null) {
1165 loge("getForbiddenPlmns() UiccCard is null");
1166 request.result = new IllegalArgumentException(
1167 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001168 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001169 break;
1170 }
1171 Integer appType = (Integer) request.argument;
1172 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1173 if (uiccApp == null) {
1174 loge("getForbiddenPlmns() no app with specified type -- "
1175 + appType);
1176 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001177 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001178 break;
1179 } else {
1180 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1181 + " specified type -- " + appType);
1182 }
1183 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1184 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1185 onCompleted);
1186 break;
1187
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001188 case CMD_SWITCH_SLOTS:
1189 request = (MainThreadRequest) msg.obj;
1190 int[] physicalSlots = (int[]) request.argument;
1191 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1192 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1193 break;
1194
1195 case EVENT_SWITCH_SLOTS_DONE:
1196 ar = (AsyncResult) msg.obj;
1197 request = (MainThreadRequest) ar.userObj;
1198 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001199 notifyRequester(request);
1200 break;
1201 case CMD_GET_NETWORK_SELECTION_MODE:
1202 request = (MainThreadRequest) msg.obj;
1203 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1204 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1205 break;
1206
1207 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1208 ar = (AsyncResult) msg.obj;
1209 request = (MainThreadRequest) ar.userObj;
1210 if (ar.exception != null) {
1211 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1212 } else {
1213 int mode = ((int[]) ar.result)[0];
1214 if (mode == 0) {
1215 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1216 } else {
1217 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1218 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001219 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001220 notifyRequester(request);
1221 break;
1222 case CMD_GET_CDMA_ROAMING_MODE:
1223 request = (MainThreadRequest) msg.obj;
1224 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1225 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1226 break;
1227 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1228 ar = (AsyncResult) msg.obj;
1229 request = (MainThreadRequest) ar.userObj;
1230 if (ar.exception != null) {
1231 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1232 } else {
1233 request.result = ((int[]) ar.result)[0];
1234 }
1235 notifyRequester(request);
1236 break;
1237 case CMD_SET_CDMA_ROAMING_MODE:
1238 request = (MainThreadRequest) msg.obj;
1239 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1240 int mode = (int) request.argument;
1241 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1242 break;
1243 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1244 ar = (AsyncResult) msg.obj;
1245 request = (MainThreadRequest) ar.userObj;
1246 request.result = ar.exception == null;
1247 notifyRequester(request);
1248 break;
1249 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1250 request = (MainThreadRequest) msg.obj;
1251 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1252 int subscriptionMode = (int) request.argument;
1253 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1254 break;
1255 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1256 ar = (AsyncResult) msg.obj;
1257 request = (MainThreadRequest) ar.userObj;
1258 request.result = ar.exception == null;
1259 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001260 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001261 case CMD_GET_ALL_CELL_INFO:
1262 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001263 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001264 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001265 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001266 case EVENT_GET_ALL_CELL_INFO_DONE:
1267 ar = (AsyncResult) msg.obj;
1268 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001269 // If a timeout occurs, the response will be null
1270 request.result = (ar.exception == null && ar.result != null)
1271 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001272 synchronized (request) {
1273 request.notifyAll();
1274 }
1275 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001276 case CMD_REQUEST_CELL_INFO_UPDATE:
1277 request = (MainThreadRequest) msg.obj;
1278 request.phone.requestCellInfoUpdate(request.workSource,
1279 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1280 break;
1281 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1282 ar = (AsyncResult) msg.obj;
1283 request = (MainThreadRequest) ar.userObj;
1284 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1285 try {
1286 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001287 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001288 cb.onError(
1289 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1290 ar.exception.getClass().getName(),
1291 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001292 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001293 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001294 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001295 } else {
1296 // use the result as returned
1297 cb.onCellInfo((List<CellInfo>) ar.result);
1298 }
1299 } catch (RemoteException re) {
1300 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1301 }
1302 break;
1303 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001304 request = (MainThreadRequest) msg.obj;
1305 WorkSource ws = (WorkSource) request.argument;
1306 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001307 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001308 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001309 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001310 ar = (AsyncResult) msg.obj;
1311 request = (MainThreadRequest) ar.userObj;
1312 if (ar.exception == null) {
1313 request.result = ar.result;
1314 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001315 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001316 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001317 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001318 }
1319
1320 synchronized (request) {
1321 request.notifyAll();
1322 }
1323 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001324 case CMD_MODEM_REBOOT:
1325 request = (MainThreadRequest) msg.obj;
1326 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001327 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001328 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001329 case EVENT_CMD_MODEM_REBOOT_DONE:
1330 handleNullReturnEvent(msg, "rebootModem");
1331 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001332 case CMD_REQUEST_ENABLE_MODEM:
1333 request = (MainThreadRequest) msg.obj;
1334 boolean enable = (boolean) request.argument;
1335 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001336 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001337 PhoneConfigurationManager.getInstance()
1338 .enablePhone(request.phone, enable, onCompleted);
1339 break;
1340 case EVENT_ENABLE_MODEM_DONE:
1341 ar = (AsyncResult) msg.obj;
1342 request = (MainThreadRequest) ar.userObj;
1343 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001344 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001345 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001346 if ((boolean) request.result) {
1347 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1348 updateModemStateMetrics();
1349 } else {
1350 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1351 + ar.exception);
1352 }
1353 notifyRequester(request);
1354 break;
1355 case CMD_GET_MODEM_STATUS:
1356 request = (MainThreadRequest) msg.obj;
1357 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1358 PhoneConfigurationManager.getInstance()
1359 .getPhoneStatusFromModem(request.phone, onCompleted);
1360 break;
1361 case EVENT_GET_MODEM_STATUS_DONE:
1362 ar = (AsyncResult) msg.obj;
1363 request = (MainThreadRequest) ar.userObj;
1364 int id = request.phone.getPhoneId();
1365 if (ar.exception == null && ar.result != null) {
1366 request.result = ar.result;
1367 //update the cache as modem status has changed
1368 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1369 (boolean) request.result);
1370 } else {
1371 // Return true if modem status cannot be retrieved. For most cases,
1372 // modem status is on. And for older version modems, GET_MODEM_STATUS
1373 // and disable modem are not supported. Modem is always on.
1374 // TODO: this should be fixed in R to support a third
1375 // status UNKNOWN b/131631629
1376 request.result = true;
1377 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1378 + ar.exception);
1379 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001380 notifyRequester(request);
1381 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001382 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1383 request = (MainThreadRequest) msg.obj;
1384 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1385 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1386 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1387 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1388 break;
1389 }
1390 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1391 ar = (AsyncResult) msg.obj;
1392 request = (MainThreadRequest) ar.userObj;
1393 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1394 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1395 args.second.accept(ar.exception == null);
1396 notifyRequester(request);
1397 break;
1398 }
yincheng zhao2737e882019-09-06 17:06:54 -07001399 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1400 ar = (AsyncResult) msg.obj;
1401 request = (MainThreadRequest) ar.userObj;
1402 if (ar.exception == null && ar.result != null) {
1403 request.result = ar.result;
1404 } else {
1405 request.result = -1;
1406 loge("Failed to set Forbidden Plmns");
1407 if (ar.result == null) {
1408 loge("setForbidenPlmns: Empty response");
1409 } else if (ar.exception != null) {
1410 loge("setForbiddenPlmns: Exception: " + ar.exception);
1411 request.result = -1;
1412 } else {
1413 loge("setForbiddenPlmns: Unknown exception");
1414 }
1415 }
1416 notifyRequester(request);
1417 break;
1418 case CMD_SET_FORBIDDEN_PLMNS:
1419 request = (MainThreadRequest) msg.obj;
1420 uiccCard = getUiccCardFromRequest(request);
1421 if (uiccCard == null) {
1422 loge("setForbiddenPlmns: UiccCard is null");
1423 request.result = -1;
1424 notifyRequester(request);
1425 break;
1426 }
1427 Pair<Integer, List<String>> setFplmnsArgs =
1428 (Pair<Integer, List<String>>) request.argument;
1429 appType = setFplmnsArgs.first;
1430 List<String> fplmns = setFplmnsArgs.second;
1431 uiccApp = uiccCard.getApplicationByType(appType);
1432 if (uiccApp == null) {
1433 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1434 request.result = -1;
1435 loge("Failed to get UICC App");
1436 notifyRequester(request);
1437 } else {
1438 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1439 ((SIMRecords) uiccApp.getIccRecords())
1440 .setForbiddenPlmns(onCompleted, fplmns);
1441 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001442 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001443 case CMD_ERASE_MODEM_CONFIG:
1444 request = (MainThreadRequest) msg.obj;
1445 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1446 defaultPhone.eraseModemConfig(onCompleted);
1447 break;
1448 case EVENT_ERASE_MODEM_CONFIG_DONE:
1449 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001450 break;
zoey chene02881a2019-12-30 16:11:23 +08001451
1452 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1453 request = (MainThreadRequest) msg.obj;
1454 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1455 Pair<String, String> changed = (Pair<String, String>) request.argument;
1456 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1457 changed.first, changed.second, onCompleted);
1458 break;
1459 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1460 ar = (AsyncResult) msg.obj;
1461 request = (MainThreadRequest) ar.userObj;
1462 if (ar.exception == null) {
1463 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1464 } else {
1465 request.result = msg.arg1;
1466 }
1467 notifyRequester(request);
1468 break;
1469
1470 case CMD_SET_ICC_LOCK_ENABLED:
1471 request = (MainThreadRequest) msg.obj;
1472 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1473 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1474 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1475 enabled.first, enabled.second, onCompleted);
1476 break;
1477 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1478 ar = (AsyncResult) msg.obj;
1479 request = (MainThreadRequest) ar.userObj;
1480 if (ar.exception == null) {
1481 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1482 } else {
1483 request.result = msg.arg1;
1484 }
1485 notifyRequester(request);
1486 break;
1487
Peter Wangdafb9ac2020-01-15 14:13:38 -08001488 case MSG_NOTIFY_USER_ACTIVITY:
1489 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001490 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001491 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1492 getDefaultPhone().getContext().sendBroadcastAsUser(
1493 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1494 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001495 default:
1496 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1497 break;
1498 }
1499 }
Jake Hambye994d462014-02-03 13:10:13 -08001500
Pengquan Menga1bb6272018-09-06 09:59:22 -07001501 private void notifyRequester(MainThreadRequest request) {
1502 synchronized (request) {
1503 request.notifyAll();
1504 }
1505 }
1506
Jake Hambye994d462014-02-03 13:10:13 -08001507 private void handleNullReturnEvent(Message msg, String command) {
1508 AsyncResult ar = (AsyncResult) msg.obj;
1509 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1510 if (ar.exception == null) {
1511 request.result = true;
1512 } else {
1513 request.result = false;
1514 if (ar.exception instanceof CommandException) {
1515 loge(command + ": CommandException: " + ar.exception);
1516 } else {
1517 loge(command + ": Unknown exception");
1518 }
1519 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001520 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001522 }
1523
1524 /**
1525 * Posts the specified command to be executed on the main thread,
1526 * waits for the request to complete, and returns the result.
1527 * @see #sendRequestAsync
1528 */
1529 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001530 return sendRequest(
1531 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001532 }
1533
1534 /**
1535 * Posts the specified command to be executed on the main thread,
1536 * waits for the request to complete, and returns the result.
1537 * @see #sendRequestAsync
1538 */
1539 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1540 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001541 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001542 }
1543
1544 /**
1545 * Posts the specified command to be executed on the main thread,
1546 * waits for the request to complete, and returns the result.
1547 * @see #sendRequestAsync
1548 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001549 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001550 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001551 }
1552
1553 /**
1554 * Posts the specified command to be executed on the main thread,
1555 * waits for the request to complete, and returns the result.
1556 * @see #sendRequestAsync
1557 */
Nathan Harold92bed182018-10-12 18:16:49 -07001558 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1559 return sendRequest(command, argument, subId, null, workSource);
1560 }
1561
1562 /**
1563 * Posts the specified command to be executed on the main thread,
1564 * waits for the request to complete, and returns the result.
1565 * @see #sendRequestAsync
1566 */
1567 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1568 return sendRequest(
1569 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1570 }
1571
1572 /**
1573 * Posts the specified command to be executed on the main thread,
1574 * waits for the request to complete, and returns the result.
1575 * @see #sendRequestAsync
1576 */
1577 private Object sendRequest(
1578 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001579 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1580 throw new RuntimeException("This method will deadlock if called from the main thread.");
1581 }
1582
Nathan Harold92bed182018-10-12 18:16:49 -07001583 MainThreadRequest request = null;
1584 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1585 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1586 } else if (phone != null) {
1587 request = new MainThreadRequest(argument, phone, workSource);
1588 } else {
1589 request = new MainThreadRequest(argument, subId, workSource);
1590 }
1591
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001592 Message msg = mMainThreadHandler.obtainMessage(command, request);
1593 msg.sendToTarget();
1594
1595 // Wait for the request to complete
1596 synchronized (request) {
1597 while (request.result == null) {
1598 try {
1599 request.wait();
1600 } catch (InterruptedException e) {
1601 // Do nothing, go back and wait until the request is complete
1602 }
1603 }
1604 }
1605 return request.result;
1606 }
1607
1608 /**
1609 * Asynchronous ("fire and forget") version of sendRequest():
1610 * Posts the specified command to be executed on the main thread, and
1611 * returns immediately.
1612 * @see #sendRequest
1613 */
1614 private void sendRequestAsync(int command) {
1615 mMainThreadHandler.sendEmptyMessage(command);
1616 }
1617
1618 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001619 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001620 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001621 */
1622 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001623 sendRequestAsync(command, argument, null, null);
1624 }
1625
1626 /**
1627 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1628 * @see {@link #sendRequest(int,Object)}
1629 */
1630 private void sendRequestAsync(
1631 int command, Object argument, Phone phone, WorkSource workSource) {
1632 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001633 Message msg = mMainThreadHandler.obtainMessage(command, request);
1634 msg.sendToTarget();
1635 }
1636
1637 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 * Initialize the singleton PhoneInterfaceManager instance.
1639 * This is only done once, at startup, from PhoneApp.onCreate().
1640 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001641 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 synchronized (PhoneInterfaceManager.class) {
1643 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001644 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 } else {
1646 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1647 }
1648 return sInstance;
1649 }
1650 }
1651
1652 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001653 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001656 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001657 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1659 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001660 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001661 mTelephonySharedPreferences =
1662 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001663 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001664 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001665 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001666
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001667 publish();
1668 }
1669
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001670 private Phone getDefaultPhone() {
1671 Phone thePhone = getPhone(getDefaultSubscription());
1672 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1673 }
1674
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675 private void publish() {
1676 if (DBG) log("publish: " + this);
1677
Peter Wangc035ce42020-01-08 21:00:22 -08001678 TelephonyFrameworkInitializer
1679 .getTelephonyServiceManager()
1680 .getTelephonyServiceRegisterer()
1681 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001682 }
1683
Stuart Scott584921c2015-01-15 17:10:34 -08001684 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001685 if (request.phone != null) {
1686 return request.phone;
1687 } else {
1688 return getPhoneFromSubId(request.subId);
1689 }
1690 }
1691
1692 private Phone getPhoneFromSubId(int subId) {
1693 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1694 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001695 }
1696
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001697 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1698 Phone phone = getPhoneFromRequest(request);
1699 return phone == null ? null :
1700 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1701 }
1702
Wink Saville36469e72014-06-11 15:17:00 -07001703 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001704 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001705 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707
Naina Nallurid63128d2019-09-17 14:10:30 -07001708 private void sendEraseModemConfig(Phone phone) {
1709 if (phone != null) {
1710 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1711 mApp, phone.getSubId(), "eraseModemConfig");
1712 final long identity = Binder.clearCallingIdentity();
1713 try {
1714 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1715 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1716 } finally {
1717 Binder.restoreCallingIdentity(identity);
1718 }
1719 }
1720 }
1721
Peter Wang44b186e2020-01-13 23:33:09 -08001722 private boolean isImsAvailableOnDevice() {
1723 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1724 if (pm == null) {
1725 // For some reason package manger is not available.. This will fail internally anyway,
1726 // so do not throw error and allow.
1727 return true;
1728 }
1729 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1730 }
1731
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001733 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001734 }
1735
Wink Savilleb564aae2014-10-23 10:18:09 -07001736 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 if (DBG) log("dial: " + number);
1738 // No permission check needed here: This is just a wrapper around the
1739 // ACTION_DIAL intent, which is available to any app since it puts up
1740 // the UI before it does anything.
1741
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001742 final long identity = Binder.clearCallingIdentity();
1743 try {
1744 String url = createTelUrl(number);
1745 if (url == null) {
1746 return;
1747 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001749 // PENDING: should we just silently fail if phone is offhook or ringing?
1750 PhoneConstants.State state = mCM.getState(subId);
1751 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1752 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1753 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1754 mApp.startActivity(intent);
1755 }
1756 } finally {
1757 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 }
1759 }
1760
1761 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001762 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001763 }
1764
Wink Savilleb564aae2014-10-23 10:18:09 -07001765 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001766 if (DBG) log("call: " + number);
1767
1768 // This is just a wrapper around the ACTION_CALL intent, but we still
1769 // need to do a permission check since we're calling startActivity()
1770 // from the context of the phone app.
1771 enforceCallPermission();
1772
Jordan Liu1617b712019-07-10 15:06:26 -07001773 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 != AppOpsManager.MODE_ALLOWED) {
1775 return;
1776 }
1777
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001778 final long identity = Binder.clearCallingIdentity();
1779 try {
1780 String url = createTelUrl(number);
1781 if (url == null) {
1782 return;
1783 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001785 boolean isValid = false;
1786 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1787 if (slist != null) {
1788 for (SubscriptionInfo subInfoRecord : slist) {
1789 if (subInfoRecord.getSubscriptionId() == subId) {
1790 isValid = true;
1791 break;
1792 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001793 }
Wink Saville08874612014-08-31 19:19:58 -07001794 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001795 if (!isValid) {
1796 return;
1797 }
Wink Saville08874612014-08-31 19:19:58 -07001798
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001799 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1800 intent.putExtra(SUBSCRIPTION_KEY, subId);
1801 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1802 mApp.startActivity(intent);
1803 } finally {
1804 Binder.restoreCallingIdentity(identity);
1805 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 }
1807
Wink Savilleb564aae2014-10-23 10:18:09 -07001808 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001809 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001810 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1811 }
1812
Wink Savilleb564aae2014-10-23 10:18:09 -07001813 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001814 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001815 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1816 }
1817
Wink Savilleb564aae2014-10-23 10:18:09 -07001818 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001820
1821 final long identity = Binder.clearCallingIdentity();
1822 try {
1823 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1824 checkSimPin.start();
1825 return checkSimPin.unlockSim(null, pin);
1826 } finally {
1827 Binder.restoreCallingIdentity(identity);
1828 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001829 }
1830
Wink Savilleb564aae2014-10-23 10:18:09 -07001831 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001833
1834 final long identity = Binder.clearCallingIdentity();
1835 try {
1836 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1837 checkSimPuk.start();
1838 return checkSimPuk.unlockSim(puk, pin);
1839 } finally {
1840 Binder.restoreCallingIdentity(identity);
1841 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 }
1843
1844 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001845 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 * a synchronous one.
1847 */
1848 private static class UnlockSim extends Thread {
1849
1850 private final IccCard mSimCard;
1851
1852 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001853 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1854 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001855
1856 // For replies from SimCard interface
1857 private Handler mHandler;
1858
1859 // For async handler to identify request type
1860 private static final int SUPPLY_PIN_COMPLETE = 100;
1861
1862 public UnlockSim(IccCard simCard) {
1863 mSimCard = simCard;
1864 }
1865
1866 @Override
1867 public void run() {
1868 Looper.prepare();
1869 synchronized (UnlockSim.this) {
1870 mHandler = new Handler() {
1871 @Override
1872 public void handleMessage(Message msg) {
1873 AsyncResult ar = (AsyncResult) msg.obj;
1874 switch (msg.what) {
1875 case SUPPLY_PIN_COMPLETE:
1876 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1877 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001878 mRetryCount = msg.arg1;
1879 if (ar.exception != null) {
1880 if (ar.exception instanceof CommandException &&
1881 ((CommandException)(ar.exception)).getCommandError()
1882 == CommandException.Error.PASSWORD_INCORRECT) {
1883 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1884 } else {
1885 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1886 }
1887 } else {
1888 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 mDone = true;
1891 UnlockSim.this.notifyAll();
1892 }
1893 break;
1894 }
1895 }
1896 };
1897 UnlockSim.this.notifyAll();
1898 }
1899 Looper.loop();
1900 }
1901
1902 /*
1903 * Use PIN or PUK to unlock SIM card
1904 *
1905 * If PUK is null, unlock SIM card with PIN
1906 *
1907 * If PUK is not null, unlock SIM card with PUK and set PIN code
1908 */
Wink Saville9de0f752013-10-22 19:04:03 -07001909 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910
1911 while (mHandler == null) {
1912 try {
1913 wait();
1914 } catch (InterruptedException e) {
1915 Thread.currentThread().interrupt();
1916 }
1917 }
1918 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1919
1920 if (puk == null) {
1921 mSimCard.supplyPin(pin, callback);
1922 } else {
1923 mSimCard.supplyPuk(puk, pin, callback);
1924 }
1925
1926 while (!mDone) {
1927 try {
1928 Log.d(LOG_TAG, "wait for done");
1929 wait();
1930 } catch (InterruptedException e) {
1931 // Restore the interrupted status
1932 Thread.currentThread().interrupt();
1933 }
1934 }
1935 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001936 int[] resultArray = new int[2];
1937 resultArray[0] = mResult;
1938 resultArray[1] = mRetryCount;
1939 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 }
1941 }
1942
1943 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001944 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001945
1946 }
1947
Wink Savilleb564aae2014-10-23 10:18:09 -07001948 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001949 // No permission check needed here: this call is harmless, and it's
1950 // needed for the ServiceState.requestStateUpdate() call (which is
1951 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001952 final long identity = Binder.clearCallingIdentity();
1953 try {
1954 final Phone phone = getPhone(subId);
1955 if (phone != null) {
1956 phone.updateServiceLocation();
1957 }
1958 } finally {
1959 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001960 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001961 }
1962
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001963 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001964 @Override
1965 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001966 return isRadioOnWithFeature(callingPackage, null);
1967 }
1968
1969
1970 @Override
1971 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1972 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1973 callingFeatureId);
1974 }
1975
1976 @Deprecated
1977 @Override
1978 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1979 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001980 }
1981
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001982 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001983 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1984 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001986 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001987 return false;
1988 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001989
1990 final long identity = Binder.clearCallingIdentity();
1991 try {
1992 return isRadioOnForSubscriber(subId);
1993 } finally {
1994 Binder.restoreCallingIdentity(identity);
1995 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001996 }
1997
1998 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001999 final long identity = Binder.clearCallingIdentity();
2000 try {
2001 final Phone phone = getPhone(subId);
2002 if (phone != null) {
2003 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2004 } else {
2005 return false;
2006 }
2007 } finally {
2008 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002009 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002010 }
2011
2012 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002013 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002014 }
Wink Saville36469e72014-06-11 15:17:00 -07002015
Wink Savilleb564aae2014-10-23 10:18:09 -07002016 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002018
2019 final long identity = Binder.clearCallingIdentity();
2020 try {
2021 final Phone phone = getPhone(subId);
2022 if (phone != null) {
2023 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2024 }
2025 } finally {
2026 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002027 }
Wink Saville36469e72014-06-11 15:17:00 -07002028 }
2029
2030 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002031 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002032 }
2033
Wink Savilleb564aae2014-10-23 10:18:09 -07002034 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002035 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002036
2037 final long identity = Binder.clearCallingIdentity();
2038 try {
2039 final Phone phone = getPhone(subId);
2040 if (phone == null) {
2041 return false;
2042 }
2043 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2044 toggleRadioOnOffForSubscriber(subId);
2045 }
2046 return true;
2047 } finally {
2048 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002049 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002050 }
Wink Saville36469e72014-06-11 15:17:00 -07002051
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002052 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002053 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002054 /*
2055 * If any of the Radios are available, it will need to be
2056 * shutdown. So return true if any Radio is available.
2057 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002058 final long identity = Binder.clearCallingIdentity();
2059 try {
2060 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2061 Phone phone = PhoneFactory.getPhone(i);
2062 if (phone != null && phone.isRadioAvailable()) return true;
2063 }
2064 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2065 return false;
2066 } finally {
2067 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002068 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002069 }
2070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002071 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002072 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002073 enforceModifyPermission();
2074
2075 final long identity = Binder.clearCallingIdentity();
2076 try {
2077 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2078 logv("Shutting down Phone " + i);
2079 shutdownRadioUsingPhoneId(i);
2080 }
2081 } finally {
2082 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002083 }
2084 }
2085
2086 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002087 Phone phone = PhoneFactory.getPhone(phoneId);
2088 if (phone != null && phone.isRadioAvailable()) {
2089 phone.shutdownRadio();
2090 }
2091 }
2092
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002094 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002095
2096 final long identity = Binder.clearCallingIdentity();
2097 try {
2098 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2099 if (defaultPhone != null) {
2100 defaultPhone.setRadioPower(turnOn);
2101 return true;
2102 } else {
2103 loge("There's no default phone.");
2104 return false;
2105 }
2106 } finally {
2107 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002108 }
Wink Saville36469e72014-06-11 15:17:00 -07002109 }
2110
Wink Savilleb564aae2014-10-23 10:18:09 -07002111 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002113
2114 final long identity = Binder.clearCallingIdentity();
2115 try {
2116 final Phone phone = getPhone(subId);
2117 if (phone != null) {
2118 phone.setRadioPower(turnOn);
2119 return true;
2120 } else {
2121 return false;
2122 }
2123 } finally {
2124 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002125 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002126 }
2127
Wink Saville36469e72014-06-11 15:17:00 -07002128 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002129 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002130 public boolean enableDataConnectivity() {
2131 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002132
2133 final long identity = Binder.clearCallingIdentity();
2134 try {
2135 int subId = mSubscriptionController.getDefaultDataSubId();
2136 final Phone phone = getPhone(subId);
2137 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002138 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002139 return true;
2140 } else {
2141 return false;
2142 }
2143 } finally {
2144 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002145 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002146 }
2147
Wink Saville36469e72014-06-11 15:17:00 -07002148 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002149 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 public boolean disableDataConnectivity() {
2151 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002152
2153 final long identity = Binder.clearCallingIdentity();
2154 try {
2155 int subId = mSubscriptionController.getDefaultDataSubId();
2156 final Phone phone = getPhone(subId);
2157 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002158 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002159 return true;
2160 } else {
2161 return false;
2162 }
2163 } finally {
2164 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 }
2167
Sanket Padawe356d7632015-06-22 14:03:32 -07002168 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002169 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002170 final long identity = Binder.clearCallingIdentity();
2171 try {
2172 final Phone phone = getPhone(subId);
2173 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002174 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002175 } else {
2176 return false;
2177 }
2178 } finally {
2179 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 }
2182
2183 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002184 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002185 }
2186
pkanwarae03a6b2016-11-06 20:37:09 -08002187 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002188 enforceCallPermission();
2189
2190 final long identity = Binder.clearCallingIdentity();
2191 try {
2192 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2193 return;
2194 }
2195 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2196 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2197 } finally {
2198 Binder.restoreCallingIdentity(identity);
2199 }
pkanwar32d516d2016-10-14 19:37:38 -07002200 };
2201
Wink Savilleb564aae2014-10-23 10:18:09 -07002202 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002203 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002204
2205 final long identity = Binder.clearCallingIdentity();
2206 try {
2207 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2208 return false;
2209 }
2210 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2211 } finally {
2212 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002213 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002214 }
2215
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002217 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002218 }
2219
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002220 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002221 final long identity = Binder.clearCallingIdentity();
2222 try {
2223 Phone phone = PhoneFactory.getPhone(slotIndex);
2224 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2225 PhoneConstantConversions.convertCallState(phone.getState());
2226 } finally {
2227 Binder.restoreCallingIdentity(identity);
2228 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229 }
2230
Sanket Padawe356d7632015-06-22 14:03:32 -07002231 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002232 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002233 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2234 }
2235
2236 @Override
2237 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002238 final long identity = Binder.clearCallingIdentity();
2239 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002240 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002241 if (phone != null) {
2242 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2243 } else {
2244 return PhoneConstantConversions.convertDataState(
2245 PhoneConstants.DataState.DISCONNECTED);
2246 }
2247 } finally {
2248 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002250 }
2251
Sanket Padawe356d7632015-06-22 14:03:32 -07002252 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002253 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002254 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2255 }
2256
2257 @Override
2258 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002259 final long identity = Binder.clearCallingIdentity();
2260 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002261 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002262 if (phone != null) {
2263 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2264 } else {
2265 return TelephonyManager.DATA_ACTIVITY_NONE;
2266 }
2267 } finally {
2268 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 }
2271
2272 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002273 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002274 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002275 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002276
2277 LocationAccessPolicy.LocationPermissionResult locationResult =
2278 LocationAccessPolicy.checkLocationPermission(mApp,
2279 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2280 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002281 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002282 .setCallingPid(Binder.getCallingPid())
2283 .setCallingUid(Binder.getCallingUid())
2284 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002285 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002286 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2287 .build());
2288 switch (locationResult) {
2289 case DENIED_HARD:
2290 throw new SecurityException("Not allowed to access cell location");
2291 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002292 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2293 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 }
2295
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002296 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002297 final long identity = Binder.clearCallingIdentity();
2298 try {
2299 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002300 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002301 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002302 } finally {
2303 Binder.restoreCallingIdentity(identity);
2304 }
Svetoslav64fad262015-04-14 14:35:21 -07002305 }
2306
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002308 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002309 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2310 // registered cell info, so return a NULL country instead.
2311 final long identity = Binder.clearCallingIdentity();
2312 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002313 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2314 // Get default phone in this case.
2315 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2316 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002317 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002318 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002319 if (phone == null) return "";
2320 ServiceStateTracker sst = phone.getServiceStateTracker();
2321 if (sst == null) return "";
2322 LocaleTracker lt = sst.getLocaleTracker();
2323 if (lt == null) return "";
2324 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2325 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2326 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002327 } finally {
2328 Binder.restoreCallingIdentity(identity);
2329 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002330 }
2331
2332 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002334 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002335 }
2336
Sanket Padawe356d7632015-06-22 14:03:32 -07002337 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002338 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 mApp.enforceCallingOrSelfPermission(
2340 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002341
2342 final long identity = Binder.clearCallingIdentity();
2343 try {
2344 final Phone phone = getPhone(subId);
2345 if (phone != null) {
2346 phone.enableLocationUpdates();
2347 }
2348 } finally {
2349 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002350 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351 }
2352
2353 @Override
2354 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002355 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002356 }
2357
Sanket Padawe356d7632015-06-22 14:03:32 -07002358 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002359 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 mApp.enforceCallingOrSelfPermission(
2361 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002362
2363 final long identity = Binder.clearCallingIdentity();
2364 try {
2365 final Phone phone = getPhone(subId);
2366 if (phone != null) {
2367 phone.disableLocationUpdates();
2368 }
2369 } finally {
2370 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 }
2373
Nathan Harold31d7ff32018-10-15 20:20:30 -07002374 /**
2375 * Returns the target SDK version number for a given package name.
2376 *
Nathan Haroldec184742019-07-10 17:04:16 -07002377 * This call MUST be invoked before clearing the calling UID.
2378 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002379 * @return target SDK if the package is found or INT_MAX.
2380 */
2381 private int getTargetSdk(String packageName) {
2382 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002383 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002384 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002385 if (ai != null) return ai.targetSdkVersion;
2386 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002387 loge("Failed to get package info for pkg="
2388 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002389 }
2390 return Integer.MAX_VALUE;
2391 }
2392
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393 @Override
2394 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002395 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2396 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002397 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002398 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2399 throw new SecurityException(
2400 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2401 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002402
Jordan Liu1617b712019-07-10 15:06:26 -07002403 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2405 return null;
2406 }
Svetoslav64fad262015-04-14 14:35:21 -07002407
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002408 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002409
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002410 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002411 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412
Nathan Haroldf180aac2018-06-01 18:43:55 -07002413 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2414 for (CellInfo ci : info) {
2415 if (ci instanceof CellInfoGsm) {
2416 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2417 } else if (ci instanceof CellInfoWcdma) {
2418 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2419 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002420 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002421 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 }
2423
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002424 private List<CellInfo> getCachedCellInfo() {
2425 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2426 for (Phone phone : PhoneFactory.getPhones()) {
2427 List<CellInfo> info = phone.getAllCellInfo();
2428 if (info != null) cellInfos.addAll(info);
2429 }
2430 return cellInfos;
2431 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432
2433 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002434 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002435 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002436 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002437
2438 LocationAccessPolicy.LocationPermissionResult locationResult =
2439 LocationAccessPolicy.checkLocationPermission(mApp,
2440 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2441 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002442 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002443 .setCallingPid(Binder.getCallingPid())
2444 .setCallingUid(Binder.getCallingUid())
2445 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002446 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002447 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2448 .build());
2449 switch (locationResult) {
2450 case DENIED_HARD:
2451 throw new SecurityException("Not allowed to access cell info");
2452 case DENIED_SOFT:
2453 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454 }
2455
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002456 final int targetSdk = getTargetSdk(callingPackage);
2457 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2458 return getCachedCellInfo();
2459 }
2460
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002461 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002462 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002463 final long identity = Binder.clearCallingIdentity();
2464 try {
2465 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2466 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002467 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002468 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002469 if (info != null) cellInfos.addAll(info);
2470 }
2471 return cellInfos;
2472 } finally {
2473 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002474 }
2475 }
2476
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002477 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002478 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2479 String callingFeatureId) {
2480 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2481 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002482 }
2483
2484 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002485 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2486 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002487 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002488 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002489 }
2490
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002491 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2492 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002493 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002494 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002495
2496 LocationAccessPolicy.LocationPermissionResult locationResult =
2497 LocationAccessPolicy.checkLocationPermission(mApp,
2498 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2499 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002500 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002501 .setCallingPid(Binder.getCallingPid())
2502 .setCallingUid(Binder.getCallingUid())
2503 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002504 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2505 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002506 .build());
2507 switch (locationResult) {
2508 case DENIED_HARD:
Hall Liud60acc92020-05-21 17:09:35 -07002509 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2510 // Safetynet logging for b/154934934
2511 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2512 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002513 throw new SecurityException("Not allowed to access cell info");
2514 case DENIED_SOFT:
Hall Liud60acc92020-05-21 17:09:35 -07002515 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2516 // Safetynet logging for b/154934934
2517 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2518 }
Nathan Harold5320c422019-05-09 10:26:08 -07002519 try {
2520 cb.onCellInfo(new ArrayList<CellInfo>());
2521 } catch (RemoteException re) {
2522 // Drop without consequences
2523 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002524 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002525 }
2526
Nathan Harolda939a962019-05-09 10:13:47 -07002527
2528 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002529 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2530
2531 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2532 }
2533
2534 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002535 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002536 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002537 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002538
2539 final long identity = Binder.clearCallingIdentity();
2540 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002541 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002542 } finally {
2543 Binder.restoreCallingIdentity(identity);
2544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002545 }
2546
Shishir Agrawala9f32182016-04-12 12:00:16 -07002547 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002548 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002549 Phone phone = PhoneFactory.getPhone(slotIndex);
2550 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002551 return null;
2552 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002553 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002554 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002555 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002556 return null;
2557 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002558
2559 final long identity = Binder.clearCallingIdentity();
2560 try {
2561 return phone.getImei();
2562 } finally {
2563 Binder.restoreCallingIdentity(identity);
2564 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002565 }
2566
2567 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002568 public String getTypeAllocationCodeForSlot(int slotIndex) {
2569 Phone phone = PhoneFactory.getPhone(slotIndex);
2570 String tac = null;
2571 if (phone != null) {
2572 String imei = phone.getImei();
2573 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2574 }
2575 return tac;
2576 }
2577
2578 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002579 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002580 Phone phone = PhoneFactory.getPhone(slotIndex);
2581 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002582 return null;
2583 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002584
Jeff Davidson913390f2018-02-23 17:11:49 -08002585 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002586 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002587 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002588 return null;
2589 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002590
2591 final long identity = Binder.clearCallingIdentity();
2592 try {
2593 return phone.getMeid();
2594 } finally {
2595 Binder.restoreCallingIdentity(identity);
2596 }
Jack Yu2af8d712017-03-15 17:14:14 -07002597 }
2598
2599 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002600 public String getManufacturerCodeForSlot(int slotIndex) {
2601 Phone phone = PhoneFactory.getPhone(slotIndex);
2602 String manufacturerCode = null;
2603 if (phone != null) {
2604 String meid = phone.getMeid();
2605 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2606 }
2607 return manufacturerCode;
2608 }
2609
2610 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002611 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2612 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002613 Phone phone = PhoneFactory.getPhone(slotIndex);
2614 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002615 return null;
2616 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002617 int subId = phone.getSubId();
2618 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002619 mApp, subId, callingPackage, callingFeatureId,
2620 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002621 return null;
2622 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623
2624 final long identity = Binder.clearCallingIdentity();
2625 try {
2626 return phone.getDeviceSvn();
2627 } finally {
2628 Binder.restoreCallingIdentity(identity);
2629 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002630 }
2631
fionaxu43304da2017-11-27 22:51:16 -08002632 @Override
2633 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002634 final long identity = Binder.clearCallingIdentity();
2635 try {
2636 final Phone phone = getPhone(subId);
2637 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2638 } finally {
2639 Binder.restoreCallingIdentity(identity);
2640 }
fionaxu43304da2017-11-27 22:51:16 -08002641 }
2642
2643 @Override
2644 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002645 final long identity = Binder.clearCallingIdentity();
2646 try {
2647 final Phone phone = getPhone(subId);
2648 return phone == null ? null : phone.getCarrierName();
2649 } finally {
2650 Binder.restoreCallingIdentity(identity);
2651 }
fionaxu43304da2017-11-27 22:51:16 -08002652 }
2653
calvinpanffe225e2018-11-01 19:43:06 +08002654 @Override
chen xu0026ca62019-03-06 15:28:50 -08002655 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002656 final long identity = Binder.clearCallingIdentity();
2657 try {
2658 final Phone phone = getPhone(subId);
2659 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002660 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002661 } finally {
2662 Binder.restoreCallingIdentity(identity);
2663 }
2664 }
2665
2666 @Override
chen xu0026ca62019-03-06 15:28:50 -08002667 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002668 final long identity = Binder.clearCallingIdentity();
2669 try {
2670 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002671 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002672 } finally {
2673 Binder.restoreCallingIdentity(identity);
2674 }
2675 }
2676
chen xu651eec72018-11-11 19:03:44 -08002677 @Override
chen xu864e11c2018-12-06 22:10:03 -08002678 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2679 if (!isSubscriptionMccMnc) {
2680 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2681 }
chen xu651eec72018-11-11 19:03:44 -08002682 final Phone phone = PhoneFactory.getPhone(slotIndex);
2683 if (phone == null) {
2684 return TelephonyManager.UNKNOWN_CARRIER_ID;
2685 }
2686 final long identity = Binder.clearCallingIdentity();
2687 try {
2688 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2689 } finally {
2690 Binder.restoreCallingIdentity(identity);
2691 }
2692 }
2693
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694 //
2695 // Internal helper methods.
2696 //
2697
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002698 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2700 *
2701 * @throws SecurityException if the caller does not have the required permission
2702 */
2703 private void enforceModifyPermission() {
2704 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2705 }
2706
Shuo Qiancd19c462020-01-16 20:51:11 -08002707 /**
2708 * Make sure the caller is system.
2709 *
2710 * @throws SecurityException if the caller is not system.
2711 */
2712 private void enforceSystemCaller() {
2713 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2714 throw new SecurityException("Caller must be system");
2715 }
2716 }
2717
Shuo Qian3b6ee772019-11-13 17:43:31 -08002718 private void enforceActiveEmergencySessionPermission() {
2719 mApp.enforceCallingOrSelfPermission(
2720 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2721 }
2722
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002723 /**
2724 * Make sure the caller has the CALL_PHONE permission.
2725 *
2726 * @throws SecurityException if the caller does not have the required permission
2727 */
2728 private void enforceCallPermission() {
2729 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2730 }
2731
paulhu5a773602019-08-23 19:17:33 +08002732 private void enforceSettingsPermission() {
2733 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002734 }
2735
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736 private String createTelUrl(String number) {
2737 if (TextUtils.isEmpty(number)) {
2738 return null;
2739 }
2740
Jake Hambye994d462014-02-03 13:10:13 -08002741 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 }
2743
Ihab Awadf9e92732013-12-05 18:02:52 -08002744 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2746 }
2747
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002748 private static void logv(String msg) {
2749 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2750 }
2751
Ihab Awadf9e92732013-12-05 18:02:52 -08002752 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002753 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2754 }
2755
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002756 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002758 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002759 }
2760
Sanket Padawe356d7632015-06-22 14:03:32 -07002761 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002762 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002763 final long identity = Binder.clearCallingIdentity();
2764 try {
2765 final Phone phone = PhoneFactory.getPhone(slotIndex);
2766 if (phone == null) {
2767 return PhoneConstants.PHONE_TYPE_NONE;
2768 } else {
2769 return phone.getPhoneType();
2770 }
2771 } finally {
2772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002774 }
2775
2776 /**
2777 * Returns the CDMA ERI icon index to display
2778 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002779 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002780 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2781 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2782 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002783 }
2784
Sanket Padawe356d7632015-06-22 14:03:32 -07002785 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002786 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2787 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002788 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002789 mApp, subId, callingPackage, callingFeatureId,
2790 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002791 return -1;
2792 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002793
2794 final long identity = Binder.clearCallingIdentity();
2795 try {
2796 final Phone phone = getPhone(subId);
2797 if (phone != null) {
2798 return phone.getCdmaEriIconIndex();
2799 } else {
2800 return -1;
2801 }
2802 } finally {
2803 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002804 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002805 }
2806
2807 /**
2808 * Returns the CDMA ERI icon mode,
2809 * 0 - ON
2810 * 1 - FLASHING
2811 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002812 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002813 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2814 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2815 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002816 }
2817
Sanket Padawe356d7632015-06-22 14:03:32 -07002818 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002819 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2820 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002821 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002822 mApp, subId, callingPackage, callingFeatureId,
2823 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002824 return -1;
2825 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826
2827 final long identity = Binder.clearCallingIdentity();
2828 try {
2829 final Phone phone = getPhone(subId);
2830 if (phone != null) {
2831 return phone.getCdmaEriIconMode();
2832 } else {
2833 return -1;
2834 }
2835 } finally {
2836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002838 }
2839
2840 /**
2841 * Returns the CDMA ERI text,
2842 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002843 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002844 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2845 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2846 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002847 }
2848
Sanket Padawe356d7632015-06-22 14:03:32 -07002849 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002850 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2851 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002852 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002853 mApp, subId, callingPackage, callingFeatureId,
2854 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002855 return null;
2856 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002857
2858 final long identity = Binder.clearCallingIdentity();
2859 try {
2860 final Phone phone = getPhone(subId);
2861 if (phone != null) {
2862 return phone.getCdmaEriText();
2863 } else {
2864 return null;
2865 }
2866 } finally {
2867 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002868 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002869 }
2870
2871 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002872 * Returns the CDMA MDN.
2873 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002874 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002875 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2877 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878
2879 final long identity = Binder.clearCallingIdentity();
2880 try {
2881 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002882 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002883 return phone.getLine1Number();
2884 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002885 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002886 return null;
2887 }
2888 } finally {
2889 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002890 }
2891 }
2892
2893 /**
2894 * Returns the CDMA MIN.
2895 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002896 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002897 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2899 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002900
2901 final long identity = Binder.clearCallingIdentity();
2902 try {
2903 final Phone phone = getPhone(subId);
2904 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2905 return phone.getCdmaMin();
2906 } else {
2907 return null;
2908 }
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002911 }
2912 }
2913
Hall Liud892bec2018-11-30 14:51:45 -08002914 @Override
2915 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2916 INumberVerificationCallback callback, String callingPackage) {
2917 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2918 != PERMISSION_GRANTED) {
2919 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2920 }
2921 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2922
2923 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2924 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2925 throw new SecurityException("Calling package must be configured in the device config");
2926 }
2927
2928 if (range == null) {
2929 throw new NullPointerException("Range must be non-null");
2930 }
2931
2932 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002933 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002934
2935 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2936 }
2937
Junda Liuca05d5d2014-08-14 22:36:34 -07002938 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002939 * Returns true if CDMA provisioning needs to run.
2940 */
2941 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002942 final long identity = Binder.clearCallingIdentity();
2943 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002944 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002945 } finally {
2946 Binder.restoreCallingIdentity(identity);
2947 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002948 }
2949
2950 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002951 * Sets the voice mail number of a given subId.
2952 */
2953 @Override
2954 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002955 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2956 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002957
2958 final long identity = Binder.clearCallingIdentity();
2959 try {
2960 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2961 new Pair<String, String>(alphaTag, number), new Integer(subId));
2962 return success;
2963 } finally {
2964 Binder.restoreCallingIdentity(identity);
2965 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002966 }
2967
Ta-wei Yen87c49842016-05-13 21:19:52 -07002968 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002969 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2970 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002971 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2972 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002973 if (!TextUtils.equals(callingPackage, systemDialer)) {
2974 throw new SecurityException("caller must be system dialer");
2975 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002976
2977 final long identity = Binder.clearCallingIdentity();
2978 try {
2979 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2980 if (phoneAccountHandle == null) {
2981 return null;
2982 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002983 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002984 } finally {
2985 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002986 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002987 }
2988
2989 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002990 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2991 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002992 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002993 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002994 mApp, subId, callingPackage, callingFeatureId,
2995 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002996 return null;
2997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002999 final long identity = Binder.clearCallingIdentity();
3000 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003001 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003002 } finally {
3003 Binder.restoreCallingIdentity(identity);
3004 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003005 }
3006
3007 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003008 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3009 VisualVoicemailSmsFilterSettings settings) {
3010 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003011
3012 final long identity = Binder.clearCallingIdentity();
3013 try {
3014 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003015 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016 } finally {
3017 Binder.restoreCallingIdentity(identity);
3018 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003019 }
3020
3021 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003022 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3023 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003024
3025 final long identity = Binder.clearCallingIdentity();
3026 try {
3027 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003028 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003029 } finally {
3030 Binder.restoreCallingIdentity(identity);
3031 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003032 }
3033
3034 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003035 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3036 String callingPackage, int subId) {
3037 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003038
3039 final long identity = Binder.clearCallingIdentity();
3040 try {
3041 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003042 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003043 } finally {
3044 Binder.restoreCallingIdentity(identity);
3045 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003046 }
3047
3048 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003049 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003050 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003051
3052 final long identity = Binder.clearCallingIdentity();
3053 try {
3054 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003055 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003056 } finally {
3057 Binder.restoreCallingIdentity(identity);
3058 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003059 }
3060
3061 @Override
Philip P. Moltmannacc63642020-03-19 21:37:01 +00003062 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3063 String callingAttributionTag, int subId, String number, int port, String text,
3064 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003065 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003066 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003067 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003068 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmannacc63642020-03-19 21:37:01 +00003069 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3070 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003071 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003072
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003073 /**
fionaxu0152e512016-11-14 13:36:14 -08003074 * Sets the voice activation state of a given subId.
3075 */
3076 @Override
3077 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003078 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3079 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003080
3081 final long identity = Binder.clearCallingIdentity();
3082 try {
3083 final Phone phone = getPhone(subId);
3084 if (phone != null) {
3085 phone.setVoiceActivationState(activationState);
3086 } else {
3087 loge("setVoiceActivationState fails with invalid subId: " + subId);
3088 }
3089 } finally {
3090 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003091 }
3092 }
3093
3094 /**
3095 * Sets the data activation state of a given subId.
3096 */
3097 @Override
3098 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3100 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003101
3102 final long identity = Binder.clearCallingIdentity();
3103 try {
3104 final Phone phone = getPhone(subId);
3105 if (phone != null) {
3106 phone.setDataActivationState(activationState);
3107 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003108 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003109 }
3110 } finally {
3111 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003112 }
3113 }
3114
3115 /**
3116 * Returns the voice activation state of a given subId.
3117 */
3118 @Override
3119 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003120 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003121
fionaxu0152e512016-11-14 13:36:14 -08003122 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003123 final long identity = Binder.clearCallingIdentity();
3124 try {
3125 if (phone != null) {
3126 return phone.getVoiceActivationState();
3127 } else {
3128 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3129 }
3130 } finally {
3131 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003132 }
3133 }
3134
3135 /**
3136 * Returns the data activation state of a given subId.
3137 */
3138 @Override
3139 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003140 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003141
fionaxu0152e512016-11-14 13:36:14 -08003142 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003143 final long identity = Binder.clearCallingIdentity();
3144 try {
3145 if (phone != null) {
3146 return phone.getDataActivationState();
3147 } else {
3148 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3149 }
3150 } finally {
3151 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003152 }
3153 }
3154
3155 /**
Wink Saville36469e72014-06-11 15:17:00 -07003156 * Returns the unread count of voicemails for a subId
3157 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003158 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003159 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3160 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003161 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003162 mApp, subId, callingPackage, callingFeatureId,
3163 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003164 return 0;
3165 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003166 final long identity = Binder.clearCallingIdentity();
3167 try {
3168 final Phone phone = getPhone(subId);
3169 if (phone != null) {
3170 return phone.getVoiceMessageCount();
3171 } else {
3172 return 0;
3173 }
3174 } finally {
3175 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003176 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003177 }
3178
3179 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003180 * returns true, if the device is in a state where both voice and data
3181 * are supported simultaneously. This can change based on location or network condition.
3182 */
3183 @Override
3184 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003185 final long identity = Binder.clearCallingIdentity();
3186 try {
3187 final Phone phone = getPhone(subId);
3188 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3189 } finally {
3190 Binder.restoreCallingIdentity(identity);
3191 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003192 }
3193
3194 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003195 * Send the dialer code if called from the current default dialer or the caller has
3196 * carrier privilege.
3197 * @param inputCode The dialer code to send
3198 */
3199 @Override
3200 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003201 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003202 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003203 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3204 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003205 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003206 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003207 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003208 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003209
3210 final long identity = Binder.clearCallingIdentity();
3211 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003212 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003213 } finally {
3214 Binder.restoreCallingIdentity(identity);
3215 }
fionaxu235cc5e2017-03-06 22:25:57 -08003216 }
3217
Pengquan Menga1bb6272018-09-06 09:59:22 -07003218 @Override
3219 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003220 TelephonyPermissions
3221 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3222 mApp, subId, "getNetworkSelectionMode");
3223 final long identity = Binder.clearCallingIdentity();
3224 try {
3225 if (!isActiveSubscription(subId)) {
3226 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3227 }
3228 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3229 } finally {
3230 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003231 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003232 }
3233
Brad Ebinger35c841c2018-10-01 10:40:55 -07003234 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003235 public boolean isInEmergencySmsMode() {
3236 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 for (Phone phone : PhoneFactory.getPhones()) {
3240 if (phone.isInEmergencySmsMode()) {
3241 return true;
3242 }
3243 }
3244 } finally {
3245 Binder.restoreCallingIdentity(identity);
3246 }
3247 return false;
3248 }
3249
shilu366312e2019-12-17 09:28:10 -08003250 /**
3251 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3252 * @param subId The subscription to use to check the configuration.
3253 * @param c The callback that will be used to send the result.
3254 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003255 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003256 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3257 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003258 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3259 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003260
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003261 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3262 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3263 "IMS not available on device.");
3264 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003265 final long token = Binder.clearCallingIdentity();
3266 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003267 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003268 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003269 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003270 } catch (ImsException e) {
3271 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003272 } finally {
3273 Binder.restoreCallingIdentity(token);
3274 }
3275 }
3276
shilu366312e2019-12-17 09:28:10 -08003277 /**
3278 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3279 * @param subId The subscription to use to check the configuration.
3280 * @param c The callback that will be used to send the result.
3281 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003282 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003283 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003284 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3285 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003286 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3287 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3288 }
Meng Wangafbc5852019-09-19 17:37:13 -07003289 final long token = Binder.clearCallingIdentity();
3290 try {
3291 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3292 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3293 .removeRegistrationCallbackForSubscription(c, subId);
3294 } catch (ImsException e) {
3295 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3296 + "is inactive, ignoring unregister.");
3297 // If the subscription is no longer active, just return, since the callback
3298 // will already have been removed internally.
3299 } finally {
3300 Binder.restoreCallingIdentity(token);
3301 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003302 }
3303
Brad Ebingera34a6c22019-10-22 17:36:18 -07003304 /**
3305 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3306 */
3307 @Override
3308 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3309 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3310 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3311 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3312 "IMS not available on device.");
3313 }
3314 final long token = Binder.clearCallingIdentity();
3315 try {
3316 Phone phone = getPhone(subId);
3317 if (phone == null) {
3318 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3319 + subId + "'");
3320 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3321 }
3322 phone.getImsRegistrationState(regState -> {
3323 try {
3324 consumer.accept((regState == null)
3325 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3326 } catch (RemoteException e) {
3327 // Ignore if the remote process is no longer available to call back.
3328 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3329 }
3330 });
3331 } finally {
3332 Binder.restoreCallingIdentity(token);
3333 }
3334 }
3335
3336 /**
3337 * Get the transport type for the IMS service registration state.
3338 */
3339 @Override
3340 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003341 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3342 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003343 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3344 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3345 "IMS not available on device.");
3346 }
3347 final long token = Binder.clearCallingIdentity();
3348 try {
3349 Phone phone = getPhone(subId);
3350 if (phone == null) {
3351 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3352 + subId + "'");
3353 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3354 }
3355 phone.getImsRegistrationTech(regTech -> {
3356 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3357 int regTechConverted = (regTech == null)
3358 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3359 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3360 regTechConverted);
3361 try {
3362 consumer.accept(regTechConverted);
3363 } catch (RemoteException e) {
3364 // Ignore if the remote process is no longer available to call back.
3365 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3366 }
3367 });
3368 } finally {
3369 Binder.restoreCallingIdentity(token);
3370 }
3371 }
3372
shilu366312e2019-12-17 09:28:10 -08003373 /**
3374 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3375 * @param subId The subscription to use to check the configuration.
3376 * @param c The callback that will be used to send the result.
3377 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003378 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003379 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3380 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003381 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3382 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003383 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3384 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3385 "IMS not available on device.");
3386 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003387 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3388 final long token = Binder.clearCallingIdentity();
3389 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003390 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003391 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003392 } catch (ImsException e) {
3393 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003394 } finally {
3395 Binder.restoreCallingIdentity(token);
3396 }
3397 }
3398
shilu366312e2019-12-17 09:28:10 -08003399 /**
3400 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3401 * @param subId The subscription to use to check the configuration.
3402 * @param c The callback that will be used to send the result.
3403 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003404 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003405 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003406 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3407 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003408 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3409 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3410 }
Meng Wangafbc5852019-09-19 17:37:13 -07003411
3412 final long token = Binder.clearCallingIdentity();
3413 try {
3414 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3415 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003416 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003417 } catch (ImsException e) {
3418 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3419 + "is inactive, ignoring unregister.");
3420 // If the subscription is no longer active, just return, since the callback
3421 // will already have been removed internally.
3422 } finally {
3423 Binder.restoreCallingIdentity(token);
3424 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003425 }
3426
3427 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003428 public boolean isCapable(int subId, int capability, int regTech) {
3429 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003430 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3431 final long token = Binder.clearCallingIdentity();
3432 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003433 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003434 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003435 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003436 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3437 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003438 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003439 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3440 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003441 } finally {
3442 Binder.restoreCallingIdentity(token);
3443 }
3444 }
3445
3446 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003447 public boolean isAvailable(int subId, int capability, int regTech) {
3448 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003449 final long token = Binder.clearCallingIdentity();
3450 try {
3451 Phone phone = getPhone(subId);
3452 if (phone == null) return false;
3453 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003454 } catch (com.android.ims.ImsException e) {
3455 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3456 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003457 } finally {
3458 Binder.restoreCallingIdentity(token);
3459 }
3460 }
3461
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003462 /**
3463 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3464 * subscription.
3465 * @param subId The subscription to use to check the configuration.
3466 * @param callback The callback that will be used to send the result.
3467 * @param capability The MmTelFeature capability that will be used to send the result.
3468 * @param transportType The transport type of the MmTelFeature capability.
3469 */
3470 @Override
3471 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3472 int transportType) {
3473 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3474 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3475 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3476 "IMS not available on device.");
3477 }
3478 final long token = Binder.clearCallingIdentity();
3479 try {
3480 int slotId = getSlotIndex(subId);
3481 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3482 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3483 + subId + "'");
3484 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3485 }
3486 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3487 transportType, aBoolean -> {
3488 try {
3489 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3490 } catch (RemoteException e) {
3491 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3492 + "running. Ignore");
3493 }
3494 });
3495 } finally {
3496 Binder.restoreCallingIdentity(token);
3497 }
3498 }
3499
shilu366312e2019-12-17 09:28:10 -08003500 /**
3501 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3502 * @param subId The subscription to use to check the configuration.
3503 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003504 @Override
3505 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003506 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3507 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003508
Brad Ebinger35c841c2018-10-01 10:40:55 -07003509 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3510 final long token = Binder.clearCallingIdentity();
3511 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003512 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003513 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003514 } catch (ImsException e) {
3515 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003516 } finally {
3517 Binder.restoreCallingIdentity(token);
3518 }
3519 }
3520
3521 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003522 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003524 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003525 final long identity = Binder.clearCallingIdentity();
3526 try {
3527 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003528 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003529 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003530 } catch (ImsException e) {
3531 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003532 } finally {
3533 Binder.restoreCallingIdentity(identity);
3534 }
3535 }
3536
shilu366312e2019-12-17 09:28:10 -08003537 /**
3538 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3539 * @param subId The subscription to use to check the configuration.
3540 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003541 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003542 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003543 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3544 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003548 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3549 } catch (ImsException e) {
3550 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003551 } finally {
3552 Binder.restoreCallingIdentity(identity);
3553 }
3554 }
3555
3556 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003557 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003559 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003560 final long identity = Binder.clearCallingIdentity();
3561 try {
3562 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003563 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003564 } catch (ImsException e) {
3565 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003566 } finally {
3567 Binder.restoreCallingIdentity(identity);
3568 }
3569 }
3570
shilu366312e2019-12-17 09:28:10 -08003571 /**
3572 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3573 * @param subId The subscription to use to check the configuration.
3574 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003575 @Override
3576 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003577 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3578 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003579 final long identity = Binder.clearCallingIdentity();
3580 try {
3581 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003582 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003583 getSlotIndexOrException(subId)).isWfcEnabledByUser();
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(identity);
3588 }
3589 }
3590
3591 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003592 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003594 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003595 final long identity = Binder.clearCallingIdentity();
3596 try {
3597 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003598 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003599 } catch (ImsException e) {
3600 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003601 } finally {
3602 Binder.restoreCallingIdentity(identity);
3603 }
3604 }
3605
shilu366312e2019-12-17 09:28:10 -08003606 /**
3607 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3608 * @param subId The subscription to use to check the configuration.
3609 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003610 @Override
3611 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003612 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3613 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003614 final long identity = Binder.clearCallingIdentity();
3615 try {
3616 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003617 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003618 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003619 } catch (ImsException e) {
3620 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003621 } finally {
3622 Binder.restoreCallingIdentity(identity);
3623 }
3624 }
3625
3626 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003627 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003629 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003630 final long identity = Binder.clearCallingIdentity();
3631 try {
3632 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003633 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003634 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003635 } catch (ImsException e) {
3636 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003637 } finally {
3638 Binder.restoreCallingIdentity(identity);
3639 }
3640 }
3641
3642 @Override
3643 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3645 "setVoWiFiNonPersistent");
3646 final long identity = Binder.clearCallingIdentity();
3647 try {
3648 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003649 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003650 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003651 } catch (ImsException e) {
3652 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003653 } finally {
3654 Binder.restoreCallingIdentity(identity);
3655 }
3656 }
3657
shilu366312e2019-12-17 09:28:10 -08003658 /**
3659 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3660 * @param subId The subscription to use to check the configuration.
3661 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003662 @Override
3663 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003664 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3665 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003666 final long identity = Binder.clearCallingIdentity();
3667 try {
3668 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003669 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003670 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003671 } catch (ImsException e) {
3672 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003673 } finally {
3674 Binder.restoreCallingIdentity(identity);
3675 }
3676 }
3677
3678 @Override
3679 public void setVoWiFiModeSetting(int subId, int mode) {
3680 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3681 "setVoWiFiModeSetting");
3682 final long identity = Binder.clearCallingIdentity();
3683 try {
3684 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003685 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003686 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003687 } catch (ImsException e) {
3688 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003689 } finally {
3690 Binder.restoreCallingIdentity(identity);
3691 }
3692 }
3693
3694 @Override
3695 public int getVoWiFiRoamingModeSetting(int subId) {
3696 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003700 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003701 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003702 } catch (ImsException e) {
3703 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003704 } finally {
3705 Binder.restoreCallingIdentity(identity);
3706 }
3707 }
3708
3709 @Override
3710 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3712 "setVoWiFiRoamingModeSetting");
3713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003716 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003717 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003718 } catch (ImsException e) {
3719 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003720 } finally {
3721 Binder.restoreCallingIdentity(identity);
3722 }
3723 }
3724
3725 @Override
3726 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3727 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3728 "setRttCapabilityEnabled");
3729 final long identity = Binder.clearCallingIdentity();
3730 try {
3731 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003732 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3733 } catch (ImsException e) {
3734 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003735 } finally {
3736 Binder.restoreCallingIdentity(identity);
3737 }
3738 }
3739
shilu366312e2019-12-17 09:28:10 -08003740 /**
3741 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3742 * @param subId The subscription to use to check the configuration.
3743 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003744 @Override
3745 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003746 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3747 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003748 final long identity = Binder.clearCallingIdentity();
3749 try {
3750 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003751 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003752 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003753 } catch (ImsException e) {
3754 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003755 } finally {
3756 Binder.restoreCallingIdentity(identity);
3757 }
3758 }
3759
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003760 @Override
3761 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3762 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3763 final long identity = Binder.clearCallingIdentity();
3764 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003765 if (!isImsAvailableOnDevice()) {
3766 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3767 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003768 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003769 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003770 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003771 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003772 } catch (ImsException e) {
3773 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003774 } finally {
3775 Binder.restoreCallingIdentity(identity);
3776 }
3777 }
3778
3779 @Override
3780 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3781 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3782 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003783 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3784 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3785 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003786 try {
3787 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003788 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003789 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003790 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003791 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3792 + "is inactive, ignoring unregister.");
3793 // If the subscription is no longer active, just return, since the callback will already
3794 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003795 } finally {
3796 Binder.restoreCallingIdentity(identity);
3797 }
3798 }
3799
allenwtsu99c623b2020-01-03 18:24:23 +08003800
3801 private void checkModifyPhoneStatePermission(int subId, String message) {
3802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3803 message);
3804 }
3805
3806 private boolean isImsProvisioningRequired(int subId, int capability,
3807 boolean isMmtelCapability) {
3808 Phone phone = getPhone(subId);
3809 if (phone == null) {
3810 loge("phone instance null for subid " + subId);
3811 return false;
3812 }
3813 if (isMmtelCapability) {
3814 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3815 return false;
3816 }
3817 } else {
3818 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3819 return false;
3820 }
3821 }
3822 return true;
3823 }
3824
3825 @Override
3826 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3827 boolean isProvisioned) {
3828 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3829
3830 final long identity = Binder.clearCallingIdentity();
3831 try {
3832 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3833 if (!isImsProvisioningRequired(subId, capability, false)) {
3834 return;
3835 }
3836
3837 // this capability requires provisioning, route to the correct API.
3838 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3839 switch (capability) {
3840 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3841 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3842 ims.setEabProvisioned(isProvisioned);
3843 break;
3844 default: {
3845 throw new IllegalArgumentException("Tried to set provisioning for "
3846 + "rcs capability '" + capability + "', which does not require "
3847 + "provisioning.");
3848 }
3849 }
3850 } finally {
3851 Binder.restoreCallingIdentity(identity);
3852 }
3853
3854 }
3855
3856
3857 @Override
3858 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3859 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3860 final long identity = Binder.clearCallingIdentity();
3861 try {
3862 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3863 if (!isImsProvisioningRequired(subId, capability, false)) {
3864 return true;
3865 }
3866
3867 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3868 switch (capability) {
3869 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3870 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3871 return ims.isEabProvisionedOnDevice();
3872
3873 default: {
3874 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3875 + "capability '" + capability + "', which does not require "
3876 + "provisioning.");
3877 }
3878 }
3879
3880 } finally {
3881 Binder.restoreCallingIdentity(identity);
3882 }
3883 }
3884
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003885 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003886 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3887 boolean isProvisioned) {
3888 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3889 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3890 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3891 }
allenwtsu99c623b2020-01-03 18:24:23 +08003892 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003893 final long identity = Binder.clearCallingIdentity();
3894 try {
3895 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003896 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003897 return;
3898 }
3899
3900 // this capability requires provisioning, route to the correct API.
3901 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3902 switch (capability) {
3903 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3904 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3905 ims.setVolteProvisioned(isProvisioned);
3906 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3907 ims.setWfcProvisioned(isProvisioned);
3908 }
3909 break;
3910 }
3911 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3912 // There is currently no difference in VT provisioning type.
3913 ims.setVtProvisioned(isProvisioned);
3914 break;
3915 }
3916 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3917 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3918 // change the capability of the feature instead if needed.
3919 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3920 == isProvisioned) {
3921 // No change in provisioning.
3922 return;
3923 }
3924 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3925 try {
3926 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003927 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003928 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3929 + ", Exception" + e.getMessage());
3930 }
3931 break;
3932 }
3933 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003934 throw new IllegalArgumentException("Tried to set provisioning for "
3935 + "MmTel capability '" + capability + "', which does not require "
3936 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003937 }
3938 }
3939
3940 } finally {
3941 Binder.restoreCallingIdentity(identity);
3942 }
3943 }
3944
3945 @Override
3946 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3947 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3948 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3949 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3950 }
3951 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3952 final long identity = Binder.clearCallingIdentity();
3953 try {
3954 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003955 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003956 return true;
3957 }
3958
3959 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3960 switch (capability) {
3961 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3962 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3963 return ims.isVolteProvisionedOnDevice();
3964 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3965 return ims.isWfcProvisionedOnDevice();
3966 }
3967 // This should never happen, since we are checking tech above to make sure it
3968 // is either LTE or IWLAN.
3969 throw new IllegalArgumentException("Invalid radio technology for voice "
3970 + "capability.");
3971 }
3972 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3973 // There is currently no difference in VT provisioning type.
3974 return ims.isVtProvisionedOnDevice();
3975 }
3976 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3977 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3978 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3979 }
3980 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003981 throw new IllegalArgumentException(
3982 "Tried to get provisioning for MmTel capability '" + capability
3983 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003984 }
3985 }
3986
3987 } finally {
3988 Binder.restoreCallingIdentity(identity);
3989 }
3990 }
3991
3992 @Override
3993 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3994 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3995 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3996 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3997 }
3998 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3999 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4000 return (provisionedBits & capability) > 0;
4001 }
4002
4003 @Override
4004 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4005 boolean isProvisioned) {
4006 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4007 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4008 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4009 }
4010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4011 "setProvisioningStatusForCapability");
4012 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4013 // If the current provisioning status for capability already matches isProvisioned,
4014 // do nothing.
4015 if (((provisionedBits & capability) > 0) == isProvisioned) {
4016 return;
4017 }
4018 if (isProvisioned) {
4019 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4020 } else {
4021 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4022 }
4023 }
4024
4025 /**
4026 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4027 * technology. The bitfield should mirror the bitfield defined by
4028 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4029 */
4030 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4031 String key = getMmTelProvisioningKey(subId, tech);
4032 // Default is no capabilities are provisioned.
4033 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4034 }
4035
4036 /**
4037 * Sets the MmTel capability provisioning bitfield (defined by
4038 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4039 * technology specified.
4040 *
4041 * Note: This is a synchronous command and should not be called on UI thread.
4042 */
4043 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4044 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4045 String key = getMmTelProvisioningKey(subId, tech);
4046 editor.putInt(key, newField);
4047 editor.commit();
4048 }
4049
4050 private static String getMmTelProvisioningKey(int subId, int tech) {
4051 // resulting key is provision_ims_mmtel_{subId}_{tech}
4052 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4053 }
4054
4055 /**
4056 * Query CarrierConfig to see if the specified capability requires provisioning for the
4057 * carrier associated with the subscription id.
4058 */
4059 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4060 int capability) {
4061 CarrierConfigManager configManager = new CarrierConfigManager(context);
4062 PersistableBundle c = configManager.getConfigForSubId(subId);
4063 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004064 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004065 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4066 false);
4067 boolean requireVoiceVtProvisioning = c.getBoolean(
4068 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4069
4070 // First check to make sure that the capability requires provisioning.
4071 switch (capability) {
4072 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4073 // intentional fallthrough
4074 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4075 if (requireVoiceVtProvisioning) {
4076 // Voice and Video requires provisioning
4077 return true;
4078 }
4079 break;
4080 }
4081 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4082 if (requireUtProvisioning) {
4083 // UT requires provisioning
4084 return true;
4085 }
4086 break;
4087 }
4088 }
4089 return false;
4090 }
4091
allenwtsu99c623b2020-01-03 18:24:23 +08004092 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4093 int capability) {
4094 CarrierConfigManager configManager = new CarrierConfigManager(context);
4095 PersistableBundle c = configManager.getConfigForSubId(subId);
4096
4097 boolean requireRcsProvisioning = c.getBoolean(
4098 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4099
4100 // First check to make sure that the capability requires provisioning.
4101 switch (capability) {
4102 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4103 // intentional fallthrough
4104 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4105 if (requireRcsProvisioning) {
4106 // OPTION or PRESENCE requires provisioning
4107 return true;
4108 }
4109 break;
4110 }
4111 }
4112 return false;
4113 }
4114
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004115 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004116 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004117 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4118 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4119 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004120 enforceReadPrivilegedPermission("getImsProvisioningInt");
4121 final long identity = Binder.clearCallingIdentity();
4122 try {
4123 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004124 int slotId = getSlotIndex(subId);
4125 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4126 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4127 + subId + "' for key:" + key);
4128 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4129 }
4130 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004131 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004132 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4133 + subId + "' for key:" + key);
4134 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004135 } finally {
4136 Binder.restoreCallingIdentity(identity);
4137 }
4138 }
4139
4140 @Override
4141 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004142 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4143 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4144 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004145 enforceReadPrivilegedPermission("getImsProvisioningString");
4146 final long identity = Binder.clearCallingIdentity();
4147 try {
4148 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004149 int slotId = getSlotIndex(subId);
4150 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4151 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4152 + subId + "' for key:" + key);
4153 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4154 }
4155 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004156 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004157 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4158 + subId + "' for key:" + key);
4159 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004160 } finally {
4161 Binder.restoreCallingIdentity(identity);
4162 }
4163 }
4164
4165 @Override
4166 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004167 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4168 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4169 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004170 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4171 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004172 final long identity = Binder.clearCallingIdentity();
4173 try {
4174 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004175 int slotId = getSlotIndex(subId);
4176 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4177 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4178 + subId + "' for key:" + key);
4179 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4180 }
4181 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004182 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004183 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4184 + "' for key:" + key);
4185 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004186 } finally {
4187 Binder.restoreCallingIdentity(identity);
4188 }
4189 }
4190
4191 @Override
4192 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004193 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4194 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4195 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4197 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004198 final long identity = Binder.clearCallingIdentity();
4199 try {
4200 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004201 int slotId = getSlotIndex(subId);
4202 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4203 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4204 + subId + "' for key:" + key);
4205 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4206 }
4207 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004208 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004209 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4210 + "' for key:" + key);
4211 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004212 } finally {
4213 Binder.restoreCallingIdentity(identity);
4214 }
4215 }
4216
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004217 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004218 int slotId = SubscriptionManager.getSlotIndex(subId);
4219 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004220 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4221 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004222 }
4223 return slotId;
4224 }
4225
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004226 private int getSlotIndex(int subId) {
4227 int slotId = SubscriptionManager.getSlotIndex(subId);
4228 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4229 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4230 }
4231 return slotId;
4232 }
4233
Wink Saville36469e72014-06-11 15:17:00 -07004234 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004235 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004236 */
4237 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004238 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4239 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004240 final int targetSdk = getTargetSdk(callingPackage);
4241 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004242 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004243 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004244 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004245 mApp, subId, callingPackage, callingFeatureId,
4246 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004247 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4248 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004249
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004250 final long identity = Binder.clearCallingIdentity();
4251 try {
4252 final Phone phone = getPhone(subId);
4253 if (phone != null) {
4254 return phone.getServiceState().getDataNetworkType();
4255 } else {
4256 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4257 }
4258 } finally {
4259 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004260 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004261 }
4262
4263 /**
4264 * Returns the data network type
4265 */
4266 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004267 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4268 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4269 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004270 }
4271
4272 /**
4273 * Returns the data network type for a subId
4274 */
4275 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004276 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4277 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004278 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004279 mApp, subId, callingPackage, callingFeatureId,
4280 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004281 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4282 }
4283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004284 final long identity = Binder.clearCallingIdentity();
4285 try {
4286 final Phone phone = getPhone(subId);
4287 if (phone != null) {
4288 return phone.getServiceState().getDataNetworkType();
4289 } else {
4290 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4291 }
4292 } finally {
4293 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004295 }
4296
4297 /**
Wink Saville36469e72014-06-11 15:17:00 -07004298 * Returns the Voice network type for a subId
4299 */
4300 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004301 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4302 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004303 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004304 mApp, subId, callingPackage, callingFeatureId,
4305 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004306 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4307 }
4308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004309 final long identity = Binder.clearCallingIdentity();
4310 try {
4311 final Phone phone = getPhone(subId);
4312 if (phone != null) {
4313 return phone.getServiceState().getVoiceNetworkType();
4314 } else {
4315 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4316 }
4317 } finally {
4318 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004319 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004320 }
4321
4322 /**
4323 * @return true if a ICC card is present
4324 */
4325 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004326 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004327 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4328 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004329 }
4330
4331 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004332 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004333 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004334 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004335 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004336 final long identity = Binder.clearCallingIdentity();
4337 try {
4338 final Phone phone = PhoneFactory.getPhone(slotIndex);
4339 if (phone != null) {
4340 return phone.getIccCard().hasIccCard();
4341 } else {
4342 return false;
4343 }
4344 } finally {
4345 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004347 }
4348
4349 /**
4350 * Return if the current radio is LTE on CDMA. This
4351 * is a tri-state return value as for a period of time
4352 * the mode may be unknown.
4353 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004354 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004355 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004356 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004357 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004358 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004359 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4360 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4361 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004362 }
4363
Sanket Padawe356d7632015-06-22 14:03:32 -07004364 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004365 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4366 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004367 try {
4368 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4369 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004370 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4371 }
4372
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004373 final long identity = Binder.clearCallingIdentity();
4374 try {
4375 final Phone phone = getPhone(subId);
4376 if (phone == null) {
4377 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4378 } else {
4379 return phone.getLteOnCdmaMode();
4380 }
4381 } finally {
4382 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004383 }
Wink Saville36469e72014-06-11 15:17:00 -07004384 }
4385
Wink Saville36469e72014-06-11 15:17:00 -07004386 /**
4387 * {@hide}
4388 * Returns Default subId, 0 in the case of single standby.
4389 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004390 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004391 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004392 }
4393
Shishir Agrawala9f32182016-04-12 12:00:16 -07004394 private int getSlotForDefaultSubscription() {
4395 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4396 }
4397
Wink Savilleb564aae2014-10-23 10:18:09 -07004398 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004399 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004400 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004401
Pengquan Menge92a50d2018-09-21 15:54:48 -07004402 private boolean isActiveSubscription(int subId) {
4403 return mSubscriptionController.isActiveSubId(subId);
4404 }
4405
Ihab Awadf2177b72013-11-25 13:33:23 -08004406 /**
4407 * @see android.telephony.TelephonyManager.WifiCallingChoices
4408 */
4409 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004410 final long identity = Binder.clearCallingIdentity();
4411 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004412 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004413 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4414 getWhenToMakeWifiCallsDefaultPreference());
4415 } finally {
4416 Binder.restoreCallingIdentity(identity);
4417 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004418 }
4419
4420 /**
4421 * @see android.telephony.TelephonyManager.WifiCallingChoices
4422 */
4423 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004424 final long identity = Binder.clearCallingIdentity();
4425 try {
4426 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004427 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004428 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4429 } finally {
4430 Binder.restoreCallingIdentity(identity);
4431 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004432 }
4433
Sailesh Nepald1e68152013-12-12 19:08:02 -08004434 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004435 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004436 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004437 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004438
Jordan Liu4c733742019-02-28 12:03:40 -08004439 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4440 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4441 if (phoneId == -1) {
4442 throw new IllegalArgumentException("Given slot index: " + slotIndex
4443 + " does not correspond to an active phone");
4444 }
4445 return PhoneFactory.getPhone(phoneId);
4446 }
4447
Shishir Agrawal566b7612013-10-28 14:41:00 -07004448 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004449 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4450 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4452 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004453 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004454 if (DBG) {
4455 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4456 }
4457 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4458 p2);
4459 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004460
Jordan Liu4c733742019-02-28 12:03:40 -08004461
4462 @Override
4463 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4464 int slotIndex, String callingPackage, String aid, int p2) {
4465 enforceModifyPermission();
4466 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4467 if (DBG) {
4468 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4469 }
4470 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4471 callingPackage, aid, p2);
4472 }
4473
4474 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4475 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004476 final long identity = Binder.clearCallingIdentity();
4477 try {
4478 if (TextUtils.equals(ISDR_AID, aid)) {
4479 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004480 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4481 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004482 if (bestComponent == null
4483 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4484 loge("The calling package is not allowed to access ISD-R.");
4485 throw new SecurityException(
4486 "The calling package is not allowed to access ISD-R.");
4487 }
Derek Tan740e1672017-06-27 14:56:27 -07004488 }
Derek Tan740e1672017-06-27 14:56:27 -07004489
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004490 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004491 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4492 null /* workSource */);
4493 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004494 return response;
4495 } finally {
4496 Binder.restoreCallingIdentity(identity);
4497 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004498 }
4499
4500 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004501 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4503 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004504 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4505 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4506 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004507
Jordan Liu4c733742019-02-28 12:03:40 -08004508 @Override
4509 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4510 enforceModifyPermission();
4511 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4512 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4513 channel);
4514 }
4515
4516 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004517 final long identity = Binder.clearCallingIdentity();
4518 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004519 if (channel < 0) {
4520 return false;
4521 }
Jordan Liu4c733742019-02-28 12:03:40 -08004522 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4523 null /* workSource */);
4524 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004525 return success;
4526 } finally {
4527 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004528 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004529 }
4530
4531 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004532 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004533 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4535 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004536 if (DBG) {
4537 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4538 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4539 + p3 + " data=" + data);
4540 }
4541 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4542 command, p1, p2, p3, data);
4543 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004544
Jordan Liu4c733742019-02-28 12:03:40 -08004545 @Override
4546 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4547 int command, int p1, int p2, int p3, String data) {
4548 enforceModifyPermission();
4549 if (DBG) {
4550 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4551 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4552 + p3 + " data=" + data);
4553 }
4554 return iccTransmitApduLogicalChannelWithPermission(
4555 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4556 data);
4557 }
4558
4559 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4560 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004561 final long identity = Binder.clearCallingIdentity();
4562 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004563 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004564 return "";
4565 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004566
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004567 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004568 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4569 null /* workSource */);
4570 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004572 // Append the returned status code to the end of the response payload.
4573 String s = Integer.toHexString(
4574 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4575 if (response.payload != null) {
4576 s = IccUtils.bytesToHexString(response.payload) + s;
4577 }
4578 return s;
4579 } finally {
4580 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004581 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004582 }
Jake Hambye994d462014-02-03 13:10:13 -08004583
Evan Charltonc66da362014-05-16 14:06:40 -07004584 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004585 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4586 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4588 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004590 if (DBG) {
4591 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4592 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4593 }
4594 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4595 cla, command, p1, p2, p3, data);
4596 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004597
Jordan Liu4c733742019-02-28 12:03:40 -08004598 @Override
4599 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4600 int command, int p1, int p2, int p3, String data) {
4601 enforceModifyPermission();
4602 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4603 if (DBG) {
4604 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4605 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4606 + " data=" + data);
4607 }
4608
4609 return iccTransmitApduBasicChannelWithPermission(
4610 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4611 p2, p3, data);
4612 }
4613
4614 // open APDU basic channel assuming the caller has sufficient permissions
4615 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4616 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004617 final long identity = Binder.clearCallingIdentity();
4618 try {
4619 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4620 && TextUtils.equals(ISDR_AID, data)) {
4621 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004622 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4623 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004624 if (bestComponent == null
4625 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4626 loge("The calling package is not allowed to select ISD-R.");
4627 throw new SecurityException(
4628 "The calling package is not allowed to select ISD-R.");
4629 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004630 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004631
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004632 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004633 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4634 null /* workSource */);
4635 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004637 // Append the returned status code to the end of the response payload.
4638 String s = Integer.toHexString(
4639 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4640 if (response.payload != null) {
4641 s = IccUtils.bytesToHexString(response.payload) + s;
4642 }
4643 return s;
4644 } finally {
4645 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004646 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004647 }
4648
4649 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004650 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004651 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4653 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004654
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004655 final long identity = Binder.clearCallingIdentity();
4656 try {
4657 if (DBG) {
4658 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4659 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4660 }
4661
4662 IccIoResult response =
4663 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4664 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4665 subId);
4666
4667 if (DBG) {
4668 log("Exchange SIM_IO [R]" + response);
4669 }
4670
4671 byte[] result = null;
4672 int length = 2;
4673 if (response.payload != null) {
4674 length = 2 + response.payload.length;
4675 result = new byte[length];
4676 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4677 } else {
4678 result = new byte[length];
4679 }
4680
4681 result[length - 1] = (byte) response.sw2;
4682 result[length - 2] = (byte) response.sw1;
4683 return result;
4684 } finally {
4685 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004686 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004687 }
4688
Nathan Haroldb3014052017-01-25 15:57:32 -08004689 /**
4690 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4691 * on a particular subscription
4692 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004693 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4694 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004695 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004696 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004697 return null;
4698 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004699
4700 final long identity = Binder.clearCallingIdentity();
4701 try {
4702 if (appType != TelephonyManager.APPTYPE_USIM
4703 && appType != TelephonyManager.APPTYPE_SIM) {
4704 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4705 return null;
4706 }
4707 Object response = sendRequest(
4708 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4709 if (response instanceof String[]) {
4710 return (String[]) response;
4711 }
yincheng zhao2737e882019-09-06 17:06:54 -07004712 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004713 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004714 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004715 } finally {
4716 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004717 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004718 }
4719
yincheng zhao2737e882019-09-06 17:06:54 -07004720 /**
4721 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4722 * subscription.
4723 *
4724 * @param subId the id of the subscription.
4725 * @param appType the uicc app type, must be USIM or SIM.
4726 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4727 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004728 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004729 * @return number of fplmns that is successfully written to the SIM.
4730 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004731 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4732 String callingFeatureId) {
4733 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4734 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004735 if (DBG) logv("no permissions for setForbiddenplmns");
4736 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4737 }
4738 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4739 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4740 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4741 }
4742 if (fplmns == null) {
4743 throw new IllegalArgumentException("Fplmn List provided is null");
4744 }
4745 for (String fplmn : fplmns) {
4746 if (!CellIdentity.isValidPlmn(fplmn)) {
4747 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4748 }
4749 }
4750 final long identity = Binder.clearCallingIdentity();
4751 try {
4752 Object response = sendRequest(
4753 CMD_SET_FORBIDDEN_PLMNS,
4754 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4755 subId);
4756 return (int) response;
4757 } finally {
4758 Binder.restoreCallingIdentity(identity);
4759 }
4760 }
4761
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004762 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004763 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004764 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4765 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004766
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004767 final long identity = Binder.clearCallingIdentity();
4768 try {
4769 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4770 if (response.payload == null) {
4771 return "";
4772 }
Evan Charltonc66da362014-05-16 14:06:40 -07004773
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004774 // Append the returned status code to the end of the response payload.
4775 String s = Integer.toHexString(
4776 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4777 s = IccUtils.bytesToHexString(response.payload) + s;
4778 return s;
4779 } finally {
4780 Binder.restoreCallingIdentity(identity);
4781 }
Evan Charltonc66da362014-05-16 14:06:40 -07004782 }
4783
Jake Hambye994d462014-02-03 13:10:13 -08004784 /**
4785 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4786 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4787 *
4788 * @param itemID the ID of the item to read
4789 * @return the NV item as a String, or null on error.
4790 */
4791 @Override
4792 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004793 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4795 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004796
4797 final long identity = Binder.clearCallingIdentity();
4798 try {
4799 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004800 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004801 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4802 return value;
4803 } finally {
4804 Binder.restoreCallingIdentity(identity);
4805 }
Jake Hambye994d462014-02-03 13:10:13 -08004806 }
4807
4808 /**
4809 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4810 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4811 *
4812 * @param itemID the ID of the item to read
4813 * @param itemValue the value to write, as a String
4814 * @return true on success; false on any failure
4815 */
4816 @Override
4817 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004818 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4820 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004821
4822 final long identity = Binder.clearCallingIdentity();
4823 try {
4824 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4825 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004826 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004827 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4828 return success;
4829 } finally {
4830 Binder.restoreCallingIdentity(identity);
4831 }
Jake Hambye994d462014-02-03 13:10:13 -08004832 }
4833
4834 /**
4835 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4836 * Used for device configuration by some CDMA operators.
4837 *
4838 * @param preferredRoamingList byte array containing the new PRL
4839 * @return true on success; false on any failure
4840 */
4841 @Override
4842 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4844 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004845
4846 final long identity = Binder.clearCallingIdentity();
4847 try {
4848 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4849 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4850 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4851 return success;
4852 } finally {
4853 Binder.restoreCallingIdentity(identity);
4854 }
Jake Hambye994d462014-02-03 13:10:13 -08004855 }
4856
4857 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004858 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004859 * Used for device configuration by some CDMA operators.
4860 *
chen xu6dac5ab2018-10-26 17:39:23 -07004861 * @param slotIndex - device slot.
4862 *
Jake Hambye994d462014-02-03 13:10:13 -08004863 * @return true on success; false on any failure
4864 */
4865 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004866 public boolean resetModemConfig(int slotIndex) {
4867 Phone phone = PhoneFactory.getPhone(slotIndex);
4868 if (phone != null) {
4869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4870 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004871
chen xu6dac5ab2018-10-26 17:39:23 -07004872 final long identity = Binder.clearCallingIdentity();
4873 try {
4874 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4875 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4876 return success;
4877 } finally {
4878 Binder.restoreCallingIdentity(identity);
4879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004880 }
chen xu6dac5ab2018-10-26 17:39:23 -07004881 return false;
4882 }
4883
4884 /**
4885 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4886 *
4887 * @param slotIndex - device slot.
4888 *
4889 * @return true on success; false on any failure
4890 */
4891 @Override
4892 public boolean rebootModem(int slotIndex) {
4893 Phone phone = PhoneFactory.getPhone(slotIndex);
4894 if (phone != null) {
4895 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4896 mApp, phone.getSubId(), "rebootModem");
4897
4898 final long identity = Binder.clearCallingIdentity();
4899 try {
4900 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4901 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4902 return success;
4903 } finally {
4904 Binder.restoreCallingIdentity(identity);
4905 }
4906 }
4907 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004908 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004909
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004910 public String[] getPcscfAddress(String apnType, String callingPackage,
4911 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004912 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004913 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4914 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004915 return new String[0];
4916 }
4917
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004918 final long identity = Binder.clearCallingIdentity();
4919 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004920 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004921 } finally {
4922 Binder.restoreCallingIdentity(identity);
4923 }
Wink Saville36469e72014-06-11 15:17:00 -07004924 }
4925
Brad Ebinger51f743a2017-01-23 13:50:20 -08004926 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004927 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4928 * {@link #disableIms(int)}.
4929 * @param slotIndex device slot.
4930 */
4931 public void resetIms(int slotIndex) {
4932 enforceModifyPermission();
4933
4934 final long identity = Binder.clearCallingIdentity();
4935 try {
4936 if (mImsResolver == null) {
4937 // may happen if the does not support IMS.
4938 return;
4939 }
4940 mImsResolver.disableIms(slotIndex);
4941 mImsResolver.enableIms(slotIndex);
4942 } finally {
4943 Binder.restoreCallingIdentity(identity);
4944 }
4945 }
4946
4947 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004948 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4949 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004950 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004951 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004952 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004953
4954 final long identity = Binder.clearCallingIdentity();
4955 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004956 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004957 // may happen if the device does not support IMS.
4958 return;
4959 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004960 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004961 } finally {
4962 Binder.restoreCallingIdentity(identity);
4963 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004964 }
4965
4966 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004967 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4968 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004969 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004970 public void disableIms(int slotId) {
4971 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004972
4973 final long identity = Binder.clearCallingIdentity();
4974 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004975 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004976 // may happen if the device does not support IMS.
4977 return;
4978 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004979 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004980 } finally {
4981 Binder.restoreCallingIdentity(identity);
4982 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004983 }
4984
4985 /**
4986 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4987 * feature or {@link null} if the service is not available. If the feature is available, the
4988 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4989 */
4990 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004991 IImsServiceFeatureCallback callback) {
4992 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993
4994 final long identity = Binder.clearCallingIdentity();
4995 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004996 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004997 // may happen if the device does not support IMS.
4998 return null;
4999 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005000 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001 } finally {
5002 Binder.restoreCallingIdentity(identity);
5003 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005004 }
5005
5006 /**
5007 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
5008 * feature during emergency calling or {@link null} if the service is not available. If the
5009 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5010 * listener for feature updates.
5011 */
5012 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5013 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005014
5015 final long identity = Binder.clearCallingIdentity();
5016 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005017 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005018 // may happen if the device does not support IMS.
5019 return null;
5020 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005021 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005022 } finally {
5023 Binder.restoreCallingIdentity(identity);
5024 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005025 }
5026
Brad Ebinger5f64b052017-12-14 14:26:15 -08005027 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005028 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5029 */
5030 public void unregisterImsFeatureCallback(int slotId, int featureType,
5031 IImsServiceFeatureCallback callback) {
5032 enforceModifyPermission();
5033
5034 final long identity = Binder.clearCallingIdentity();
5035 try {
5036 if (mImsResolver == null) return;
5037 mImsResolver.unregisterImsFeatureCallback(slotId, featureType, callback);
5038 } finally {
5039 Binder.restoreCallingIdentity(identity);
5040 }
5041 }
5042
5043 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005044 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005045 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005046 */
5047 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5048 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005049
5050 final long identity = Binder.clearCallingIdentity();
5051 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005052 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005053 // may happen if the device does not support IMS.
5054 return null;
5055 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005056 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005057 } finally {
5058 Binder.restoreCallingIdentity(identity);
5059 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005060 }
5061
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005062 /**
5063 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005064 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005065 */
5066 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5067 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005068
5069 final long identity = Binder.clearCallingIdentity();
5070 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005071 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005072 // may happen if the device does not support IMS.
5073 return null;
5074 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005075 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005076 } finally {
5077 Binder.restoreCallingIdentity(identity);
5078 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005079 }
5080
Brad Ebinger884c07b2018-02-15 16:17:40 -08005081 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005082 * Sets the ImsService Package Name that Telephony will bind to.
5083 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005084 * @param slotIndex the slot ID that the ImsService should bind for.
5085 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005086 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005087 * @param featureTypes An integer array of feature types associated with a packageName.
5088 * @param packageName The name of the package that the current configuration will be replaced
5089 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005090 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005091 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005092 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5093 int[] featureTypes, String packageName) {
5094 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5095 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5097 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005098 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005099
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005100 final long identity = Binder.clearCallingIdentity();
5101 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005102 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005103 // may happen if the device does not support IMS.
5104 return false;
5105 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005106 Map<Integer, String> featureConfig = new HashMap<>();
5107 for (int featureType : featureTypes) {
5108 featureConfig.put(featureType, packageName);
5109 }
5110 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5111 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005112 } finally {
5113 Binder.restoreCallingIdentity(identity);
5114 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005115 }
5116
5117 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005118 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005119 *
5120 * @param slotId The slot that the ImsService is associated with.
5121 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5122 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005123 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005124 * @return the package name of the ImsService configuration.
5125 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005126 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5127 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005128 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005129 TelephonyPermissions
5130 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5131 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5132 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005133
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005134 final long identity = Binder.clearCallingIdentity();
5135 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005136 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005137 // may happen if the device does not support IMS.
5138 return "";
5139 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005140 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005141 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5142 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005143 } finally {
5144 Binder.restoreCallingIdentity(identity);
5145 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005146 }
5147
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005148 /**
5149 * Get the MmTelFeature state associated with the requested subscription id.
5150 * @param subId The subscription that the MmTelFeature is associated with.
5151 * @param callback A callback with an integer containing the
5152 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5153 */
5154 @Override
5155 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5156 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5157 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5158 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5159 "IMS not available on device.");
5160 }
5161 final long token = Binder.clearCallingIdentity();
5162 try {
5163 int slotId = getSlotIndex(subId);
5164 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5165 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5166 + subId + "'");
5167 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5168 }
5169 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5170 try {
5171 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5172 } catch (RemoteException e) {
5173 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5174 + "Ignore");
5175 }
5176 });
5177 } finally {
5178 Binder.restoreCallingIdentity(token);
5179 }
5180 }
5181
Wink Saville36469e72014-06-11 15:17:00 -07005182 public void setImsRegistrationState(boolean registered) {
5183 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005184
5185 final long identity = Binder.clearCallingIdentity();
5186 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005187 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005188 } finally {
5189 Binder.restoreCallingIdentity(identity);
5190 }
Wink Saville36469e72014-06-11 15:17:00 -07005191 }
5192
5193 /**
Stuart Scott54788802015-03-30 13:18:01 -07005194 * Set the network selection mode to automatic.
5195 *
5196 */
5197 @Override
5198 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005199 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5200 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201
5202 final long identity = Binder.clearCallingIdentity();
5203 try {
shilufc958392020-01-20 11:36:01 -08005204 if (!isActiveSubscription(subId)) {
5205 return;
5206 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5208 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5209 } finally {
5210 Binder.restoreCallingIdentity(identity);
5211 }
Stuart Scott54788802015-03-30 13:18:01 -07005212 }
5213
Pengquan Mengea84e042018-09-20 14:57:26 -07005214 /**
5215 * Ask the radio to connect to the input network and change selection mode to manual.
5216 *
5217 * @param subId the id of the subscription.
5218 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5219 * the operator to attach to.
5220 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5221 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5222 * normal network selection next time.
5223 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005224 */
5225 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005226 public boolean setNetworkSelectionModeManual(
5227 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5229 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005230
5231 if (!isActiveSubscription(subId)) {
5232 return false;
5233 }
5234
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 final long identity = Binder.clearCallingIdentity();
5236 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005237 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005239 if (DBG) {
5240 log("setNetworkSelectionModeManual: subId: " + subId
5241 + " operator: " + operatorInfo);
5242 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5244 } finally {
5245 Binder.restoreCallingIdentity(identity);
5246 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005247 }
shilu84f6e8b2019-12-19 13:58:01 -08005248 /**
5249 * Get the manual network selection
5250 *
5251 * @param subId the id of the subscription.
5252 *
5253 * @return the previously saved user selected PLMN
5254 */
5255 @Override
5256 public String getManualNetworkSelectionPlmn(int subId) {
5257 TelephonyPermissions
5258 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5259 mApp, subId, "getManualNetworkSelectionPlmn");
5260
5261 final long identity = Binder.clearCallingIdentity();
5262 try {
5263 if (!isActiveSubscription(subId)) {
5264 return "";
5265 }
5266
5267 final Phone phone = getPhone(subId);
5268 if (phone == null) {
5269 return "";
5270 }
5271 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5272 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5273 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5274 } finally {
5275 Binder.restoreCallingIdentity(identity);
5276 }
5277 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005278
5279 /**
5280 * Scans for available networks.
5281 */
5282 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005283 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5284 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5286 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005287 LocationAccessPolicy.LocationPermissionResult locationResult =
5288 LocationAccessPolicy.checkLocationPermission(mApp,
5289 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5290 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005291 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005292 .setCallingPid(Binder.getCallingPid())
5293 .setCallingUid(Binder.getCallingUid())
5294 .setMethod("getCellNetworkScanResults")
5295 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5296 .build());
5297 switch (locationResult) {
5298 case DENIED_HARD:
5299 throw new SecurityException("Not allowed to access scan results -- location");
5300 case DENIED_SOFT:
5301 return null;
5302 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005303
Pengquan Menga1bb6272018-09-06 09:59:22 -07005304 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005305 try {
5306 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005307 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005308 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005309 } finally {
5310 Binder.restoreCallingIdentity(identity);
5311 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005312 }
5313
5314 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005315 * Get the call forwarding info, given the call forwarding reason.
5316 */
5317 @Override
5318 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5319 enforceReadPrivilegedPermission("getCallForwarding");
5320 long identity = Binder.clearCallingIdentity();
5321 try {
5322 if (DBG) {
5323 log("getCallForwarding: subId " + subId
5324 + " callForwardingReason" + callForwardingReason);
5325 }
5326 return (CallForwardingInfo) sendRequest(
5327 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5328 } finally {
5329 Binder.restoreCallingIdentity(identity);
5330 }
5331 }
5332
5333 /**
5334 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5335 * reason, the number to forward, and the timeout before the forwarding is attempted.
5336 */
5337 @Override
5338 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5339 enforceModifyPermission();
5340 long identity = Binder.clearCallingIdentity();
5341 try {
5342 if (DBG) {
5343 log("setCallForwarding: subId " + subId
5344 + " callForwardingInfo" + callForwardingInfo);
5345 }
5346 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5347 } finally {
5348 Binder.restoreCallingIdentity(identity);
5349 }
5350 }
5351
5352 /**
5353 * Get the call forwarding info, given the call forwarding reason.
5354 */
5355 @Override
5356 public int getCallWaitingStatus(int subId) {
5357 enforceReadPrivilegedPermission("getCallForwarding");
5358 long identity = Binder.clearCallingIdentity();
5359 try {
5360 if (DBG) log("getCallWaitingStatus: subId " + subId);
5361 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5362 } finally {
5363 Binder.restoreCallingIdentity(identity);
5364 }
5365 }
5366
5367 /**
5368 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5369 * reason, the number to forward, and the timeout before the forwarding is attempted.
5370 */
5371 @Override
5372 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5373 enforceModifyPermission();
5374 long identity = Binder.clearCallingIdentity();
5375 try {
5376 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5377 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5378 } finally {
5379 Binder.restoreCallingIdentity(identity);
5380 }
5381 }
5382
5383 /**
yinxub1bed742017-04-17 11:45:04 -07005384 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005385 *
yinxub1bed742017-04-17 11:45:04 -07005386 * @param subId id of the subscription
5387 * @param request contains the radio access networks with bands/channels to scan
5388 * @param messenger callback messenger for scan results or errors
5389 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005390 * @return the id of the requested scan which can be used to stop the scan.
5391 */
5392 @Override
5393 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005394 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5396 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005397 LocationAccessPolicy.LocationPermissionResult locationResult =
5398 LocationAccessPolicy.checkLocationPermission(mApp,
5399 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5400 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005401 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005402 .setCallingPid(Binder.getCallingPid())
5403 .setCallingUid(Binder.getCallingUid())
5404 .setMethod("requestNetworkScan")
5405 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5406 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005407 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005408 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5409 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005410 if (e != null) {
5411 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5412 throw e;
5413 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005414 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005415 return TelephonyScanManager.INVALID_SCAN_ID;
5416 }
5417 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418 }
Hall Liu912dfd32019-04-25 14:02:26 -07005419 int callingUid = Binder.getCallingUid();
5420 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005421 final long identity = Binder.clearCallingIdentity();
5422 try {
5423 return mNetworkScanRequestTracker.startNetworkScan(
5424 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005425 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005426 } finally {
5427 Binder.restoreCallingIdentity(identity);
5428 }
yinxu504e1392017-04-12 16:03:22 -07005429 }
5430
Hall Liub2ac8ef2019-02-28 15:56:23 -08005431 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005432 NetworkScanRequest request, int subId, String callingPackage) {
5433 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005434 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5435 boolean hasNetworkScanPermission =
5436 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5437 == PERMISSION_GRANTED;
5438
5439 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5440 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5441 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005442 }
5443
5444 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5445 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005446 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5447 return new SecurityException("Specific channels must not be"
5448 + " scanned without location access.");
5449 }
5450 }
5451 }
5452
Hall Liub2ac8ef2019-02-28 15:56:23 -08005453 return null;
5454 }
5455
yinxu504e1392017-04-12 16:03:22 -07005456 /**
5457 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005458 *
5459 * @param subId id of the subscription
5460 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005461 */
5462 @Override
5463 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5465 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466
Hall Liu912dfd32019-04-25 14:02:26 -07005467 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005468 final long identity = Binder.clearCallingIdentity();
5469 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005470 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471 } finally {
5472 Binder.restoreCallingIdentity(identity);
5473 }
yinxu504e1392017-04-12 16:03:22 -07005474 }
5475
5476 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005477 * Get the calculated preferred network type.
5478 * Used for debugging incorrect network type.
5479 *
5480 * @return the preferred network type, defined in RILConstants.java.
5481 */
5482 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005483 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005484 final Phone defaultPhone = getDefaultPhone();
5485 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005486 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005487 return RILConstants.PREFERRED_NETWORK_MODE;
5488 }
5489
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490 final long identity = Binder.clearCallingIdentity();
5491 try {
5492 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005493 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494 } finally {
5495 Binder.restoreCallingIdentity(identity);
5496 }
Junda Liu84d15a22014-07-02 11:21:04 -07005497 }
5498
5499 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005500 * Get the preferred network type.
5501 * Used for device configuration by some CDMA operators.
5502 *
5503 * @return the preferred network type, defined in RILConstants.java.
5504 */
5505 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005506 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005507 TelephonyPermissions
5508 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5509 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510
5511 final long identity = Binder.clearCallingIdentity();
5512 try {
5513 if (DBG) log("getPreferredNetworkType");
5514 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5515 int networkType = (result != null ? result[0] : -1);
5516 if (DBG) log("getPreferredNetworkType: " + networkType);
5517 return networkType;
5518 } finally {
5519 Binder.restoreCallingIdentity(identity);
5520 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005521 }
5522
5523 /**
5524 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005525 *
5526 * @param networkType the preferred network type, defined in RILConstants.java.
5527 * @return true on success; false on any failure.
5528 */
5529 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005530 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5532 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533
5534 final long identity = Binder.clearCallingIdentity();
5535 try {
calvinpan8ed33732020-03-12 14:17:55 +08005536 Boolean success = (Boolean) sendRequest(
5537 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005538
5539 if (success) {
5540 Settings.Global.putInt(mApp.getContentResolver(),
5541 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5542 }
calvinpan8ed33732020-03-12 14:17:55 +08005543 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5544 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005545 } finally {
5546 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005547 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005548 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005549
5550 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005551 * Get the allowed network types that store in the telephony provider.
5552 *
5553 * @param subId the id of the subscription.
5554 * @return allowedNetworkTypes the allowed network types.
5555 */
5556 @Override
5557 public long getAllowedNetworkTypes(int subId) {
5558 TelephonyPermissions
5559 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5560 mApp, subId, "getAllowedNetworkTypes");
5561
5562 final long identity = Binder.clearCallingIdentity();
5563 try {
5564 return SubscriptionManager.getLongSubscriptionProperty(
5565 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5566 } finally {
5567 Binder.restoreCallingIdentity(identity);
5568 }
5569 }
5570
5571 /**
5572 * Set the allowed network types.
5573 *
5574 * @param subId the id of the subscription.
5575 * @param allowedNetworkTypes the allowed network types.
5576 * @return true on success; false on any failure.
5577 */
5578 @Override
5579 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5581 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005582
calvinpan8ed33732020-03-12 14:17:55 +08005583 SubscriptionManager.setSubscriptionProperty(subId,
5584 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5585 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005586
calvinpan8ed33732020-03-12 14:17:55 +08005587 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5588 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5589 RILConstants.PREFERRED_NETWORK_MODE);
5590 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005591 }
5592
5593 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005594 * Get the allowed network types for certain reason.
5595 *
5596 * @param subId the id of the subscription.
5597 * @param reason the reason the allowed network type change is taking place
5598 * @return the allowed network types.
5599 */
5600 @Override
5601 public long getAllowedNetworkTypesForReason(int subId,
5602 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5603 TelephonyPermissions
5604 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5605 mApp, subId, "getAllowedNetworkTypesForReason");
5606 final long identity = Binder.clearCallingIdentity();
5607 try {
5608 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5609 } finally {
5610 Binder.restoreCallingIdentity(identity);
5611 }
5612 }
5613
5614 /**
5615 * Get the effective allowed network types on the device.
5616 * This API will return an intersection of allowed network types for all reasons,
5617 * including the configuration done through setAllowedNetworkTypes
5618 *
5619 * @param subId the id of the subscription.
5620 * @return the allowed network types
5621 */
5622 @Override
5623 public long getEffectiveAllowedNetworkTypes(int subId) {
5624 TelephonyPermissions
5625 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5626 mApp, subId, "getEffectiveAllowedNetworkTypes");
5627 final long identity = Binder.clearCallingIdentity();
5628 try {
5629 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5630 } finally {
5631 Binder.restoreCallingIdentity(identity);
5632 }
5633 }
5634
5635 /**
5636 * Set the allowed network types of the device and
5637 * provide the reason triggering the allowed network change.
5638 *
5639 * @param subId the id of the subscription.
5640 * @param reason the reason the allowed network type change is taking place
5641 * @param allowedNetworkTypes the allowed network types.
5642 * @return true on success; false on any failure.
5643 */
5644 @Override
5645 public boolean setAllowedNetworkTypesForReason(int subId,
5646 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5648 mApp, subId, "setAllowedNetworkTypesForReason");
5649 final long identity = Binder.clearCallingIdentity();
5650 try {
5651 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5652 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5653 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5654 RILConstants.PREFERRED_NETWORK_MODE);
5655 return setPreferredNetworkType(subId, preferredNetworkMode);
5656 } finally {
5657 Binder.restoreCallingIdentity(identity);
5658 }
5659 }
5660
5661 /**
Miaoa84611c2019-03-15 09:21:10 +08005662 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005663 *
Miaoa84611c2019-03-15 09:21:10 +08005664 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005665 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005666 * @hide
5667 */
5668 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005669 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005670 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005671 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005672 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673 try {
Miaoa84611c2019-03-15 09:21:10 +08005674 if (phone != null) {
5675 return phone.hasMatchedTetherApnSetting();
5676 } else {
5677 return false;
5678 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679 } finally {
5680 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005681 }
Junda Liu475951f2014-11-07 16:45:03 -08005682 }
5683
5684 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005685 * Set mobile data enabled
5686 * Used by the user through settings etc to turn on/off mobile data
5687 *
5688 * @param enable {@code true} turn turn data on, else {@code false}
5689 */
5690 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005691 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5693 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694
5695 final long identity = Binder.clearCallingIdentity();
5696 try {
5697 int phoneId = mSubscriptionController.getPhoneId(subId);
5698 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5699 Phone phone = PhoneFactory.getPhone(phoneId);
5700 if (phone != null) {
5701 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005702 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005704 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705 }
5706 } finally {
5707 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005708 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005709 }
5710
5711 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005712 * Enable or disable always reporting signal strength changes from radio.
5713 *
5714 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5715 */
5716 @Override
5717 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5718 enforceModifyPermission();
5719 enforceSystemCaller();
5720
5721 final long identity = Binder.clearCallingIdentity();
5722 final Phone phone = getPhone(subId);
5723 try {
5724 if (phone != null) {
5725 if (DBG) {
5726 log("setAlwaysReportSignalStrength: subId=" + subId
5727 + " isEnable=" + isEnable);
5728 }
5729 phone.setAlwaysReportSignalStrength(isEnable);
5730 } else {
5731 loge("setAlwaysReportSignalStrength: no phone found for subId="
5732 + subId);
5733 }
5734 } finally {
5735 Binder.restoreCallingIdentity(identity);
5736 }
5737 }
5738
5739 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005740 * Get the user enabled state of Mobile Data.
5741 *
5742 * TODO: remove and use isUserDataEnabled.
5743 * This can't be removed now because some vendor codes
5744 * calls through ITelephony directly while they should
5745 * use TelephonyManager.
5746 *
5747 * @return true on enabled
5748 */
5749 @Override
5750 public boolean getDataEnabled(int subId) {
5751 return isUserDataEnabled(subId);
5752 }
5753
5754 /**
5755 * Get whether mobile data is enabled per user setting.
5756 *
5757 * There are other factors deciding whether mobile data is actually enabled, but they are
5758 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005759 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005760 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005761 *
5762 * @return {@code true} if data is enabled else {@code false}
5763 */
5764 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005765 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005766 try {
5767 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5768 null);
5769 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5771 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005772 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773
5774 final long identity = Binder.clearCallingIdentity();
5775 try {
5776 int phoneId = mSubscriptionController.getPhoneId(subId);
5777 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5778 Phone phone = PhoneFactory.getPhone(phoneId);
5779 if (phone != null) {
5780 boolean retVal = phone.isUserDataEnabled();
5781 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5782 return retVal;
5783 } else {
5784 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5785 return false;
5786 }
5787 } finally {
5788 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005789 }
5790 }
5791
5792 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005793 * Checks if the device is capable of mobile data by considering whether whether the
5794 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5795 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005796 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005797 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005798 */
5799 @Override
5800 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005801 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005802
5803 final long identity = Binder.clearCallingIdentity();
5804 try {
5805 int phoneId = mSubscriptionController.getPhoneId(subId);
5806 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5807 Phone phone = PhoneFactory.getPhone(phoneId);
5808 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005809 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005810 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5811 return retVal;
5812 } else {
5813 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5814 return false;
5815 }
5816 } finally {
5817 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005818 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005819 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005820
Malcolm Chen6a13f2a2020-02-24 15:12:43 -08005821 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005822 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07005823 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
5824 // Skip the check if it's one of these special uids
5825 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5826 }
5827
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005828 //load access rules from carrier configs, and check those as well: b/139133814
5829 SubscriptionController subController = SubscriptionController.getInstance();
5830 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5831 || subController == null) return privilegeFromSim;
5832
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005833 PackageManager pkgMgr = phone.getContext().getPackageManager();
5834 String[] packages = pkgMgr.getPackagesForUid(uid);
5835
5836 final long identity = Binder.clearCallingIdentity();
5837 try {
5838 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5839 SubscriptionManager subManager = (SubscriptionManager)
5840 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5841 for (String pkg : packages) {
5842 if (subManager.canManageSubscription(subInfo, pkg)) {
5843 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5844 }
5845 }
5846 return privilegeFromSim;
5847 } finally {
5848 Binder.restoreCallingIdentity(identity);
5849 }
5850 }
5851
5852 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5853 String pkgName) {
5854 //load access rules from carrier configs, and check those as well: b/139133814
5855 SubscriptionController subController = SubscriptionController.getInstance();
5856 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5857 || subController == null) return privilegeFromSim;
5858
5859 final long identity = Binder.clearCallingIdentity();
5860 try {
5861 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5862 SubscriptionManager subManager = (SubscriptionManager)
5863 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5864 return subManager.canManageSubscription(subInfo, pkgName)
5865 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5866 } finally {
5867 Binder.restoreCallingIdentity(identity);
5868 }
5869 }
5870
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005871 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005872 public int getCarrierPrivilegeStatus(int subId) {
5873 final Phone phone = getPhone(subId);
5874 if (phone == null) {
5875 loge("getCarrierPrivilegeStatus: Invalid subId");
5876 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5877 }
5878 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005879 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005880 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005881 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5882 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005883
5884 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5885 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chen6a13f2a2020-02-24 15:12:43 -08005886 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005887 }
Junda Liu29340342014-07-10 15:23:27 -07005888
5889 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005890 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005891 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005892 final Phone phone = getPhone(subId);
5893 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005894 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005895 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5896 }
5897 UiccProfile profile =
5898 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5899 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005900 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005901 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5902 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005903 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005904 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chen6a13f2a2020-02-24 15:12:43 -08005905 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005906 }
5907
5908 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005909 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5910 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005911 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005912 }
5913
5914 int phoneId = SubscriptionManager.getPhoneId(subId);
5915 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005916 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005917 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005918 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5919 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005920 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5921 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5922 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005923 }
5924
5925 @Override
5926 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005927 if (TextUtils.isEmpty(pkgName))
5928 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005929 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5930 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5931 UiccCard card = UiccController.getInstance().getUiccCard(i);
5932 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005933 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005934 continue;
5935 }
5936
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005937 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5938 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5939 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005940 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5941 break;
5942 }
5943 }
5944
5945 return result;
Junda Liu29340342014-07-10 15:23:27 -07005946 }
Derek Tan89e89d42014-07-08 17:00:10 -07005947
5948 @Override
Junda Liue64de782015-04-16 17:19:16 -07005949 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5950 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5951 loge("phoneId " + phoneId + " is not valid.");
5952 return null;
5953 }
5954 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005955 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005956 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005957 return null ;
5958 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005959 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005960 }
5961
Amith Yamasani6e118872016-02-19 12:53:51 -08005962 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005963 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005964 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005965 List<String> privilegedPackages = new ArrayList<>();
5966 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005967 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5968 // has UICC in that slot.
5969 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005970 if (card.hasCarrierPrivilegeRules()) {
5971 if (packages == null) {
5972 // Only check packages in user 0 for now
5973 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005974 PackageManager.MATCH_DISABLED_COMPONENTS
5975 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005976 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08005977 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005978 }
5979 for (int p = packages.size() - 1; p >= 0; p--) {
5980 PackageInfo pkgInfo = packages.get(p);
5981 if (pkgInfo != null && pkgInfo.packageName != null
5982 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005983 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005984 privilegedPackages.add(pkgInfo.packageName);
5985 }
5986 }
5987 }
5988 }
5989 return privilegedPackages;
5990 }
5991
chen xuf7e9fe82019-05-09 19:31:02 -07005992 @Override
5993 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005994 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5995
5996 final long identity = Binder.clearCallingIdentity();
5997
chen xuf7e9fe82019-05-09 19:31:02 -07005998 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005999 try {
6000 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6001 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6002 }
6003 } finally {
6004 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006005 }
6006 return privilegedPackages;
6007 }
6008
Wink Savilleb564aae2014-10-23 10:18:09 -07006009 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006010 final Phone phone = getPhone(subId);
6011 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006012 if (card == null) {
6013 loge("getIccId: No UICC");
6014 return null;
6015 }
6016 String iccId = card.getIccId();
6017 if (TextUtils.isEmpty(iccId)) {
6018 loge("getIccId: ICC ID is null or empty.");
6019 return null;
6020 }
6021 return iccId;
6022 }
6023
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006024 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006025 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6026 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006027 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006028 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006029
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030 final long identity = Binder.clearCallingIdentity();
6031 try {
6032 final String iccId = getIccId(subId);
6033 final Phone phone = getPhone(subId);
6034 if (phone == null) {
6035 return false;
6036 }
6037 final String subscriberId = phone.getSubscriberId();
6038
6039 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006040 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006041 + subscriberId + " to " + number);
6042 }
6043
6044 if (TextUtils.isEmpty(iccId)) {
6045 return false;
6046 }
6047
6048 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6049
6050 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6051 if (alphaTag == null) {
6052 editor.remove(alphaTagPrefKey);
6053 } else {
6054 editor.putString(alphaTagPrefKey, alphaTag);
6055 }
6056
6057 // Record both the line number and IMSI for this ICCID, since we need to
6058 // track all merged IMSIs based on line number
6059 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6060 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6061 if (number == null) {
6062 editor.remove(numberPrefKey);
6063 editor.remove(subscriberPrefKey);
6064 } else {
6065 editor.putString(numberPrefKey, number);
6066 editor.putString(subscriberPrefKey, subscriberId);
6067 }
6068
6069 editor.commit();
6070 return true;
6071 } finally {
6072 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006073 }
Derek Tan7226c842014-07-02 17:42:23 -07006074 }
6075
6076 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006077 public String getLine1NumberForDisplay(int subId, String callingPackage,
6078 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006079 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006080 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006081 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006082 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006083 return null;
6084 }
Derek Tan97ebb422014-09-05 16:55:38 -07006085
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006086 final long identity = Binder.clearCallingIdentity();
6087 try {
6088 String iccId = getIccId(subId);
6089 if (iccId != null) {
6090 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6091 if (DBG_MERGE) {
6092 log("getLine1NumberForDisplay returning "
6093 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6094 }
6095 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006096 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006097 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6098 return null;
6099 } finally {
6100 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006101 }
Derek Tan7226c842014-07-02 17:42:23 -07006102 }
6103
6104 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006105 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6106 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006107 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006108 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006109 return null;
6110 }
Derek Tan97ebb422014-09-05 16:55:38 -07006111
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112 final long identity = Binder.clearCallingIdentity();
6113 try {
6114 String iccId = getIccId(subId);
6115 if (iccId != null) {
6116 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6117 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6118 }
6119 return null;
6120 } finally {
6121 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006122 }
Derek Tan7226c842014-07-02 17:42:23 -07006123 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006124
6125 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006126 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6127 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006128 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6129 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006131 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006132 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006133 return null;
6134 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006135
Jordan Liub49b04b2019-05-06 14:45:15 -07006136 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6137 // the process, where TelephonyManager was instantiated.
6138 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006139 final long identity = Binder.clearCallingIdentity();
6140 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006141 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006142 final TelephonyManager tele = TelephonyManager.from(context);
6143 final SubscriptionManager sub = SubscriptionManager.from(context);
6144
6145 // Figure out what subscribers are currently active
6146 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006147
Jordan Liub49b04b2019-05-06 14:45:15 -07006148 // Only consider subs which match the current subId
6149 // This logic can be simplified. See b/131189269 for progress.
6150 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006151 activeSubscriberIds.add(tele.getSubscriberId(subId));
6152 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006153
6154 // First pass, find a number override for an active subscriber
6155 String mergeNumber = null;
6156 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6157 for (String key : prefs.keySet()) {
6158 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6159 final String subscriberId = (String) prefs.get(key);
6160 if (activeSubscriberIds.contains(subscriberId)) {
6161 final String iccId = key.substring(
6162 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6163 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6164 mergeNumber = (String) prefs.get(numberKey);
6165 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006166 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006167 + " for active subscriber " + subscriberId);
6168 }
6169 if (!TextUtils.isEmpty(mergeNumber)) {
6170 break;
6171 }
6172 }
6173 }
6174 }
6175
6176 // Shortcut when no active merged subscribers
6177 if (TextUtils.isEmpty(mergeNumber)) {
6178 return null;
6179 }
6180
6181 // Second pass, find all subscribers under that line override
6182 final ArraySet<String> result = new ArraySet<>();
6183 for (String key : prefs.keySet()) {
6184 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6185 final String number = (String) prefs.get(key);
6186 if (mergeNumber.equals(number)) {
6187 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6188 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6189 final String subscriberId = (String) prefs.get(subscriberKey);
6190 if (!TextUtils.isEmpty(subscriberId)) {
6191 result.add(subscriberId);
6192 }
6193 }
6194 }
6195 }
6196
6197 final String[] resultArray = result.toArray(new String[result.size()]);
6198 Arrays.sort(resultArray);
6199 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006200 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006201 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6202 }
6203 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006204 } finally {
6205 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006206 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006207 }
6208
6209 @Override
zoey chen38003472019-12-13 17:16:31 +08006210 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6211 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006212
6213 final long identity = Binder.clearCallingIdentity();
6214 try {
6215 final TelephonyManager telephonyManager = mApp.getSystemService(
6216 TelephonyManager.class);
6217 String subscriberId = telephonyManager.getSubscriberId(subId);
6218 if (subscriberId == null) {
6219 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006220 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006221 + subId);
6222 }
6223 return null;
6224 }
6225
6226 final SubscriptionInfo info = SubscriptionController.getInstance()
6227 .getSubscriptionInfo(subId);
6228 final ParcelUuid groupUuid = info.getGroupUuid();
6229 // If it doesn't belong to any group, return just subscriberId of itself.
6230 if (groupUuid == null) {
6231 return new String[]{subscriberId};
6232 }
6233
6234 // Get all subscriberIds from the group.
6235 final List<String> mergedSubscriberIds = new ArrayList<>();
6236 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006237 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006238 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006239 for (SubscriptionInfo subInfo : groupInfos) {
6240 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6241 if (subscriberId != null) {
6242 mergedSubscriberIds.add(subscriberId);
6243 }
6244 }
6245
6246 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6247 } finally {
6248 Binder.restoreCallingIdentity(identity);
6249
6250 }
6251 }
6252
6253 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006254 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006255 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006256 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006257
6258 final long identity = Binder.clearCallingIdentity();
6259 try {
6260 final Phone phone = getPhone(subId);
6261 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6262 } finally {
6263 Binder.restoreCallingIdentity(identity);
6264 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006265 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006266
6267 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006268 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006269 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6270 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006271 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6272 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006273
6274 final long identity = Binder.clearCallingIdentity();
6275 try {
6276 final Phone phone = getPhone(subId);
6277 if (phone == null) {
6278 return false;
6279 }
6280 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6281 cdmaNonRoamingList);
6282 } finally {
6283 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006284 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006285 }
6286
6287 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006288 @Deprecated
6289 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6290 enforceModifyPermission();
6291
6292 int returnValue = 0;
6293 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006294 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006295 if(result.exception == null) {
6296 if (result.result != null) {
6297 byte[] responseData = (byte[])(result.result);
6298 if(responseData.length > oemResp.length) {
6299 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6300 responseData.length + "bytes. Buffer Size is " +
6301 oemResp.length + "bytes.");
6302 }
6303 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6304 returnValue = responseData.length;
6305 }
6306 } else {
6307 CommandException ex = (CommandException) result.exception;
6308 returnValue = ex.getCommandError().ordinal();
6309 if(returnValue > 0) returnValue *= -1;
6310 }
6311 } catch (RuntimeException e) {
6312 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6313 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6314 if(returnValue > 0) returnValue *= -1;
6315 }
6316
6317 return returnValue;
6318 }
6319
6320 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006321 public void setRadioCapability(RadioAccessFamily[] rafs) {
6322 try {
6323 ProxyController.getInstance().setRadioCapability(rafs);
6324 } catch (RuntimeException e) {
6325 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6326 }
6327 }
6328
6329 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006330 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006331 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006332 try {
6333 TelephonyPermissions
6334 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6335 mApp, phone.getSubId(), "getRadioAccessFamily");
6336 } catch (SecurityException e) {
6337 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6338 throw e;
6339 }
chen xub97461a2018-10-26 14:17:57 -07006340 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006341 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006342 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006343 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006344 final long identity = Binder.clearCallingIdentity();
6345 try {
chen xub97461a2018-10-26 14:17:57 -07006346 TelephonyPermissions
6347 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6348 mApp, phone.getSubId(), "getRadioAccessFamily");
6349 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006350 } finally {
6351 Binder.restoreCallingIdentity(identity);
6352 }
chen xub97461a2018-10-26 14:17:57 -07006353 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006354 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006355
6356 @Override
6357 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006358 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006359 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006360
6361 final long identity = Binder.clearCallingIdentity();
6362 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006363 ImsManager.getInstance(defaultPhone.getContext(),
6364 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006365 } finally {
6366 Binder.restoreCallingIdentity(identity);
6367 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006368 }
6369
6370 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006371 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006372 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006373 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6374 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006375 return false;
6376 }
Svet Ganovb320e182015-04-16 12:30:10 -07006377
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006378 final long identity = Binder.clearCallingIdentity();
6379 try {
6380 // Check the user preference and the system-level IMS setting. Even if the user has
6381 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6382 // In the long run, we may instead need to check if there exists a connection service
6383 // which can support video calling.
6384 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006385 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006386 return imsManager.isVtEnabledByPlatform()
6387 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6388 && imsManager.isVtEnabledByUser();
6389 } finally {
6390 Binder.restoreCallingIdentity(identity);
6391 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006392 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006393
Andrew Leea1239f22015-03-02 17:44:07 -08006394 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006395 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6396 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006397 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006398 mApp, subId, callingPackage, callingFeatureId,
6399 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006400 return false;
6401 }
6402
6403 final long identity = Binder.clearCallingIdentity();
6404 try {
6405 CarrierConfigManager configManager =
6406 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006407 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006408 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6409 } finally {
6410 Binder.restoreCallingIdentity(identity);
6411 }
Andrew Leea1239f22015-03-02 17:44:07 -08006412 }
6413
6414 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006415 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006416 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006417 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006418 return false;
6419 }
6420
6421 final long identity = Binder.clearCallingIdentity();
6422 try {
6423 CarrierConfigManager configManager =
6424 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006425 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006426 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6427 } finally {
6428 Binder.restoreCallingIdentity(identity);
6429 }
Andrew Leea1239f22015-03-02 17:44:07 -08006430 }
6431
Andrew Lee9431b832015-03-09 18:46:45 -07006432 @Override
6433 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006434 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006435 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006436 }
6437
6438 @Override
6439 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440 final long identity = Binder.clearCallingIdentity();
6441 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006442 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006443 } finally {
6444 Binder.restoreCallingIdentity(identity);
6445 }
Andrew Lee9431b832015-03-09 18:46:45 -07006446 }
6447
Hall Liuf6668912018-10-31 17:05:23 -07006448 /**
6449 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6450 * support for the feature and device firmware support.
6451 *
6452 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6453 */
6454 @Override
6455 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006456 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006457 final Phone phone = getPhone(subscriptionId);
6458 if (phone == null) {
6459 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6460 return false;
6461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006462 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006463 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006464 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6465 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006466 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006467 return isCarrierSupported && isDeviceSupported;
6468 } finally {
6469 Binder.restoreCallingIdentity(identity);
6470 }
Hall Liu98187582018-01-22 19:15:32 -08006471 }
6472
Hall Liuf6668912018-10-31 17:05:23 -07006473 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006474 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6475 * RTT setting, will return true if the device and carrier both support RTT.
6476 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006477 */
6478 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006479 final long identity = Binder.clearCallingIdentity();
6480 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006481 boolean isRttSupported = isRttSupported(subscriptionId);
6482 boolean isUserRttSettingOn = Settings.Secure.getInt(
6483 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6484 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6485 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6486 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006487 } finally {
6488 Binder.restoreCallingIdentity(identity);
6489 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006490 }
6491
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006492 @Deprecated
6493 @Override
6494 public String getDeviceId(String callingPackage) {
6495 return getDeviceIdWithFeature(callingPackage, null);
6496 }
6497
Sanket Padawe7310cc72015-01-14 09:53:20 -08006498 /**
6499 * Returns the unique device ID of phone, for example, the IMEI for
6500 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6501 *
6502 * <p>Requires Permission:
6503 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6504 */
6505 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006506 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006507 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006508 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006509 return null;
6510 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006511 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006512 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006513 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006514 return null;
6515 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006516
6517 final long identity = Binder.clearCallingIdentity();
6518 try {
6519 return phone.getDeviceId();
6520 } finally {
6521 Binder.restoreCallingIdentity(identity);
6522 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006523 }
6524
Ping Sunc67b7c22016-03-02 19:16:45 +08006525 /**
6526 * {@hide}
6527 * Returns the IMS Registration Status on a particular subid
6528 *
6529 * @param subId
6530 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006531 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006532 Phone phone = getPhone(subId);
6533 if (phone != null) {
6534 return phone.isImsRegistered();
6535 } else {
6536 return false;
6537 }
6538 }
6539
Santos Cordon7a1885b2015-02-03 11:15:19 -08006540 @Override
6541 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542 final long identity = Binder.clearCallingIdentity();
6543 try {
6544 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6545 } finally {
6546 Binder.restoreCallingIdentity(identity);
6547 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006548 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006549
Tyler Gunnf70ed162019-04-03 15:28:53 -07006550 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006551 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006552 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006553 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006554 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006555 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6556 }
6557 final long identity = Binder.clearCallingIdentity();
6558 try {
6559 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6560 } finally {
6561 Binder.restoreCallingIdentity(identity);
6562 }
6563 }
6564
6565 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006566 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6567 final long identity = Binder.clearCallingIdentity();
6568 try {
6569 Phone phone = getPhone(subscriptionId);
6570 if (phone == null) {
6571 return null;
6572 }
6573 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6574 } finally {
6575 Binder.restoreCallingIdentity(identity);
6576 }
6577 }
6578
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006579 /**
6580 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006581 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006582 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006583 final long identity = Binder.clearCallingIdentity();
6584 try {
6585 Phone phone = getPhone(subId);
6586 if (phone != null) {
6587 return phone.isWifiCallingEnabled();
6588 } else {
6589 return false;
6590 }
6591 } finally {
6592 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006593 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006594 }
6595
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006596 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006597 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006598 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006599 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006600 final long identity = Binder.clearCallingIdentity();
6601 try {
6602 Phone phone = getPhone(subId);
6603 if (phone != null) {
6604 return phone.isVideoEnabled();
6605 } else {
6606 return false;
6607 }
6608 } finally {
6609 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006610 }
6611 }
6612
6613 /**
6614 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6615 * defined in {@link ImsRegistrationImplBase}.
6616 */
6617 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006618 final long identity = Binder.clearCallingIdentity();
6619 try {
6620 Phone phone = getPhone(subId);
6621 if (phone != null) {
6622 return phone.getImsRegistrationTech();
6623 } else {
6624 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6625 }
6626 } finally {
6627 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006628 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006629 }
6630
Stuart Scott8eef64f2015-04-08 15:13:54 -07006631 @Override
6632 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006633 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006634 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6635 return;
6636 }
6637
Svet Ganovcc087f82015-05-12 20:35:54 -07006638 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006639
Svet Ganovcc087f82015-05-12 20:35:54 -07006640 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006641 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6642 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006643 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006644 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006645 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006646 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6647 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006648 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006649 // There has been issues when Sms raw table somehow stores orphan
6650 // fragments. They lead to garbled message when new fragments come
6651 // in and combined with those stale ones. In case this happens again,
6652 // user can reset all network settings which will clean up this table.
6653 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006654 // Clean up IMS settings as well here.
6655 int slotId = getSlotIndex(subId);
6656 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6657 ImsManager.getInstance(mApp, slotId).factoryReset();
6658 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006659
6660 // Erase modem config if erase modem on network setting is enabled.
6661 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6662 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6663 if (configValue != null && Boolean.parseBoolean(configValue)) {
6664 sendEraseModemConfig(getDefaultPhone());
6665 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006666 } finally {
6667 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006668 }
6669 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006670
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006671 private void cleanUpSmsRawTable(Context context) {
6672 ContentResolver resolver = context.getContentResolver();
6673 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6674 resolver.delete(uri, null, null);
6675 }
6676
Narayan Kamath1c496c22015-04-16 14:40:19 +01006677 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006678 public String getSimLocaleForSubscriber(int subId) {
6679 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6680 final Phone phone = getPhone(subId);
6681 if (phone == null) {
6682 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006683 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006684 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006685 final long identity = Binder.clearCallingIdentity();
6686 try {
chen xu5d3637b2019-01-21 23:31:38 -08006687 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006688 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006689 if (info == null) {
6690 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6691 return null;
6692 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006693 // Try and fetch the locale from the carrier properties or from the SIM language
6694 // preferences (EF-PL and EF-LI)...
6695 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006696 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006697 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6698 if (localeFromDefaultSim != null) {
6699 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6700 if (DBG) log("Using locale from subId: " + subId + " locale: "
6701 + localeFromDefaultSim);
6702 return localeFromDefaultSim.toLanguageTag();
6703 } else {
6704 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006705 }
6706 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006707
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 // The SIM language preferences only store a language (e.g. fr = French), not an
6709 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6710 // the SIM and carrier preferences does not include a country we add the country
6711 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006712 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006713 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006714 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715 return mccLocale.toLanguageTag();
6716 }
6717
6718 if (DBG) log("No locale found - returning null");
6719 return null;
6720 } finally {
6721 Binder.restoreCallingIdentity(identity);
6722 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006723 }
6724
6725 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006726 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006727 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006728 }
6729
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006730 /**
6731 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6732 */
6733 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006734 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006735 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006736 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006737
Chenjie Yu1ba97252018-01-11 18:16:20 -08006738 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006739 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006740
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006741 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006742 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6743 * representing the state of the modem.
6744 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006745 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6746 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006747 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006748 */
6749 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006750 public void requestModemActivityInfo(ResultReceiver result) {
6751 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006752 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006753
6754 final long identity = Binder.clearCallingIdentity();
6755 try {
Shuo Qian1d931ee2020-02-20 17:12:10 -08006756 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006757 } finally {
6758 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006759 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006760 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006761
Siddharth Rayb8114062018-06-17 15:02:38 -07006762 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6763 // less than total activity duration.
6764 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6765 if (info == null) {
6766 return false;
6767 }
6768 int activityDurationMs =
6769 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6770 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006771 int[] txTimeMs = info.getTransmitTimeMillis();
6772 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6773 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006774 }
6775 return (info.isValid()
6776 && (info.getSleepTimeMillis() <= activityDurationMs)
6777 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006778 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006779 && (totalTxTimeMs <= activityDurationMs));
6780 }
6781
Jack Yu85bd38a2015-11-09 11:34:32 -08006782 /**
6783 * {@hide}
6784 * Returns the service state information on specified subscription.
6785 */
6786 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006787 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6788 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006789 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006790 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006791 return null;
6792 }
6793
Hall Liuf19c44f2018-11-27 14:38:17 -08006794 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6795 LocationAccessPolicy.checkLocationPermission(mApp,
6796 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6797 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006798 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006799 .setCallingPid(Binder.getCallingPid())
6800 .setCallingUid(Binder.getCallingUid())
6801 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006802 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006803 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6804 .build());
6805
6806 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6807 LocationAccessPolicy.checkLocationPermission(mApp,
6808 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6809 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006810 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006811 .setCallingPid(Binder.getCallingPid())
6812 .setCallingUid(Binder.getCallingUid())
6813 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006814 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006815 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6816 .build());
6817 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6818 boolean hasFinePermission =
6819 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6820 boolean hasCoarsePermission =
6821 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6822
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006823 final long identity = Binder.clearCallingIdentity();
6824 try {
Jordan Liuc437b192020-08-17 10:59:12 -07006825 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
6826 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
6827 Rlog.d(LOG_TAG,
6828 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
6829 return null;
6830 }
6831
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006832 final Phone phone = getPhone(subId);
6833 if (phone == null) {
6834 return null;
6835 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006836
Hall Liuf19c44f2018-11-27 14:38:17 -08006837 ServiceState ss = phone.getServiceState();
6838
6839 // Scrub out the location info in ServiceState depending on what level of access
6840 // the caller has.
6841 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006842 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6843 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006844 } finally {
6845 Binder.restoreCallingIdentity(identity);
6846 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006847 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006848
6849 /**
6850 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6851 *
6852 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6853 * voicemail ringtone.
6854 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6855 * PhoneAccount.
6856 */
6857 @Override
6858 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006859 final long identity = Binder.clearCallingIdentity();
6860 try {
6861 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6862 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006863 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006864 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006865
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006866 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6867 } finally {
6868 Binder.restoreCallingIdentity(identity);
6869 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006870 }
6871
6872 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006873 * Sets the per-account voicemail ringtone.
6874 *
6875 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6876 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6877 *
6878 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6879 * voicemail ringtone.
6880 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6881 * PhoneAccount.
6882 */
6883 @Override
6884 public void setVoicemailRingtoneUri(String callingPackage,
6885 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006886 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006887 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006888 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6889 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6891 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6892 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006893 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006894
6895 final long identity = Binder.clearCallingIdentity();
6896 try {
6897 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6898 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006899 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006900 }
6901 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6902 } finally {
6903 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006904 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006905 }
6906
6907 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006908 * Returns whether vibration is set for voicemail notification in Phone settings.
6909 *
6910 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6911 * voicemail vibration setting.
6912 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6913 */
6914 @Override
6915 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006916 final long identity = Binder.clearCallingIdentity();
6917 try {
6918 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6919 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006920 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006921 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006922
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006923 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6924 } finally {
6925 Binder.restoreCallingIdentity(identity);
6926 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006927 }
6928
Youhan Wange64578a2016-05-02 15:32:42 -07006929 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006930 * Sets the per-account voicemail vibration.
6931 *
6932 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6933 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6934 *
6935 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6936 * voicemail vibration setting.
6937 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6938 * specific PhoneAccount.
6939 */
6940 @Override
6941 public void setVoicemailVibrationEnabled(String callingPackage,
6942 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006943 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006944 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006945 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6946 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006947 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6948 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6949 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006950 }
6951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006952 final long identity = Binder.clearCallingIdentity();
6953 try {
6954 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6955 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006956 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006957 }
6958 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6959 } finally {
6960 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006961 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006962 }
6963
6964 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006965 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6966 *
6967 * @throws SecurityException if the caller does not have the required permission
6968 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006969 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006970 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006971 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006972 }
6973
6974 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006975 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6976 * permission.
6977 *
6978 * @throws SecurityException if the caller does not have the required permission
6979 */
6980 private void enforceSendSmsPermission() {
6981 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6982 }
6983
6984 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006985 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006986 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006987 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006988 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006989 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006990 final long identity = Binder.clearCallingIdentity();
6991 try {
6992 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006993 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006994 if (componentName == null) {
6995 throw new SecurityException(
6996 "Caller not current active visual voicemail package[null]");
6997 }
6998 String vvmPackage = componentName.getPackageName();
6999 if (!callingPackage.equals(vvmPackage)) {
7000 throw new SecurityException("Caller not current active visual voicemail package["
7001 + vvmPackage + "]");
7002 }
7003 } finally {
7004 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007005 }
7006 }
7007
7008 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007009 * Return the application ID for the app type.
7010 *
7011 * @param subId the subscription ID that this request applies to.
7012 * @param appType the uicc app type.
7013 * @return Application ID for specificied app type, or null if no uicc.
7014 */
7015 @Override
7016 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007017 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007018 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019
7020 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007021 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007022 if (phone == null) {
7023 return null;
7024 }
7025 String aid = null;
7026 try {
7027 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7028 .getApplicationByType(appType).getAid();
7029 } catch (Exception e) {
7030 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7031 }
7032 return aid;
7033 } finally {
7034 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007035 }
Youhan Wange64578a2016-05-02 15:32:42 -07007036 }
7037
Youhan Wang4001d252016-05-11 10:29:41 -07007038 /**
7039 * Return the Electronic Serial Number.
7040 *
7041 * @param subId the subscription ID that this request applies to.
7042 * @return ESN or null if error.
7043 */
7044 @Override
7045 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007046 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007047 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007048
7049 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007050 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 if (phone == null) {
7052 return null;
7053 }
7054 String esn = null;
7055 try {
7056 esn = phone.getEsn();
7057 } catch (Exception e) {
7058 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7059 }
7060 return esn;
7061 } finally {
7062 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007063 }
Youhan Wang4001d252016-05-11 10:29:41 -07007064 }
7065
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007066 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007067 * Return the Preferred Roaming List Version.
7068 *
7069 * @param subId the subscription ID that this request applies to.
7070 * @return PRLVersion or null if error.
7071 */
7072 @Override
7073 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007074 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007075 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007076
7077 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007078 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 if (phone == null) {
7080 return null;
7081 }
7082 String cdmaPrlVersion = null;
7083 try {
7084 cdmaPrlVersion = phone.getCdmaPrlVersion();
7085 } catch (Exception e) {
7086 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7087 }
7088 return cdmaPrlVersion;
7089 } finally {
7090 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007091 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007092 }
7093
7094 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007095 * Get snapshot of Telephony histograms
7096 * @return List of Telephony histograms
7097 * @hide
7098 */
7099 @Override
7100 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7102 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007103
7104 final long identity = Binder.clearCallingIdentity();
7105 try {
7106 return RIL.getTelephonyRILTimingHistograms();
7107 } finally {
7108 Binder.restoreCallingIdentity(identity);
7109 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007110 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007111
7112 /**
7113 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007114 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7115 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007116 * Require system privileges. In the future we may add this to carrier APIs.
7117 *
Michele Berionne482f8202018-11-27 18:57:59 -08007118 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007119 */
7120 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007121 @TelephonyManager.SetCarrierRestrictionResult
7122 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007123 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007124 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007125
Michele Berionne482f8202018-11-27 18:57:59 -08007126 if (carrierRestrictionRules == null) {
7127 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007128 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007129
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007130 final long identity = Binder.clearCallingIdentity();
7131 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007132 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007133 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007134 } finally {
7135 Binder.restoreCallingIdentity(identity);
7136 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007137 }
7138
7139 /**
7140 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007141 * Get the allowed carrier list and the excluded carrier list, including the priority between
7142 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007143 * Require system privileges. In the future we may add this to carrier APIs.
7144 *
Michele Berionne482f8202018-11-27 18:57:59 -08007145 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007146 */
7147 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007148 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007149 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007150 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151
7152 final long identity = Binder.clearCallingIdentity();
7153 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007154 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7155 if (response instanceof CarrierRestrictionRules) {
7156 return (CarrierRestrictionRules) response;
7157 }
7158 // Response is an Exception of some kind,
7159 // which is signalled to the user as a NULL retval
7160 return null;
7161 } catch (Exception e) {
7162 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7163 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007164 } finally {
7165 Binder.restoreCallingIdentity(identity);
7166 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007167 }
7168
fionaxu59545b42016-05-25 15:53:37 -07007169 /**
7170 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7171 * @param subId the subscription ID that this action applies to.
7172 * @param enabled control enable or disable metered apns.
7173 * {@hide}
7174 */
7175 @Override
7176 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7177 enforceModifyPermission();
7178 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179
7180 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007181 if (phone == null) {
7182 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7183 return;
7184 }
7185 try {
7186 phone.carrierActionSetMeteredApnsEnabled(enabled);
7187 } catch (Exception e) {
7188 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007189 } finally {
7190 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007191 }
7192 }
7193
7194 /**
7195 * Action set from carrier signalling broadcast receivers to enable/disable radio
7196 * @param subId the subscription ID that this action applies to.
7197 * @param enabled control enable or disable radio.
7198 * {@hide}
7199 */
7200 @Override
7201 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7202 enforceModifyPermission();
7203 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007204
7205 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007206 if (phone == null) {
7207 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7208 return;
7209 }
7210 try {
7211 phone.carrierActionSetRadioEnabled(enabled);
7212 } catch (Exception e) {
7213 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007214 } finally {
7215 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007216 }
7217 }
7218
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007219 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007220 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7221 * network status based on which carrier apps could apply actions accordingly,
7222 * enable/disable default url handler for example.
7223 *
7224 * @param subId the subscription ID that this action applies to.
7225 * @param report control start/stop reporting the default network status.
7226 * {@hide}
7227 */
7228 @Override
7229 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7230 enforceModifyPermission();
7231 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007232
7233 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007234 if (phone == null) {
7235 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7236 return;
7237 }
7238 try {
7239 phone.carrierActionReportDefaultNetworkStatus(report);
7240 } catch (Exception e) {
7241 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007242 } finally {
7243 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007244 }
7245 }
7246
7247 /**
fionaxud9622282017-07-17 17:51:30 -07007248 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7249 * @param subId the subscription ID that this action applies to.
7250 * {@hide}
7251 */
7252 @Override
7253 public void carrierActionResetAll(int subId) {
7254 enforceModifyPermission();
7255 final Phone phone = getPhone(subId);
7256 if (phone == null) {
7257 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7258 return;
7259 }
7260 try {
7261 phone.carrierActionResetAll();
7262 } catch (Exception e) {
7263 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7264 }
7265 }
7266
7267 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007268 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7269 * bug report is being generated.
7270 */
7271 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007272 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007273 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7274 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007275 writer.println("Permission Denial: can't dump Phone from pid="
7276 + Binder.getCallingPid()
7277 + ", uid=" + Binder.getCallingUid()
7278 + "without permission "
7279 + android.Manifest.permission.DUMP);
7280 return;
7281 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007282 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007283 }
Jack Yueb89b242016-06-22 13:27:47 -07007284
Brad Ebingerdac2f002018-04-03 15:17:52 -07007285 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007286 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7287 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7288 @NonNull String[] args) {
7289 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7290 this, in.getFileDescriptor(), out.getFileDescriptor(),
7291 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007292 }
7293
Jack Yueb89b242016-06-22 13:27:47 -07007294 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007295 * Policy control of data connection. Usually used when data limit is passed.
7296 * @param enabled True if enabling the data, otherwise disabling.
7297 * @param subId Subscription index
7298 * {@hide}
7299 */
7300 @Override
7301 public void setPolicyDataEnabled(boolean enabled, int subId) {
7302 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007303
7304 final long identity = Binder.clearCallingIdentity();
7305 try {
7306 Phone phone = getPhone(subId);
7307 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007308 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007309 }
7310 } finally {
7311 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007312 }
7313 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007314
7315 /**
7316 * Get Client request stats
7317 * @return List of Client Request Stats
7318 * @hide
7319 */
7320 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007321 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7322 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007324 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007325 return null;
7326 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007327 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007328
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007329 final long identity = Binder.clearCallingIdentity();
7330 try {
7331 if (phone != null) {
7332 return phone.getClientRequestStats();
7333 }
7334
7335 return null;
7336 } finally {
7337 Binder.restoreCallingIdentity(identity);
7338 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007339 }
7340
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007341 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007342 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007343 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007344 }
Jack Yueb4124c2017-02-16 15:32:43 -08007345
7346 /**
Grace Chen70990072017-03-24 17:21:30 -07007347 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007348 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007349 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007350 * @param state State of SIM (power down, power up, pass through)
7351 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7352 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7353 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007354 *
7355 **/
7356 @Override
Grace Chen70990072017-03-24 17:21:30 -07007357 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007358 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007359 Phone phone = PhoneFactory.getPhone(slotIndex);
7360
vagdeviaf9a5b92018-08-15 16:01:53 -07007361 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007363 final long identity = Binder.clearCallingIdentity();
7364 try {
7365 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007366 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007367 }
7368 } finally {
7369 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007370 }
7371 }
Shuo Qiandd210312017-04-12 22:11:33 +00007372
Tyler Gunn65d45c22017-06-05 11:22:26 -07007373 private boolean isUssdApiAllowed(int subId) {
7374 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007375 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007376 if (configManager == null) {
7377 return false;
7378 }
7379 PersistableBundle pb = configManager.getConfigForSubId(subId);
7380 if (pb == null) {
7381 return false;
7382 }
7383 return pb.getBoolean(
7384 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7385 }
7386
Shuo Qiandd210312017-04-12 22:11:33 +00007387 /**
7388 * Check if phone is in emergency callback mode
7389 * @return true if phone is in emergency callback mode
7390 * @param subId sub id
7391 */
goneil9c5f4872017-12-05 14:07:56 -08007392 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007393 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007394 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007395 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007396
7397 final long identity = Binder.clearCallingIdentity();
7398 try {
7399 if (phone != null) {
7400 return phone.isInEcm();
7401 } else {
7402 return false;
7403 }
7404 } finally {
7405 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007406 }
7407 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007408
7409 /**
7410 * Get the current signal strength information for the given subscription.
7411 * Because this information is not updated when the device is in a low power state
7412 * it should not be relied-upon to be current.
7413 * @param subId Subscription index
7414 * @return the most recent cached signal strength info from the modem
7415 */
7416 @Override
7417 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007418 final long identity = Binder.clearCallingIdentity();
7419 try {
7420 Phone p = getPhone(subId);
7421 if (p == null) {
7422 return null;
7423 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007424
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007425 return p.getSignalStrength();
7426 } finally {
7427 Binder.restoreCallingIdentity(identity);
7428 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007429 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007430
Pengquan Meng77b7f132018-08-22 14:49:57 -07007431 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007432 * Get the current modem radio state for the given slot.
7433 * @param slotIndex slot index.
7434 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007435 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007436 * @return the current radio power state from the modem
7437 */
7438 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007439 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007440 Phone phone = PhoneFactory.getPhone(slotIndex);
7441 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7443 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007444 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7445 }
7446
7447 final long identity = Binder.clearCallingIdentity();
7448 try {
7449 return phone.getRadioPowerState();
7450 } finally {
7451 Binder.restoreCallingIdentity(identity);
7452 }
7453 }
7454 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7455 }
7456
7457 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007458 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7459 *
7460 * <p>Requires one of the following permissions:
7461 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7462 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7463 * privileges.
7464 *
7465 * @param subId subscription id
7466 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7467 * {@code false}.
7468 */
7469 @Override
7470 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007471 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7472 null /* message */);
7473
Pengquan Menga1bb6272018-09-06 09:59:22 -07007474 boolean isEnabled = false;
7475 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007476 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007477 Phone phone = getPhone(subId);
7478 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007479 } catch (Exception e) {
7480 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7481 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007482 } finally {
7483 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007484 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007485 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007486 }
7487
7488
7489 /**
7490 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7491 *
7492 * <p> Requires permission:
7493 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7494 * privileges.
7495 *
7496 * @param subId subscription id
7497 * @param isEnabled {@code true} means enable, {@code false} means disable.
7498 */
7499 @Override
7500 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007501 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7502 mApp, subId, "setDataRoamingEnabled");
7503
Pengquan Menga1bb6272018-09-06 09:59:22 -07007504 final long identity = Binder.clearCallingIdentity();
7505 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007506 Phone phone = getPhone(subId);
7507 if (phone != null) {
7508 phone.setDataRoamingEnabled(isEnabled);
7509 }
7510 } finally {
7511 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007512 }
7513 }
7514
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007515 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007516 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007517 TelephonyPermissions
7518 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007519 mApp, subId, "isManualNetworkSelectionAllowed");
7520
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007521 boolean isAllowed = true;
7522 final long identity = Binder.clearCallingIdentity();
7523 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007524 Phone phone = getPhone(subId);
7525 if (phone != null) {
7526 isAllowed = phone.isCspPlmnEnabled();
7527 }
7528 } finally {
7529 Binder.restoreCallingIdentity(identity);
7530 }
7531 return isAllowed;
7532 }
7533
7534 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007535 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007536 // Verify that tha callingPackage belongs to the calling UID
7537 mApp.getSystemService(AppOpsManager.class)
7538 .checkPackage(Binder.getCallingUid(), callingPackage);
7539
Jordan Liu1e142fc2019-04-22 15:10:43 -07007540 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007541 try {
7542 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007543 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007544 } catch (SecurityException e) {
7545 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7546 // has carrier privileges on an active UICC
7547 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7548 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007549 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007550 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007551 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007552
7553 final long identity = Binder.clearCallingIdentity();
7554 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007555 UiccController uiccController = UiccController.getInstance();
7556 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007557 if (hasReadPermission) {
7558 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007559 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007560
7561 // Remove private info if the caller doesn't have access
7562 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7563 for (UiccCardInfo cardInfo : cardInfos) {
7564 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7565 // is available
7566 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7567 if (card == null || card.getUiccProfile() == null) {
7568 // assume no access if the card or profile is unavailable
7569 filteredInfos.add(cardInfo.getUnprivileged());
7570 continue;
7571 }
7572 UiccProfile profile = card.getUiccProfile();
7573 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7574 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7575 filteredInfos.add(cardInfo);
7576 } else {
7577 filteredInfos.add(cardInfo.getUnprivileged());
7578 }
7579 }
7580 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007581 } finally {
7582 Binder.restoreCallingIdentity(identity);
7583 }
7584 }
7585
7586 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007587 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007588 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007589
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007590 final long identity = Binder.clearCallingIdentity();
7591 try {
7592 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7593 if (slots == null) {
7594 Rlog.i(LOG_TAG, "slots is null.");
7595 return null;
7596 }
7597
7598 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7599 for (int i = 0; i < slots.length; i++) {
7600 UiccSlot slot = slots[i];
7601 if (slot == null) {
7602 continue;
7603 }
7604
Jordan Liu7be7e652019-05-06 18:55:02 +00007605 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007606 UiccCard card = slot.getUiccCard();
7607 if (card != null) {
7608 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007609 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007610 cardId = slot.getEid();
7611 if (TextUtils.isEmpty(cardId)) {
7612 cardId = slot.getIccId();
7613 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007614 }
7615
Jordan Liu857451f2019-05-09 16:35:35 -07007616 if (cardId != null) {
7617 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7618 // if cardId is an EID, it's all digits so this is fine
7619 cardId = IccUtils.stripTrailingFs(cardId);
7620 }
7621
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007622 int cardState = 0;
7623 switch (slot.getCardState()) {
7624 case CARDSTATE_ABSENT:
7625 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7626 break;
7627 case CARDSTATE_PRESENT:
7628 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7629 break;
7630 case CARDSTATE_ERROR:
7631 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7632 break;
7633 case CARDSTATE_RESTRICTED:
7634 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7635 break;
7636 default:
7637 break;
7638
7639 }
7640
7641 infos[i] = new UiccSlotInfo(
7642 slot.isActive(),
7643 slot.isEuicc(),
7644 cardId,
7645 cardState,
7646 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007647 slot.isExtendedApduSupported(),
7648 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007649 }
7650 return infos;
7651 } finally {
7652 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007653 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007654 }
7655
7656 @Override
7657 public boolean switchSlots(int[] physicalSlots) {
7658 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007659
7660 final long identity = Binder.clearCallingIdentity();
7661 try {
7662 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7663 } finally {
7664 Binder.restoreCallingIdentity(identity);
7665 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007666 }
Jack Yu4c988042018-02-27 15:30:01 -08007667
7668 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007669 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007670 final long identity = Binder.clearCallingIdentity();
7671 try {
7672 return UiccController.getInstance().getCardIdForDefaultEuicc();
7673 } finally {
7674 Binder.restoreCallingIdentity(identity);
7675 }
7676 }
7677
Pengquan Meng85728fb2018-03-12 16:31:21 -07007678 /**
goneil47ffb6e2018-04-06 15:40:58 -07007679 * A test API to reload the UICC profile.
7680 *
7681 * <p>Requires that the calling app has permission
7682 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7683 * @hide
7684 */
7685 @Override
7686 public void refreshUiccProfile(int subId) {
7687 enforceModifyPermission();
7688
7689 final long identity = Binder.clearCallingIdentity();
7690 try {
7691 Phone phone = getPhone(subId);
7692 if (phone == null) {
7693 return;
7694 }
7695 UiccCard uiccCard = phone.getUiccCard();
7696 if (uiccCard == null) {
7697 return;
7698 }
7699 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7700 if (uiccProfile == null) {
7701 return;
7702 }
7703 uiccProfile.refresh();
7704 } finally {
7705 Binder.restoreCallingIdentity(identity);
7706 }
7707 }
7708
7709 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007710 * Returns false if the mobile data is disabled by default, otherwise return true.
7711 */
7712 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007713 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007714 }
7715
7716 /**
7717 * Returns true if the data roaming is enabled by default, i.e the system property
7718 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7719 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7720 */
7721 private boolean getDefaultDataRoamingEnabled(int subId) {
7722 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007723 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07007724 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007725 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7726 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7727 return isDataRoamingEnabled;
7728 }
7729
7730 /**
7731 * Returns the default network type for the given {@code subId}, if the default network type is
7732 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7733 */
7734 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007735 List<Integer> list = TelephonyProperties.default_network();
7736 int phoneId = mSubscriptionController.getPhoneId(subId);
7737 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7738 return list.get(phoneId);
7739 }
7740 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007741 }
fionaxua13278b2018-03-21 00:08:13 -07007742
7743 @Override
7744 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007745 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007746 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007747
7748 final long identity = Binder.clearCallingIdentity();
7749 try {
7750 final Phone phone = getPhone(subId);
7751 if (phone == null) {
7752 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7753 return;
7754 }
chen xueaba88a2019-03-15 13:15:10 -07007755 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7756 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007757 } finally {
7758 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007759 }
fionaxua13278b2018-03-21 00:08:13 -07007760 }
7761
7762 @Override
7763 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007764 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007765
7766 final long identity = Binder.clearCallingIdentity();
7767 try {
7768 final Phone phone = getPhone(subId);
7769 if (phone == null) {
7770 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7771 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7772 }
7773 return phone.getCarrierIdListVersion();
7774 } finally {
7775 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007776 }
fionaxua13278b2018-03-21 00:08:13 -07007777 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007778
7779 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007780 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7781 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007782 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007783 mApp, subId, callingPackage, callingFeatureId,
7784 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007785 return -1;
7786 }
7787
7788 final long identity = Binder.clearCallingIdentity();
7789 try {
7790 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7791 } finally {
7792 Binder.restoreCallingIdentity(identity);
7793 }
7794 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007795
7796 @Override
7797 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007798 TelephonyPermissions
7799 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007800 mApp, subId, "getCdmaRoamingMode");
7801
7802 final long identity = Binder.clearCallingIdentity();
7803 try {
7804 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7805 } finally {
7806 Binder.restoreCallingIdentity(identity);
7807 }
7808 }
7809
7810 @Override
7811 public boolean setCdmaRoamingMode(int subId, int mode) {
7812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7813 mApp, subId, "setCdmaRoamingMode");
7814
7815 final long identity = Binder.clearCallingIdentity();
7816 try {
7817 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7818 } finally {
7819 Binder.restoreCallingIdentity(identity);
7820 }
7821 }
7822
7823 @Override
7824 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7826 mApp, subId, "setCdmaSubscriptionMode");
7827
7828 final long identity = Binder.clearCallingIdentity();
7829 try {
7830 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7831 } finally {
7832 Binder.restoreCallingIdentity(identity);
7833 }
7834 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007835
sqianc5eccab2018-10-19 18:46:41 -07007836 @Override
sqian8c685422019-02-22 15:55:18 -08007837 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007838 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007839 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007840 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7841 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007842 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7843 }
7844 final long identity = Binder.clearCallingIdentity();
7845 try {
sqian854d44b2018-12-12 16:48:18 -08007846 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7847 for (Phone phone: PhoneFactory.getPhones()) {
7848 if (phone.getEmergencyNumberTracker() != null
7849 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7850 emergencyNumberListInternal.put(
7851 phone.getSubId(),
7852 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7853 }
sqian11b7a0e2018-12-05 18:48:28 -08007854 }
sqian854d44b2018-12-12 16:48:18 -08007855 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007856 } finally {
7857 Binder.restoreCallingIdentity(identity);
7858 }
sqianc5eccab2018-10-19 18:46:41 -07007859 }
7860
7861 @Override
sqian8c685422019-02-22 15:55:18 -08007862 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007863 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007864 if (!exactMatch) {
7865 TelephonyPermissions
7866 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007867 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007868 }
7869 final long identity = Binder.clearCallingIdentity();
7870 try {
sqian854d44b2018-12-12 16:48:18 -08007871 for (Phone phone: PhoneFactory.getPhones()) {
7872 if (phone.getEmergencyNumberTracker() != null
7873 && phone.getEmergencyNumberTracker() != null) {
7874 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7875 number, exactMatch)) {
7876 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007877 }
7878 }
sqian11b7a0e2018-12-05 18:48:28 -08007879 }
7880 return false;
7881 } finally {
7882 Binder.restoreCallingIdentity(identity);
7883 }
7884 }
7885
sqianf4ca7ed2019-01-15 18:32:07 -08007886 /**
7887 * Update emergency number list for test mode.
7888 */
7889 @Override
7890 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7891 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7892 "updateEmergencyNumberListTestMode");
7893
7894 final long identity = Binder.clearCallingIdentity();
7895 try {
7896 for (Phone phone: PhoneFactory.getPhones()) {
7897 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7898 if (tracker != null) {
7899 tracker.executeEmergencyNumberTestModeCommand(action, num);
7900 }
7901 }
7902 } finally {
7903 Binder.restoreCallingIdentity(identity);
7904 }
7905 }
7906
7907 /**
7908 * Get the full emergency number list for test mode.
7909 */
7910 @Override
7911 public List<String> getEmergencyNumberListTestMode() {
7912 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7913 "getEmergencyNumberListTestMode");
7914
7915 final long identity = Binder.clearCallingIdentity();
7916 try {
7917 Set<String> emergencyNumbers = new HashSet<>();
7918 for (Phone phone: PhoneFactory.getPhones()) {
7919 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7920 if (tracker != null) {
7921 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7922 emergencyNumbers.add(num.getNumber());
7923 }
7924 }
7925 }
7926 return new ArrayList<>(emergencyNumbers);
7927 } finally {
7928 Binder.restoreCallingIdentity(identity);
7929 }
7930 }
7931
chen xud6b45bd2018-10-30 22:27:10 -07007932 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007933 public int getEmergencyNumberDbVersion(int subId) {
7934 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7935
7936 final long identity = Binder.clearCallingIdentity();
7937 try {
7938 final Phone phone = getPhone(subId);
7939 if (phone == null) {
7940 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7941 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7942 }
7943 return phone.getEmergencyNumberDbVersion();
7944 } finally {
7945 Binder.restoreCallingIdentity(identity);
7946 }
7947 }
7948
7949 @Override
7950 public void notifyOtaEmergencyNumberDbInstalled() {
7951 enforceModifyPermission();
7952
7953 final long identity = Binder.clearCallingIdentity();
7954 try {
7955 for (Phone phone: PhoneFactory.getPhones()) {
7956 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7957 if (tracker != null) {
7958 tracker.updateOtaEmergencyNumberDatabase();
7959 }
7960 }
7961 } finally {
7962 Binder.restoreCallingIdentity(identity);
7963 }
7964 }
7965
7966 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08007967 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08007968 enforceActiveEmergencySessionPermission();
7969
7970 final long identity = Binder.clearCallingIdentity();
7971 try {
7972 for (Phone phone: PhoneFactory.getPhones()) {
7973 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7974 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08007975 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7976 }
7977 }
7978 } finally {
7979 Binder.restoreCallingIdentity(identity);
7980 }
7981 }
7982
7983 @Override
7984 public void resetOtaEmergencyNumberDbFilePath() {
7985 enforceActiveEmergencySessionPermission();
7986
7987 final long identity = Binder.clearCallingIdentity();
7988 try {
7989 for (Phone phone: PhoneFactory.getPhones()) {
7990 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7991 if (tracker != null) {
7992 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08007993 }
7994 }
7995 } finally {
7996 Binder.restoreCallingIdentity(identity);
7997 }
7998 }
7999
8000 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008001 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8002 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8003 Phone phone = getPhone(subId);
8004 if (phone == null) {
8005 return null;
8006 }
8007 final long identity = Binder.clearCallingIdentity();
8008 try {
8009 UiccProfile profile = UiccController.getInstance()
8010 .getUiccProfileForPhone(phone.getPhoneId());
8011 if (profile != null) {
8012 return profile.getCertsFromCarrierPrivilegeAccessRules();
8013 }
8014 } finally {
8015 Binder.restoreCallingIdentity(identity);
8016 }
8017 return null;
8018 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008019
8020 /**
8021 * Enable or disable a modem stack.
8022 */
8023 @Override
8024 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8025 enforceModifyPermission();
8026
8027 final long identity = Binder.clearCallingIdentity();
8028 try {
8029 Phone phone = PhoneFactory.getPhone(slotIndex);
8030 if (phone == null) {
8031 return false;
8032 } else {
8033 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8034 }
8035 } finally {
8036 Binder.restoreCallingIdentity(identity);
8037 }
8038 }
Michelecea4cf22018-12-21 15:00:11 -08008039
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008040 /**
8041 * Whether a modem stack is enabled or not.
8042 */
8043 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008044 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8045 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008046 Phone phone = PhoneFactory.getPhone(slotIndex);
8047 if (phone == null) return false;
8048
8049 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008050 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8051 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008052 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8053 }
8054
8055 final long identity = Binder.clearCallingIdentity();
8056 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008057 try {
8058 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8059 } catch (NoSuchElementException ex) {
8060 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8061 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008062 } finally {
8063 Binder.restoreCallingIdentity(identity);
8064 }
8065 }
8066
Michelecea4cf22018-12-21 15:00:11 -08008067 @Override
Michele0ea7d782019-03-19 14:58:42 -07008068 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008069 enforceModifyPermission();
8070
8071 final long identity = Binder.clearCallingIdentity();
8072 try {
8073 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008074 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008075 .commit();
8076 } finally {
8077 Binder.restoreCallingIdentity(identity);
8078 }
8079 }
8080
8081 @Override
Michele0ea7d782019-03-19 14:58:42 -07008082 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008083 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008084 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008085 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8086 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008087 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008088 }
Michelecea4cf22018-12-21 15:00:11 -08008089
8090 final long identity = Binder.clearCallingIdentity();
8091 try {
Michele0ea7d782019-03-19 14:58:42 -07008092 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008093 } finally {
8094 Binder.restoreCallingIdentity(identity);
8095 }
8096 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008097
Michele0ea7d782019-03-19 14:58:42 -07008098 @TelephonyManager.IsMultiSimSupportedResult
8099 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008100 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8101 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8102 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008103 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8104 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008105 }
8106 // Check if the hardware supports multisim functionality. If usage of multisim is not
8107 // supported by the modem, indicate that it is restricted.
8108 PhoneCapability staticCapability =
8109 mPhoneConfigurationManager.getStaticPhoneCapability();
8110 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008111 loge("isMultiSimSupportedInternal: no static configuration available");
8112 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008113 }
Sarah Chin7caee492020-02-18 20:49:02 +00008114 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008115 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8116 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008117 }
8118 // Check if support of multiple SIMs is restricted by carrier
8119 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008120 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008121 }
8122
Michele0ea7d782019-03-19 14:58:42 -07008123 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008124 }
8125
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008126 /**
8127 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008128 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8129 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8130 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008131 * @param numOfSims number of active sims we want to switch to
8132 */
8133 @Override
8134 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008135 if (numOfSims == 1) {
8136 enforceModifyPermission();
8137 } else {
8138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8139 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8140 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008141 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008142
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008143 try {
Michele30b57b22019-03-01 12:01:14 -08008144 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008145 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008146 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8147 return;
8148 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008149 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8150 } finally {
8151 Binder.restoreCallingIdentity(identity);
8152 }
8153 }
8154
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008155 @Override
8156 public boolean isApplicationOnUicc(int subId, int appType) {
8157 enforceReadPrivilegedPermission("isApplicationOnUicc");
8158 Phone phone = getPhone(subId);
8159 if (phone == null) {
8160 return false;
8161 }
8162 final long identity = Binder.clearCallingIdentity();
8163 try {
8164 UiccCard uiccCard = phone.getUiccCard();
8165 if (uiccCard == null) {
8166 return false;
8167 }
8168 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8169 if (uiccProfile == null) {
8170 return false;
8171 }
8172 if (TelephonyManager.APPTYPE_SIM <= appType
8173 && appType <= TelephonyManager.APPTYPE_ISIM) {
8174 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8175 }
8176 return false;
8177 } finally {
8178 Binder.restoreCallingIdentity(identity);
8179 }
8180 }
8181
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008182 /**
chen xub4baa772019-04-03 10:23:41 -07008183 * Get whether making changes to modem configurations will trigger reboot.
8184 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008185 */
8186 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008187 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8188 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008189 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008190 mApp, subId, callingPackage, callingFeatureId,
8191 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008192 return false;
8193 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008194 final long identity = Binder.clearCallingIdentity();
8195 try {
8196 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8197 } finally {
8198 Binder.restoreCallingIdentity(identity);
8199 }
8200 }
8201
Nathan Harold29f5f052019-02-15 13:41:57 -08008202 private void updateModemStateMetrics() {
8203 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8204 // TODO: check the state for each modem if the api is ready.
8205 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8206 }
8207
Pengquan Meng3889a572019-01-23 11:16:29 -08008208 @Override
8209 public int[] getSlotsMapping() {
8210 enforceReadPrivilegedPermission("getSlotsMapping");
8211
8212 final long identity = Binder.clearCallingIdentity();
8213 try {
8214 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8215 // All logical slots should have a mapping to a physical slot.
8216 int[] logicalSlotsMapping = new int[phoneCount];
8217 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8218 for (int i = 0; i < slotInfos.length; i++) {
8219 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8220 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8221 }
8222 }
8223 return logicalSlotsMapping;
8224 } finally {
8225 Binder.restoreCallingIdentity(identity);
8226 }
8227 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008228
8229 /**
8230 * Get the IRadio HAL Version
8231 */
8232 @Override
8233 public int getRadioHalVersion() {
8234 Phone phone = getDefaultPhone();
8235 if (phone == null) return -1;
8236 HalVersion hv = phone.getHalVersion();
8237 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8238 return hv.major * 100 + hv.minor;
8239 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008240
8241 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008242 * Get the current calling package name.
8243 * @return the current calling package name
8244 */
8245 @Override
8246 public String getCurrentPackageName() {
8247 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8248 }
8249
8250 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008251 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8252 * corresponding network requests on a subId.
8253 *
8254 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008255 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008256 * 2) APN is un-metered for this subscription, or
8257 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008258 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008259 *
8260 * @return whether data is allowed for a apn type.
8261 *
8262 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008263 */
8264 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008265 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008266 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8267 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008268
8269 // Now that all security checks passes, perform the operation as ourselves.
8270 final long identity = Binder.clearCallingIdentity();
8271 try {
8272 Phone phone = getPhone(subId);
8273 if (phone == null) return false;
8274
Jack Yu41407ee2019-05-13 16:54:09 -07008275 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008276 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8277 } finally {
8278 Binder.restoreCallingIdentity(identity);
8279 }
8280 }
8281
8282 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008283 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008284 enforceReadPrivilegedPermission("isApnMetered");
8285
8286 // Now that all security checks passes, perform the operation as ourselves.
8287 final long identity = Binder.clearCallingIdentity();
8288 try {
8289 Phone phone = getPhone(subId);
8290 if (phone == null) return true; // By default return true.
8291
Jack Yu41407ee2019-05-13 16:54:09 -07008292 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008293 } finally {
8294 Binder.restoreCallingIdentity(identity);
8295 }
8296 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008297
8298 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008299 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8300 int subscriptionId, IBooleanConsumer resultCallback) {
8301 enforceModifyPermission();
8302 long token = Binder.clearCallingIdentity();
8303 try {
8304 Phone phone = getPhone(subscriptionId);
8305 if (phone == null) {
8306 try {
8307 if (resultCallback != null) {
8308 resultCallback.accept(false);
8309 }
8310 } catch (RemoteException e) {
8311 // ignore
8312 }
8313 return;
8314 }
8315 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8316 Pair.create(specifiers, (x) -> {
8317 try {
8318 if (resultCallback != null) {
8319 resultCallback.accept(x);
8320 }
8321 } catch (RemoteException e) {
8322 // ignore
8323 }
8324 });
8325 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8326 } finally {
8327 Binder.restoreCallingIdentity(token);
8328 }
8329 }
8330
8331 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008332 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008333 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008334 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8335 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8336 if (iccRecords == null) {
8337 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8338 return false;
8339 }
8340 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8341 }
8342
8343 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008344 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8345 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008346 if (callingPackage == null) {
8347 callingPackage = getCurrentPackageName();
8348 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008349 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8350 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008351 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8352 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008353 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8354 }
8355 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8356 Intent intent = new Intent();
8357 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8358 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8359 // Bring up choose default SMS subscription dialog right now
8360 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8361 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8362 mApp.startActivity(intent);
8363 }
chen xud5ca2d52019-05-28 15:20:57 -07008364
8365 @Override
8366 public String getMmsUAProfUrl(int subId) {
8367 //TODO investigate if this API should require proper permission check in R b/133791609
8368 final long identity = Binder.clearCallingIdentity();
8369 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008370 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8371 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008372 } finally {
8373 Binder.restoreCallingIdentity(identity);
8374 }
8375 }
8376
8377 @Override
8378 public String getMmsUserAgent(int subId) {
8379 //TODO investigate if this API should require proper permission check in R b/133791609
8380 final long identity = Binder.clearCallingIdentity();
8381 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008382 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8383 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008384 } finally {
8385 Binder.restoreCallingIdentity(identity);
8386 }
8387 }
Jack Yub07d4972019-05-28 16:12:25 -07008388
8389 @Override
8390 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8391 enforceModifyPermission();
8392
8393 // Now that all security checks passes, perform the operation as ourselves.
8394 final long identity = Binder.clearCallingIdentity();
8395 try {
8396 Phone phone = getPhone(subId);
8397 if (phone == null) return false;
8398
8399 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8400 } finally {
8401 Binder.restoreCallingIdentity(identity);
8402 }
8403 }
8404
8405 @Override
8406 public boolean isDataAllowedInVoiceCall(int subId) {
8407 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8408
8409 // Now that all security checks passes, perform the operation as ourselves.
8410 final long identity = Binder.clearCallingIdentity();
8411 try {
8412 Phone phone = getPhone(subId);
8413 if (phone == null) return false;
8414
8415 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8416 } finally {
8417 Binder.restoreCallingIdentity(identity);
8418 }
8419 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008420
changbettyd5c246e2019-12-24 15:40:37 +08008421 @Override
8422 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8423 enforceModifyPermission();
8424
8425 // Now that all security checks passes, perform the operation as ourselves.
8426 final long identity = Binder.clearCallingIdentity();
8427 try {
8428 Phone phone = getPhone(subId);
8429 if (phone == null) return false;
8430
8431 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8432 } finally {
8433 Binder.restoreCallingIdentity(identity);
8434 }
8435 }
8436
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008437 /**
8438 * Updates whether conference event pacakge handling is enabled.
8439 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8440 * otherwise.
8441 */
8442 @Override
8443 public void setCepEnabled(boolean isCepEnabled) {
8444 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8445
8446 final long identity = Binder.clearCallingIdentity();
8447 try {
8448 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8449 for (Phone phone : PhoneFactory.getPhones()) {
8450 Phone defaultPhone = phone.getImsPhone();
8451 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8452 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8453 ImsPhoneCallTracker imsPhoneCallTracker =
8454 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8455 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8456 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8457 + imsPhone.getMsisdn());
8458 }
8459 }
8460 } finally {
8461 Binder.restoreCallingIdentity(identity);
8462 }
8463 }
allenwtsu46dcc572020-01-08 18:24:03 +08008464
8465 /**
8466 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8467 *
8468 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8469 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8470 * before being read.
8471 */
8472 @Override
8473 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8474 isCompressed) {
8475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8476 mApp, subId, "notifyRcsAutoConfigurationReceived");
8477 try {
8478 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8479 if (configBinder == null) {
8480 Rlog.e(LOG_TAG, "null result for getImsConfig");
8481 } else {
8482 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8483 }
8484 } catch (RemoteException e) {
8485 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8486 }
8487 }
zoey chene02881a2019-12-30 16:11:23 +08008488
8489 @Override
8490 public boolean isIccLockEnabled(int subId) {
8491 enforceReadPrivilegedPermission("isIccLockEnabled");
8492
8493 // Now that all security checks passes, perform the operation as ourselves.
8494 final long identity = Binder.clearCallingIdentity();
8495 try {
8496 Phone phone = getPhone(subId);
8497 if (phone != null && phone.getIccCard() != null) {
8498 return phone.getIccCard().getIccLockEnabled();
8499 } else {
8500 return false;
8501 }
8502 } finally {
8503 Binder.restoreCallingIdentity(identity);
8504 }
8505 }
8506
8507 /**
8508 * Set the ICC pin lock enabled or disabled.
8509 *
8510 * @return an integer representing the status of IccLock enabled or disabled in the following
8511 * three cases:
8512 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8513 * successfully.
8514 * - Positive number and zero for remaining password attempts.
8515 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8516 *
8517 */
8518 @Override
8519 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8520 enforceModifyPermission();
8521
8522 Phone phone = getPhone(subId);
8523 if (phone == null) {
8524 return 0;
8525 }
8526 // Now that all security checks passes, perform the operation as ourselves.
8527 final long identity = Binder.clearCallingIdentity();
8528 try {
8529 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8530 new Pair<Boolean, String>(enabled, password), phone, null);
8531 return attemptsRemaining;
8532
8533 } catch (Exception e) {
8534 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8535 } finally {
8536 Binder.restoreCallingIdentity(identity);
8537 }
8538 return 0;
8539 }
8540
8541 /**
8542 * Change the ICC password used in ICC pin lock.
8543 *
8544 * @return an integer representing the status of IccLock changed in the following three cases:
8545 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8546 * - Positive number and zero for remaining password attempts.
8547 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8548 *
8549 */
8550 @Override
8551 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8552 enforceModifyPermission();
8553
8554 Phone phone = getPhone(subId);
8555 if (phone == null) {
8556 return 0;
8557 }
8558 // Now that all security checks passes, perform the operation as ourselves.
8559 final long identity = Binder.clearCallingIdentity();
8560 try {
8561 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8562 new Pair<String, String>(oldPassword, newPassword), phone, null);
8563 return attemptsRemaining;
8564
8565 } catch (Exception e) {
8566 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8567 } finally {
8568 Binder.restoreCallingIdentity(identity);
8569 }
8570 return 0;
8571 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008572
8573 /**
8574 * Request for receiving user activity notification
8575 */
8576 @Override
8577 public void requestUserActivityNotification() {
8578 if (!mNotifyUserActivity.get()
8579 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8580 mNotifyUserActivity.set(true);
8581 }
8582 }
8583
8584 /**
8585 * Called when userActivity is signalled in the power manager.
8586 * This is safe to call from any thread, with any window manager locks held or not.
8587 */
8588 @Override
8589 public void userActivity() {
8590 // ***************************************
8591 // * Inherited from PhoneWindowManager *
8592 // ***************************************
8593 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8594 // WITH ITS LOCKS HELD.
8595 //
8596 // This code must be VERY careful about the locks
8597 // it acquires.
8598 // In fact, the current code acquires way too many,
8599 // and probably has lurking deadlocks.
8600
8601 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8602 throw new SecurityException("Only the OS may call notifyUserActivity()");
8603 }
8604
8605 if (mNotifyUserActivity.getAndSet(false)) {
8606 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8607 USER_ACTIVITY_NOTIFICATION_DELAY);
8608 }
8609 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008610
8611 @Override
8612 public boolean canConnectTo5GInDsdsMode() {
8613 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008615}