Merge "Show in UI if admin has disabled face auth" into rvc-dev
diff --git a/res/xml/security_settings_face.xml b/res/xml/security_settings_face.xml
index 858911d..d450fef 100644
--- a/res/xml/security_settings_face.xml
+++ b/res/xml/security_settings_face.xml
@@ -29,7 +29,7 @@
<PreferenceCategory
android:key="security_settings_face_unlock_category"
android:title="@string/security_settings_face_settings_use_face_category">
- <SwitchPreference
+ <com.android.settingslib.RestrictedSwitchPreference
android:key="security_settings_face_keyguard"
android:title="@string/security_settings_face_settings_use_face_unlock_phone"
app:keywords="@string/keywords_face_unlock"
@@ -39,7 +39,7 @@
android:title="@string/security_settings_face_settings_use_face_for_apps"
app:keywords="@string/keywords_face_unlock"
app:controller="com.android.settings.biometrics.face.FaceSettingsAppPreferenceController"/>
- <SwitchPreference
+ <com.android.settingslib.RestrictedSwitchPreference
android:key="security_lockscreen_bypass"
android:title="@string/lockscreen_bypass_title"
android:summary="@string/lockscreen_bypass_summary"
diff --git a/src/com/android/settings/biometrics/face/FaceSettingsKeyguardPreferenceController.java b/src/com/android/settings/biometrics/face/FaceSettingsKeyguardPreferenceController.java
index 9ec1ad1..7e7a748 100644
--- a/src/com/android/settings/biometrics/face/FaceSettingsKeyguardPreferenceController.java
+++ b/src/com/android/settings/biometrics/face/FaceSettingsKeyguardPreferenceController.java
@@ -25,6 +25,8 @@
import androidx.preference.Preference;
import com.android.settings.Utils;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+import com.android.settingslib.RestrictedSwitchPreference;
/**
* Preference controller for Face settings page controlling the ability to unlock the phone
@@ -53,7 +55,7 @@
public boolean isChecked() {
if (!FaceSettings.isAvailable(mContext)) {
return false;
- } else if (adminDisabled()) {
+ } else if (getRestrictingAdmin() != null) {
return false;
}
return Settings.Secure.getIntForUser(mContext.getContentResolver(),
@@ -73,11 +75,12 @@
@Override
public void updateState(Preference preference) {
+ EnforcedAdmin admin;
super.updateState(preference);
if (!FaceSettings.isAvailable(mContext)) {
preference.setEnabled(false);
- } else if (adminDisabled()) {
- preference.setEnabled(false);
+ } else if ((admin = getRestrictingAdmin()) != null) {
+ ((RestrictedSwitchPreference) preference).setDisabledByAdmin(admin);
} else if (!mFaceManager.hasEnrolledTemplates(getUserId())) {
preference.setEnabled(false);
} else {
diff --git a/src/com/android/settings/biometrics/face/FaceSettingsLockscreenBypassPreferenceController.java b/src/com/android/settings/biometrics/face/FaceSettingsLockscreenBypassPreferenceController.java
index cef174d..50c45ba 100644
--- a/src/com/android/settings/biometrics/face/FaceSettingsLockscreenBypassPreferenceController.java
+++ b/src/com/android/settings/biometrics/face/FaceSettingsLockscreenBypassPreferenceController.java
@@ -26,6 +26,8 @@
import androidx.preference.Preference;
import com.android.internal.annotations.VisibleForTesting;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+import com.android.settingslib.RestrictedSwitchPreference;
public class FaceSettingsLockscreenBypassPreferenceController
extends FaceSettingsPreferenceController {
@@ -60,11 +62,12 @@
@Override
public void updateState(Preference preference) {
+ EnforcedAdmin admin;
super.updateState(preference);
if (!FaceSettings.isAvailable(mContext)) {
preference.setEnabled(false);
- } else if (adminDisabled()) {
- preference.setEnabled(false);
+ } else if ((admin = getRestrictingAdmin()) != null) {
+ ((RestrictedSwitchPreference) preference).setDisabledByAdmin(admin);
} else if (!mFaceManager.hasEnrolledTemplates(getUserId())) {
preference.setEnabled(false);
} else {
diff --git a/src/com/android/settings/biometrics/face/FaceSettingsPreferenceController.java b/src/com/android/settings/biometrics/face/FaceSettingsPreferenceController.java
index 55e093b..3149c35 100644
--- a/src/com/android/settings/biometrics/face/FaceSettingsPreferenceController.java
+++ b/src/com/android/settings/biometrics/face/FaceSettingsPreferenceController.java
@@ -18,9 +18,10 @@
import android.app.admin.DevicePolicyManager;
import android.content.Context;
-import android.os.UserHandle;
import com.android.settings.core.TogglePreferenceController;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+import com.android.settingslib.RestrictedLockUtilsInternal;
/**
* Abstract base class for all face settings toggles.
@@ -41,12 +42,8 @@
return mUserId;
}
- protected boolean adminDisabled() {
- DevicePolicyManager dpm =
- (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
- return dpm != null &&
- (dpm.getKeyguardDisabledFeatures(null, UserHandle.myUserId())
- & DevicePolicyManager.KEYGUARD_DISABLE_FACE)
- != 0;
+ protected EnforcedAdmin getRestrictingAdmin() {
+ return RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled(
+ mContext, DevicePolicyManager.KEYGUARD_DISABLE_FACE, mUserId);
}
}