Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
SystemUI: Tell user when face unlock detection is running
Browse files Browse the repository at this point in the history
Google removed the animation on Android 12, let's use a text instead

Change-Id: I93c4121c57137764edb0b31678d103fd5f7d4dcc
  • Loading branch information
jhenrique09 committed Mar 20, 2022
1 parent 24449a8 commit aa419ee
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 9 deletions.
3 changes: 3 additions & 0 deletions packages/SystemUI/res/values/custom_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<!-- Notify use that they are in Lock-to-app (for devices without navbar and with gestures on fingerprint sensor)-->
<string name="screen_pinning_toast_no_navbar_fpsensor">To unpin this screen, touch &amp; hold fingerprint sensor</string>

<!-- Face Unlock -->
<string name="face_unlock_recognizing">Recognizing face...</string>

<!-- Custom QS tiles -->
<!-- PowerShare QS tile -->
<string name="quick_settings_powershare_label">Wireless PowerShare</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ static class BiometricAuthenticated {
SettingsObserver mSettingsObserver;

private final boolean mFaceAuthOnlyOnSecurityView;
private static final int FACE_UNLOCK_BEHAVIOR_DEFAULT = 0;
private static final int FACE_UNLOCK_BEHAVIOR_SWIPE = 1;
public static final int FACE_UNLOCK_BEHAVIOR_DEFAULT = 0;
public static final int FACE_UNLOCK_BEHAVIOR_SWIPE = 1;
private int mFaceUnlockBehavior = FACE_UNLOCK_BEHAVIOR_DEFAULT;
private boolean mBouncerFullyShown;

Expand Down Expand Up @@ -2466,6 +2466,10 @@ public void onKeyguardBouncerFullyShown(boolean fullyShow) {
}
}

public int getFaceUnlockBehavior() {
return mFaceUnlockBehavior;
}

private void maybeLogListenerModelData(KeyguardListenModel model) {
// Too chatty, but very useful when debugging issues.
if (DEBUG_SPEW) {
Expand Down Expand Up @@ -2596,7 +2600,7 @@ private boolean isUnlockWithFingerprintPossible(int userId) {
&& mFpm.hasEnrolledTemplates(userId);
}

private boolean isUnlockWithFacePossible(int userId) {
public boolean isUnlockWithFacePossible(int userId) {
return isFaceAuthEnabledForUser(userId) && !isFaceDisabled(userId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_TRUST;
import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_USER_LOCKED;
import static com.android.systemui.plugins.FalsingManager.LOW_PENALTY;
import static com.android.keyguard.KeyguardUpdateMonitor.FACE_UNLOCK_BEHAVIOR_SWIPE;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
Expand Down Expand Up @@ -115,6 +116,8 @@ public class KeyguardIndicationController {
private static final int MSG_HIDE_TRANSIENT = 1;
private static final int MSG_SHOW_ACTION_TO_UNLOCK = 2;
private static final int MSG_HIDE_BIOMETRIC_MESSAGE = 3;
private static final int MSG_SHOW_RECOGNIZING_FACE = 4;
private static final int MSG_HIDE_RECOGNIZING_FACE = 5;
private static final long TRANSIENT_BIOMETRIC_ERROR_TIMEOUT = 1300;
private static final float BOUNCE_ANIMATION_FINAL_Y = 0f;

Expand Down Expand Up @@ -161,6 +164,7 @@ public class KeyguardIndicationController {
private long mChargingTimeRemaining;
private String mMessageToShowOnScreenOn;
private boolean mInited;
private boolean mFaceDetectionRunning;

private KeyguardUpdateMonitorCallback mUpdateMonitorCallback;

Expand Down Expand Up @@ -668,6 +672,47 @@ private void hideBiometricMessage() {
}
}

private void showFaceUnlockRecognizingMessage() {
if (mKeyguardUpdateMonitor.getFaceUnlockBehavior() == FACE_UNLOCK_BEHAVIOR_SWIPE){
return;
}

String faceUnlockMessage = mContext.getResources().getString(
R.string.face_unlock_recognizing);
mBiometricMessage = faceUnlockMessage;

mHandler.removeMessages(MSG_SHOW_ACTION_TO_UNLOCK);
mHandler.removeMessages(MSG_HIDE_BIOMETRIC_MESSAGE);

mRotateTextViewController.updateIndication(
INDICATION_TYPE_BIOMETRIC_MESSAGE,
new KeyguardIndication.Builder()
.setMessage(mBiometricMessage)
.setMinVisibilityMillis(6000L) // 6 seconds
.setTextColor(mInitialTextColorState)
.build(),
true
);

if (mDozing) {
updateIndication(false);
}
}

private void hideFaceUnlockRecognizingMessage() {
if (mKeyguardUpdateMonitor.getFaceUnlockBehavior() == FACE_UNLOCK_BEHAVIOR_SWIPE){
return;
}

String faceUnlockMessage = mContext.getResources().getString(
R.string.face_unlock_recognizing);
if (mBiometricMessage != null && mBiometricMessage == faceUnlockMessage) {
mBiometricMessage = null;
mHandler.removeMessages(MSG_HIDE_BIOMETRIC_MESSAGE);
updateBiometricMessage();
}
}

/**
* Hides transient indication.
*/
Expand Down Expand Up @@ -865,6 +910,11 @@ public void handleMessage(Message msg) {
showActionToUnlock();
} else if (msg.what == MSG_HIDE_BIOMETRIC_MESSAGE) {
hideBiometricMessage();
} else if (msg.what == MSG_SHOW_RECOGNIZING_FACE){
mMessageToShowOnScreenOn = null;
showFaceUnlockRecognizingMessage();
} else if (msg.what == MSG_HIDE_RECOGNIZING_FACE){
hideFaceUnlockRecognizingMessage();
}
}
};
Expand Down Expand Up @@ -1095,14 +1145,29 @@ public void onScreenTurnedOn() {
}
}

@Override
public void onScreenTurnedOff() {
if (mFaceDetectionRunning) {
mFaceDetectionRunning = false;
mMessageToShowOnScreenOn = null;
hideFaceUnlockRecognizingMessage();
}
}

@Override
public void onBiometricRunningStateChanged(boolean running,
BiometricSourceType biometricSourceType) {
if (running && biometricSourceType == BiometricSourceType.FACE) {
// Let's hide any previous messages when authentication starts, otherwise
// multiple auth attempts would overlap.
hideBiometricMessage();
mMessageToShowOnScreenOn = null;
if (biometricSourceType == BiometricSourceType.FACE) {
mFaceDetectionRunning = running;
if (running) {
mHandler.removeMessages(MSG_HIDE_RECOGNIZING_FACE);
mHandler.removeMessages(MSG_SHOW_RECOGNIZING_FACE);
mHandler.sendEmptyMessageDelayed(MSG_SHOW_RECOGNIZING_FACE, 100);
}else{
mHandler.removeMessages(MSG_SHOW_RECOGNIZING_FACE);
mHandler.removeMessages(MSG_HIDE_RECOGNIZING_FACE);
mHandler.sendEmptyMessageDelayed(MSG_HIDE_RECOGNIZING_FACE, 100);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import com.android.systemui.statusbar.phone.panelstate.PanelExpansionStateManager;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.R;

import java.io.PrintWriter;
import java.util.ArrayList;
Expand Down Expand Up @@ -126,6 +127,7 @@ public void onFullyShown() {
mStatusBar.wakeUpIfDozing(SystemClock.uptimeMillis(),
mStatusBar.getBouncerContainer(), "BOUNCER_VISIBLE");
onKeyguardBouncerFullyShownChanged(true);
showFaceRecognizingMessage();
}

@Override
Expand Down Expand Up @@ -223,6 +225,8 @@ public void onEvent(int event) {
private KeyguardBypassController mBypassController;
@Nullable private AlternateAuthInterceptor mAlternateAuthInterceptor;
private Handler mHandler;
private boolean mFaceRecognitionRunning = false;
private Handler mFaceRecognizingHandler;

private final KeyguardUpdateMonitorCallback mUpdateMonitorCallback =
new KeyguardUpdateMonitorCallback() {
Expand All @@ -235,6 +239,20 @@ public void onEmergencyCallAction() {
reset(true /* hideBouncerWhenShowing */);
}
}

@Override
public void onBiometricRunningStateChanged(boolean running,
BiometricSourceType biometricSourceType) {
if (biometricSourceType == BiometricSourceType.FACE &&
mKeyguardUpdateManager.isUnlockWithFacePossible(mKeyguardUpdateManager.getCurrentUser())){
mFaceRecognitionRunning = running;
if (!mFaceRecognitionRunning){
mFaceRecognizingHandler.removeCallbacksAndMessages(null);
}else{
mFaceRecognizingHandler.postDelayed(() -> showFaceRecognizingMessage(), 100);
}
}
}
};

@Inject
Expand All @@ -255,7 +273,8 @@ public StatusBarKeyguardViewManager(
UnlockedScreenOffAnimationController unlockedScreenOffAnimationController,
KeyguardMessageAreaController.Factory keyguardMessageAreaFactory,
Lazy<ShadeController> shadeController,
@Main Handler handler) {
@Main Handler handler,
@Main Handler faceRecognizingHandler) {
mContext = context;
mViewMediatorCallback = callback;
mLockPatternUtils = lockPatternUtils;
Expand All @@ -273,6 +292,7 @@ public StatusBarKeyguardViewManager(
mKeyguardMessageAreaFactory = keyguardMessageAreaFactory;
mShadeController = shadeController;
mHandler = handler;
mFaceRecognizingHandler = faceRecognizingHandler;
}

@Override
Expand Down Expand Up @@ -1166,6 +1186,13 @@ public void notifyKeyguardAuthenticated(boolean strongAuth) {
}
}

private void showFaceRecognizingMessage(){
if (mFaceRecognitionRunning &&
mKeyguardUpdateManager.isUnlockWithFacePossible(mKeyguardUpdateManager.getCurrentUser())) {
showBouncerMessage(mContext.getString(R.string.face_unlock_recognizing), null);
}
}

public void showBouncerMessage(String message, ColorStateList colorState) {
if (isShowingAlternateAuth()) {
if (mKeyguardMessageAreaController != null) {
Expand Down

0 comments on commit aa419ee

Please sign in to comment.