Merge "[Gaze] Support Gaze" into main
This commit is contained in:
@@ -848,4 +848,7 @@
|
|||||||
|
|
||||||
<!-- Disable the Testing Setting Menu for user builds, i.e only display the menu on userdebug/eng builds -->
|
<!-- Disable the Testing Setting Menu for user builds, i.e only display the menu on userdebug/eng builds -->
|
||||||
<bool name="config_hide_testing_settings_menu_for_user_builds">false</bool>
|
<bool name="config_hide_testing_settings_menu_for_user_builds">false</bool>
|
||||||
|
|
||||||
|
<!-- Whether the Gaze is enabled -->
|
||||||
|
<bool name="config_gazeEnabled">false</bool>
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -924,6 +924,10 @@
|
|||||||
<string name="security_settings_face_settings_require_attention">Require eyes to be open</string>
|
<string name="security_settings_face_settings_require_attention">Require eyes to be open</string>
|
||||||
<!-- Text shown on the details of a toggle which disables/enables face unlock, depending if the user's eyes are open. [CHAR LIMIT=70] -->
|
<!-- Text shown on the details of a toggle which disables/enables face unlock, depending if the user's eyes are open. [CHAR LIMIT=70] -->
|
||||||
<string name="security_settings_face_settings_require_attention_details">To unlock the phone, your eyes must be open</string>
|
<string name="security_settings_face_settings_require_attention_details">To unlock the phone, your eyes must be open</string>
|
||||||
|
<!-- Text shown on a toggle which disables/enables face unlock, depending if the gaze supported. [CHAR LIMIT=30] -->
|
||||||
|
<string name="security_settings_face_settings_gaze"></string>
|
||||||
|
<!-- Text shown on the details of a toggle which disables/enables face unlock, depending if the gaze supported. [CHAR LIMIT=70] -->
|
||||||
|
<string name="security_settings_face_settings_gaze_details"></string>
|
||||||
<!-- When authenticating in apps, always require confirmation (e.g. confirm button) after a face is authenticated. [CHAR LIMIT=50] -->
|
<!-- When authenticating in apps, always require confirmation (e.g. confirm button) after a face is authenticated. [CHAR LIMIT=50] -->
|
||||||
<string name="security_settings_face_settings_require_confirmation">Always require confirmation</string>
|
<string name="security_settings_face_settings_require_confirmation">Always require confirmation</string>
|
||||||
<!-- When authenticating in apps, always require confirmation (e.g. confirm button) after a face is authenticated. [CHAR LIMIT=70] -->
|
<!-- When authenticating in apps, always require confirmation (e.g. confirm button) after a face is authenticated. [CHAR LIMIT=70] -->
|
||||||
|
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2025 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.biometrics.face;
|
||||||
|
|
||||||
|
import static android.hardware.biometrics.BiometricFaceConstants.FEATURE_REQUIRE_ATTENTION;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.hardware.face.FaceManager;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.android.settings.Utils;
|
||||||
|
|
||||||
|
public class FaceAttentionController {
|
||||||
|
|
||||||
|
@Nullable private byte[] mToken;
|
||||||
|
private FaceManager mFaceManager;
|
||||||
|
|
||||||
|
public interface OnSetAttentionListener {
|
||||||
|
/**
|
||||||
|
* Calls when setting attention is completed from FaceManager.
|
||||||
|
*/
|
||||||
|
void onSetAttentionCompleted(boolean success);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnGetAttentionListener {
|
||||||
|
/**
|
||||||
|
* Calls when getting attention is completed from FaceManager.
|
||||||
|
*/
|
||||||
|
void onGetAttentionCompleted(boolean success, boolean enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable private OnSetAttentionListener mSetListener;
|
||||||
|
@Nullable private OnGetAttentionListener mGetListener;
|
||||||
|
|
||||||
|
private final FaceManager.SetFeatureCallback mSetFeatureCallback =
|
||||||
|
new FaceManager.SetFeatureCallback() {
|
||||||
|
@Override
|
||||||
|
public void onCompleted(boolean success, int feature) {
|
||||||
|
if (feature == FEATURE_REQUIRE_ATTENTION) {
|
||||||
|
if (mSetListener != null) {
|
||||||
|
mSetListener.onSetAttentionCompleted(success);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final FaceManager.GetFeatureCallback mGetFeatureCallback =
|
||||||
|
new FaceManager.GetFeatureCallback() {
|
||||||
|
@Override
|
||||||
|
public void onCompleted(
|
||||||
|
boolean success, @NonNull int[] features, @NonNull boolean[] featureState) {
|
||||||
|
boolean requireAttentionEnabled = false;
|
||||||
|
for (int i = 0; i < features.length; i++) {
|
||||||
|
if (features[i] == FEATURE_REQUIRE_ATTENTION) {
|
||||||
|
requireAttentionEnabled = featureState[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mGetListener != null) {
|
||||||
|
mGetListener.onGetAttentionCompleted(success, requireAttentionEnabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public FaceAttentionController(@NonNull Context context) {
|
||||||
|
mFaceManager = Utils.getFaceManagerOrNull(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the challenge token
|
||||||
|
*/
|
||||||
|
public void setToken(@Nullable byte[] token) {
|
||||||
|
mToken = token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the gaze status
|
||||||
|
*/
|
||||||
|
public void getAttentionStatus(int userId,
|
||||||
|
@Nullable OnGetAttentionListener listener) {
|
||||||
|
mGetListener = listener;
|
||||||
|
mFaceManager.getFeature(userId, FEATURE_REQUIRE_ATTENTION, mGetFeatureCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the gaze status
|
||||||
|
*/
|
||||||
|
public void setAttentionStatus(
|
||||||
|
int userId, boolean enabled, @Nullable OnSetAttentionListener listener) {
|
||||||
|
mSetListener = listener;
|
||||||
|
mFaceManager.setFeature(userId, FEATURE_REQUIRE_ATTENTION, enabled, mToken,
|
||||||
|
mSetFeatureCallback);
|
||||||
|
}
|
||||||
|
}
|
@@ -69,6 +69,7 @@ public class FaceEnrollEducation extends BiometricEnrollBase {
|
|||||||
private View mIllustrationAccessibility;
|
private View mIllustrationAccessibility;
|
||||||
private Intent mResultIntent;
|
private Intent mResultIntent;
|
||||||
private boolean mAccessibilityEnabled;
|
private boolean mAccessibilityEnabled;
|
||||||
|
protected Intent mExtraInfoIntent;
|
||||||
|
|
||||||
private final CompoundButton.OnCheckedChangeListener mSwitchDiversityListener =
|
private final CompoundButton.OnCheckedChangeListener mSwitchDiversityListener =
|
||||||
new CompoundButton.OnCheckedChangeListener() {
|
new CompoundButton.OnCheckedChangeListener() {
|
||||||
@@ -171,12 +172,7 @@ public class FaceEnrollEducation extends BiometricEnrollBase {
|
|||||||
mFooterBarMixin.setPrimaryButton(footerButton);
|
mFooterBarMixin.setPrimaryButton(footerButton);
|
||||||
|
|
||||||
final Button accessibilityButton = findViewById(R.id.accessibility_button);
|
final Button accessibilityButton = findViewById(R.id.accessibility_button);
|
||||||
accessibilityButton.setOnClickListener(view -> {
|
accessibilityButton.setOnClickListener(this::onAccessibilityButtonClicked);
|
||||||
mSwitchDiversity.setChecked(true);
|
|
||||||
accessibilityButton.setVisibility(View.GONE);
|
|
||||||
mSwitchDiversity.setVisibility(View.VISIBLE);
|
|
||||||
mSwitchDiversity.addOnLayoutChangeListener(mSwitchDiversityOnLayoutChangeListener);
|
|
||||||
});
|
|
||||||
|
|
||||||
mSwitchDiversity = findViewById(R.id.toggle_diversity);
|
mSwitchDiversity = findViewById(R.id.toggle_diversity);
|
||||||
mSwitchDiversity.setListener(mSwitchDiversityListener);
|
mSwitchDiversity.setListener(mSwitchDiversityListener);
|
||||||
@@ -263,6 +259,9 @@ public class FaceEnrollEducation extends BiometricEnrollBase {
|
|||||||
if (mResultIntent != null) {
|
if (mResultIntent != null) {
|
||||||
intent.putExtras(mResultIntent);
|
intent.putExtras(mResultIntent);
|
||||||
}
|
}
|
||||||
|
if (mExtraInfoIntent != null) {
|
||||||
|
intent.putExtras(mExtraInfoIntent);
|
||||||
|
}
|
||||||
|
|
||||||
intent.putExtra(EXTRA_KEY_REQUIRE_DIVERSITY, !mSwitchDiversity.isChecked());
|
intent.putExtra(EXTRA_KEY_REQUIRE_DIVERSITY, !mSwitchDiversity.isChecked());
|
||||||
intent.putExtra(BiometricUtils.EXTRA_ENROLL_REASON,
|
intent.putExtra(BiometricUtils.EXTRA_ENROLL_REASON,
|
||||||
@@ -282,6 +281,13 @@ public class FaceEnrollEducation extends BiometricEnrollBase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void onAccessibilityButtonClicked(View view) {
|
||||||
|
mSwitchDiversity.setChecked(true);
|
||||||
|
view.setVisibility(View.GONE);
|
||||||
|
mSwitchDiversity.setVisibility(View.VISIBLE);
|
||||||
|
mSwitchDiversity.addOnLayoutChangeListener(mSwitchDiversityOnLayoutChangeListener);
|
||||||
|
}
|
||||||
|
|
||||||
protected void onSkipButtonClick(View view) {
|
protected void onSkipButtonClick(View view) {
|
||||||
if (!BiometricUtils.tryStartingNextBiometricEnroll(this, ENROLL_NEXT_BIOMETRIC_REQUEST,
|
if (!BiometricUtils.tryStartingNextBiometricEnroll(this, ENROLL_NEXT_BIOMETRIC_REQUEST,
|
||||||
"edu_skip")) {
|
"edu_skip")) {
|
||||||
|
@@ -16,12 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settings.biometrics.face;
|
package com.android.settings.biometrics.face;
|
||||||
|
|
||||||
import static android.hardware.biometrics.BiometricFaceConstants.FEATURE_REQUIRE_ATTENTION;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.hardware.face.FaceManager;
|
import android.hardware.face.FaceManager;
|
||||||
import android.hardware.face.FaceManager.GetFeatureCallback;
|
|
||||||
import android.hardware.face.FaceManager.SetFeatureCallback;
|
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@@ -31,6 +27,7 @@ import androidx.preference.TwoStatePreference;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
|
import com.android.settings.flags.Flags;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preference controller that manages the ability to use face authentication with/without
|
* Preference controller that manages the ability to use face authentication with/without
|
||||||
@@ -40,14 +37,13 @@ public class FaceSettingsAttentionPreferenceController extends FaceSettingsPrefe
|
|||||||
|
|
||||||
public static final String KEY = "security_settings_face_require_attention";
|
public static final String KEY = "security_settings_face_require_attention";
|
||||||
|
|
||||||
private byte[] mToken;
|
|
||||||
private FaceManager mFaceManager;
|
|
||||||
private TwoStatePreference mPreference;
|
private TwoStatePreference mPreference;
|
||||||
|
private boolean mGazeEnabled;
|
||||||
|
|
||||||
private final SetFeatureCallback mSetFeatureCallback = new SetFeatureCallback() {
|
private FaceAttentionController mFaceAttentionController;
|
||||||
@Override
|
|
||||||
public void onCompleted(boolean success, int feature) {
|
private final FaceAttentionController.OnSetAttentionListener mSetAttentionListener =
|
||||||
if (feature == FEATURE_REQUIRE_ATTENTION) {
|
(success) -> {
|
||||||
mPreference.setEnabled(true);
|
mPreference.setEnabled(true);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
mPreference.setChecked(!mPreference.isChecked());
|
mPreference.setChecked(!mPreference.isChecked());
|
||||||
@@ -56,31 +52,23 @@ public class FaceSettingsAttentionPreferenceController extends FaceSettingsPrefe
|
|||||||
Settings.Secure.FACE_UNLOCK_ATTENTION_REQUIRED,
|
Settings.Secure.FACE_UNLOCK_ATTENTION_REQUIRED,
|
||||||
mPreference.isChecked() ? 1 : 0, getUserId());
|
mPreference.isChecked() ? 1 : 0, getUserId());
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final GetFeatureCallback mGetFeatureCallback = new GetFeatureCallback() {
|
private final FaceAttentionController.OnGetAttentionListener mOnGetAttentionListener =
|
||||||
@Override
|
(success, requireAttentionEnabled) -> {
|
||||||
public void onCompleted(boolean success, int[] features, boolean[] featureState) {
|
mPreference.setChecked(requireAttentionEnabled);
|
||||||
boolean requireAttentionEnabled = false;
|
if (getRestrictingAdmin() != null) {
|
||||||
for (int i = 0; i < features.length; i++) {
|
mPreference.setEnabled(false);
|
||||||
if (features[i] == FEATURE_REQUIRE_ATTENTION) {
|
} else {
|
||||||
requireAttentionEnabled = featureState[i];
|
mPreference.setEnabled(success);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
mPreference.setChecked(requireAttentionEnabled);
|
|
||||||
if (getRestrictingAdmin() != null) {
|
|
||||||
mPreference.setEnabled(false);
|
|
||||||
} else {
|
|
||||||
mPreference.setEnabled(success);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public FaceSettingsAttentionPreferenceController(Context context, String preferenceKey) {
|
public FaceSettingsAttentionPreferenceController(Context context, String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
mFaceManager = Utils.getFaceManagerOrNull(context);
|
mFaceAttentionController = new FaceAttentionController(context);
|
||||||
|
mGazeEnabled = context.getResources().getBoolean(R.bool.config_gazeEnabled)
|
||||||
|
&& Flags.biometricsOnboardingEducation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public FaceSettingsAttentionPreferenceController(Context context) {
|
public FaceSettingsAttentionPreferenceController(Context context) {
|
||||||
@@ -88,7 +76,9 @@ public class FaceSettingsAttentionPreferenceController extends FaceSettingsPrefe
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setToken(byte[] token) {
|
public void setToken(byte[] token) {
|
||||||
mToken = token;
|
if (mFaceAttentionController != null) {
|
||||||
|
mFaceAttentionController.setToken(token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,6 +99,11 @@ public class FaceSettingsAttentionPreferenceController extends FaceSettingsPrefe
|
|||||||
if (Utils.isPrivateProfile(getUserId(), mContext)) {
|
if (Utils.isPrivateProfile(getUserId(), mContext)) {
|
||||||
preference.setSummary(mContext.getString(
|
preference.setSummary(mContext.getString(
|
||||||
R.string.private_space_face_settings_require_attention_details));
|
R.string.private_space_face_settings_require_attention_details));
|
||||||
|
} else if (mGazeEnabled) {
|
||||||
|
preference.setTitle(mContext.getString(
|
||||||
|
R.string.security_settings_face_settings_gaze));
|
||||||
|
preference.setSummary(mContext.getString(
|
||||||
|
R.string.security_settings_face_settings_gaze_details));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,8 +114,7 @@ public class FaceSettingsAttentionPreferenceController extends FaceSettingsPrefe
|
|||||||
}
|
}
|
||||||
// Set to disabled until we know the true value.
|
// Set to disabled until we know the true value.
|
||||||
mPreference.setEnabled(false);
|
mPreference.setEnabled(false);
|
||||||
mFaceManager.getFeature(getUserId(), FEATURE_REQUIRE_ATTENTION,
|
mFaceAttentionController.getAttentionStatus(getUserId(), mOnGetAttentionListener);
|
||||||
mGetFeatureCallback);
|
|
||||||
|
|
||||||
// Ideally returns a cached value.
|
// Ideally returns a cached value.
|
||||||
return true;
|
return true;
|
||||||
@@ -131,9 +125,7 @@ public class FaceSettingsAttentionPreferenceController extends FaceSettingsPrefe
|
|||||||
// Optimistically update state and set to disabled until we know it succeeded.
|
// Optimistically update state and set to disabled until we know it succeeded.
|
||||||
mPreference.setEnabled(false);
|
mPreference.setEnabled(false);
|
||||||
mPreference.setChecked(isChecked);
|
mPreference.setChecked(isChecked);
|
||||||
|
mFaceAttentionController.setAttentionStatus(getUserId(), isChecked, mSetAttentionListener);
|
||||||
mFaceManager.setFeature(getUserId(), FEATURE_REQUIRE_ATTENTION,
|
|
||||||
isChecked, mToken, mSetFeatureCallback);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user