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 4e543a38f6037cee6f6237c755d9fdc00270d6e2)
Merged-In:I7253f7f08fde04e30400a30d9a0d24f1ceff04b0
diff --git a/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragment.java
index 0d130d9..fe14c52 100644
--- a/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragment.java
+++ b/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragment.java
@@ -18,12 +18,16 @@
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 android.provider.SearchIndexableResource;
import com.android.settings.R;
import com.android.settings.bluetooth.BluetoothFilesPreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.nfc.AndroidBeamPreferenceController;
+import com.android.settings.nfc.SecureNfcPreferenceController;
import com.android.settings.print.PrintSettingPreferenceController;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -106,6 +110,11 @@
if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC)) {
keys.add(AndroidBeamPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
}
+ final UserManager userManager = context.getSystemService(UserManager.class);
+ final UserInfo myUserInfo = userManager.getUserInfo(UserHandle.myUserId());
+ if (myUserInfo.isGuest()) {
+ keys.add(SecureNfcPreferenceController.KEY_SECURENFC_SETTINGS);
+ }
return keys;
}
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;
+ }
}
diff --git a/src/com/android/settings/nfc/SecureNfcPreferenceController.java b/src/com/android/settings/nfc/SecureNfcPreferenceController.java
index 12dbd57..1a514a6 100644
--- a/src/com/android/settings/nfc/SecureNfcPreferenceController.java
+++ b/src/com/android/settings/nfc/SecureNfcPreferenceController.java
@@ -29,6 +29,7 @@
public class SecureNfcPreferenceController extends TogglePreferenceController
implements LifecycleObserver, OnResume, OnPause {
+ public static final String KEY_SECURENFC_SETTINGS = "nfc_secure_settings";
private final NfcAdapter mNfcAdapter;
private SecureNfcEnabler mSecureNfcEnabler;