Do not let guest user disable secure nfc
Bug: 209446496
Test: manual
Merged-In: I7253f7f08fde04e30400a30d9a0d24f1ceff04b0
Change-Id: I7253f7f08fde04e30400a30d9a0d24f1ceff04b0
(cherry picked from commit d9e3e6e4b1c3cb1a04dba0f530505843ef44a748)
(cherry picked from commit a579ca7554dcbfd3fce1c90451fb54cb676cfdda)
Merged-In:I7253f7f08fde04e30400a30d9a0d24f1ceff04b0
diff --git a/src/com/android/settings/connecteddevice/NfcAndPaymentFragment.java b/src/com/android/settings/connecteddevice/NfcAndPaymentFragment.java
index 4ebc0cd..feb757f 100644
--- a/src/com/android/settings/connecteddevice/NfcAndPaymentFragment.java
+++ b/src/com/android/settings/connecteddevice/NfcAndPaymentFragment.java
@@ -17,6 +17,12 @@
package com.android.settings.connecteddevice;
import android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.pm.UserInfo;
+import android.os.UserHandle;
+import android.os.UserManager;
+
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
@@ -54,5 +60,16 @@
* For Search.
*/
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
- new BaseSearchIndexProvider(R.xml.nfc_and_payment_settings);
+ new BaseSearchIndexProvider(R.xml.nfc_and_payment_settings) {
+ @Override
+ protected boolean isPageSearchEnabled(Context context) {
+ final UserManager userManager = context.getSystemService(UserManager.class);
+ final UserInfo myUserInfo = userManager.getUserInfo(UserHandle.myUserId());
+ if (myUserInfo.isGuest()) {
+ return false;
+ }
+ final PackageManager pm = context.getPackageManager();
+ return pm.hasSystemFeature(PackageManager.FEATURE_NFC);
+ }
+ };
}
diff --git a/src/com/android/settings/nfc/SecureNfcEnabler.java b/src/com/android/settings/nfc/SecureNfcEnabler.java
index 9acaf64..f31a382 100644
--- a/src/com/android/settings/nfc/SecureNfcEnabler.java
+++ b/src/com/android/settings/nfc/SecureNfcEnabler.java
@@ -18,9 +18,8 @@
import android.content.Context;
import android.nfc.NfcAdapter;
-import android.provider.Settings;
+import android.os.UserManager;
-import androidx.annotation.VisibleForTesting;
import androidx.preference.SwitchPreference;
import com.android.settings.R;
@@ -32,10 +31,12 @@
*/
public class SecureNfcEnabler extends BaseNfcEnabler {
private final SwitchPreference mPreference;
+ private final UserManager mUserManager;
public SecureNfcEnabler(Context context, SwitchPreference preference) {
super(context);
mPreference = preference;
+ mUserManager = context.getSystemService(UserManager.class);
}
@Override
@@ -48,7 +49,7 @@
case NfcAdapter.STATE_ON:
mPreference.setSummary(R.string.nfc_secure_toggle_summary);
mPreference.setChecked(mPreference.isChecked());
- mPreference.setEnabled(true);
+ mPreference.setEnabled(isToggleable());
break;
case NfcAdapter.STATE_TURNING_ON:
mPreference.setEnabled(false);
@@ -58,4 +59,11 @@
break;
}
}
+
+ private boolean isToggleable() {
+ if (mUserManager.isGuestUser()) {
+ return false;
+ }
+ return true;
+ }
}