Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 794db1b7 authored by Vincent Wang's avatar Vincent Wang
Browse files

Move fingerprint and face haptic form server to sysui(1/3)

BUG: 237621645
Test: Check the vibrator work normally when using biometric unlock
Change-Id: I16a847358fc0d4a5d486275a76a97a5195b2dddb
parent 0ce3d6f9
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -30,5 +30,4 @@
         lockscreen, setting this to true should come with customized drawables. -->
    <bool name="use_lock_pattern_drawable">false</bool>
    <bool name="resolver_landscape_phone">true</bool>
    <bool name="system_server_plays_face_haptics">true</bool>
</resources>
+0 −1
Original line number Diff line number Diff line
@@ -4847,6 +4847,5 @@

  <java-symbol type="dimen" name="status_bar_height_default" />

  <java-symbol type="bool" name="system_server_plays_face_haptics" />
  <java-symbol type="string" name="default_card_name"/>
</resources>
+21 −1
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ import com.android.systemui.doze.DozeReceiver;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.VibratorHelper;
import com.android.systemui.util.concurrency.DelayableExecutor;
import com.android.systemui.util.concurrency.Execution;

@@ -152,6 +153,19 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
    @NonNull private final InteractionJankMonitor mInteractionJankMonitor;
    private final @Background DelayableExecutor mBackgroundExecutor;


    private final VibratorHelper mVibratorHelper;

    private void vibrateSuccess(int modality) {
        mVibratorHelper.vibrateAuthSuccess(
                getClass().getSimpleName() + ", modality = " + modality + "BP::success");
    }

    private void vibrateError(int modality) {
        mVibratorHelper.vibrateAuthError(
                getClass().getSimpleName() + ", modality = " + modality + "BP::error");
    }

    @VisibleForTesting
    final TaskStackListener mTaskStackListener = new TaskStackListener() {
        @Override
@@ -599,7 +613,8 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
            @NonNull StatusBarStateController statusBarStateController,
            @NonNull InteractionJankMonitor jankMonitor,
            @Main Handler handler,
            @Background DelayableExecutor bgExecutor) {
            @Background DelayableExecutor bgExecutor,
            @NonNull VibratorHelper vibrator) {
        super(context);
        mExecution = execution;
        mUserManager = userManager;
@@ -616,6 +631,7 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
        mWindowManager = windowManager;
        mInteractionJankMonitor = jankMonitor;
        mUdfpsEnrolledForUser = new SparseBooleanArray();
        mVibratorHelper = vibrator;

        mOrientationListener = new BiometricDisplayListener(
                context,
@@ -837,6 +853,8 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
    public void onBiometricAuthenticated(@Modality int modality) {
        if (DEBUG) Log.d(TAG, "onBiometricAuthenticated: ");

        vibrateSuccess(modality);

        if (mCurrentDialog != null) {
            mCurrentDialog.onAuthenticationSucceeded(modality);
        } else {
@@ -884,6 +902,8 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
            Log.d(TAG, String.format("onBiometricError(%d, %d, %d)", modality, error, vendorCode));
        }

        vibrateError(modality);

        final boolean isLockout = (error == BiometricConstants.BIOMETRIC_ERROR_LOCKOUT)
                || (error == BiometricConstants.BIOMETRIC_ERROR_LOCKOUT_PERMANENT);

+30 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.statusbar;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.media.AudioAttributes;
import android.os.Process;
import android.os.VibrationAttributes;
import android.os.VibrationEffect;
import android.os.Vibrator;
@@ -33,6 +34,7 @@ import java.util.concurrent.Executor;
import javax.inject.Inject;

/**
 *
 */
@SysUISingleton
public class VibratorHelper {
@@ -40,9 +42,18 @@ public class VibratorHelper {
    private final Vibrator mVibrator;
    private static final VibrationAttributes TOUCH_VIBRATION_ATTRIBUTES =
            VibrationAttributes.createForUsage(VibrationAttributes.USAGE_TOUCH);

    private static final VibrationEffect BIOMETRIC_SUCCESS_VIBRATION_EFFECT =
            VibrationEffect.get(VibrationEffect.EFFECT_CLICK);
    private static final VibrationEffect BIOMETRIC_ERROR_VIBRATION_EFFECT =
            VibrationEffect.get(VibrationEffect.EFFECT_DOUBLE_CLICK);
    private static final VibrationAttributes HARDWARE_FEEDBACK_VIBRATION_ATTRIBUTES =
            VibrationAttributes.createForUsage(VibrationAttributes.USAGE_HARDWARE_FEEDBACK);

    private final Executor mExecutor;

    /**
     *
     */
    @Inject
    public VibratorHelper(@Nullable Vibrator vibrator, @Background Executor executor) {
@@ -109,4 +120,23 @@ public class VibratorHelper {
        }
        mExecutor.execute(mVibrator::cancel);
    }

    /**
     * Perform vibration when biometric authentication success
     */
    public void vibrateAuthSuccess(String reason) {
        vibrate(Process.myUid(),
                "com.android.systemui",
                BIOMETRIC_SUCCESS_VIBRATION_EFFECT, reason,
                HARDWARE_FEEDBACK_VIBRATION_ATTRIBUTES);
    }

    /**
     * Perform vibration when biometric authentication error
     */
    public void vibrateAuthError(String reason) {
        vibrate(Process.myUid(), "com.android.systemui",
                BIOMETRIC_ERROR_VIBRATION_EFFECT, reason,
                HARDWARE_FEEDBACK_VIBRATION_ATTRIBUTES);
    }
}
+14 −34
Original line number Diff line number Diff line
@@ -28,11 +28,8 @@ import android.hardware.fingerprint.FingerprintManager;
import android.metrics.LogMaker;
import android.os.Handler;
import android.os.PowerManager;
import android.os.Process;
import android.os.SystemClock;
import android.os.Trace;
import android.os.VibrationAttributes;
import android.os.VibrationEffect;
import android.util.Log;

import androidx.annotation.Nullable;
@@ -88,12 +85,6 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp
    private static final String BIOMETRIC_WAKE_LOCK_NAME = "wake-and-unlock:wakelock";
    private static final UiEventLogger UI_EVENT_LOGGER = new UiEventLoggerImpl();
    private static final int UDFPS_ATTEMPTS_BEFORE_SHOW_BOUNCER = 3;
    private static final VibrationEffect SUCCESS_VIBRATION_EFFECT =
            VibrationEffect.get(VibrationEffect.EFFECT_CLICK);
    private static final VibrationEffect ERROR_VIBRATION_EFFECT =
            VibrationEffect.get(VibrationEffect.EFFECT_DOUBLE_CLICK);
    private static final VibrationAttributes HARDWARE_FEEDBACK_VIBRATION_ATTRIBUTES =
            VibrationAttributes.createForUsage(VibrationAttributes.USAGE_HARDWARE_FEEDBACK);

    @IntDef(prefix = { "MODE_" }, value = {
            MODE_NONE,
@@ -169,7 +160,6 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp
    private final NotificationShadeWindowController mNotificationShadeWindowController;
    private final SessionTracker mSessionTracker;
    private final int mConsecutiveFpFailureThreshold;
    private final boolean mShouldVibrate;
    private int mMode;
    private BiometricSourceType mBiometricType;
    private KeyguardViewController mKeyguardViewController;
@@ -311,8 +301,6 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp
        mHandler = handler;
        mConsecutiveFpFailureThreshold = resources.getInteger(
                R.integer.fp_consecutive_failure_time_ms);
        mShouldVibrate = !(resources.getBoolean(
                com.android.internal.R.bool.system_server_plays_face_haptics));
        mKeyguardBypassController = keyguardBypassController;
        mKeyguardBypassController.setUnlockController(this);
        mMetricsLogger = metricsLogger;
@@ -427,10 +415,10 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp
    public void startWakeAndUnlock(BiometricSourceType biometricSourceType,
                                   boolean isStrongBiometric) {
        int mode = calculateMode(biometricSourceType, isStrongBiometric);
        if (BiometricSourceType.FACE == biometricSourceType && (mode == MODE_WAKE_AND_UNLOCK
        if (mode == MODE_WAKE_AND_UNLOCK
                || mode == MODE_WAKE_AND_UNLOCK_PULSING || mode == MODE_UNLOCK_COLLAPSING
                || mode == MODE_WAKE_AND_UNLOCK_FROM_DREAM || mode == MODE_DISMISS_BOUNCER)) {
            vibrateSuccess();
                || mode == MODE_WAKE_AND_UNLOCK_FROM_DREAM || mode == MODE_DISMISS_BOUNCER) {
            vibrateSuccess(biometricSourceType);
        }
        startWakeAndUnlock(mode);
    }
@@ -672,10 +660,11 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp
        }

        // Suppress all face auth errors if fingerprint can be used to authenticate
        if (biometricSourceType == BiometricSourceType.FACE
        if ((biometricSourceType == BiometricSourceType.FACE
                && !mUpdateMonitor.getCachedIsUnlockWithFingerprintPossible(
                KeyguardUpdateMonitor.getCurrentUser())) {
            vibrateError();
                KeyguardUpdateMonitor.getCurrentUser()))
                || (biometricSourceType == BiometricSourceType.FINGERPRINT)) {
            vibrateError(biometricSourceType);
        }

        cleanup();
@@ -704,24 +693,15 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp
        cleanup();
    }

    private void vibrateSuccess() {
        if (mShouldVibrate) {
            mVibratorHelper.vibrate(Process.myUid(),
                    "com.android.systemui",
                    SUCCESS_VIBRATION_EFFECT,
                    getClass().getSimpleName() + "::success",
                    HARDWARE_FEEDBACK_VIBRATION_ATTRIBUTES);
        }
    //these haptics are for device-entry only
    private void vibrateSuccess(BiometricSourceType type) {
        mVibratorHelper.vibrateAuthSuccess(
                getClass().getSimpleName() + ", type =" + type + "device-entry::success");
    }

    private void vibrateError() {
        if (mShouldVibrate) {
            mVibratorHelper.vibrate(Process.myUid(),
                    "com.android.systemui",
                    ERROR_VIBRATION_EFFECT,
                    getClass().getSimpleName() + "::error",
                    HARDWARE_FEEDBACK_VIBRATION_ATTRIBUTES);
        }
    private void vibrateError(BiometricSourceType type) {
        mVibratorHelper.vibrateAuthError(
                getClass().getSimpleName() + ", type =" + type + "device-entry::error");
    }

    private void cleanup() {
Loading