Merge "Move haptic from FaceAuthenticationClient to SysUI(1/2)" into tm-d1-dev

This commit is contained in:
Vincent Wang
2022-06-13 05:16:08 +00:00
committed by Android (Google) Code Review
5 changed files with 67 additions and 5 deletions

View File

@@ -30,4 +30,5 @@
lockscreen, setting this to true should come with customized drawables. --> lockscreen, setting this to true should come with customized drawables. -->
<bool name="use_lock_pattern_drawable">false</bool> <bool name="use_lock_pattern_drawable">false</bool>
<bool name="resolver_landscape_phone">true</bool> <bool name="resolver_landscape_phone">true</bool>
<bool name="system_server_plays_face_haptics">true</bool>
</resources> </resources>

View File

@@ -4801,4 +4801,6 @@
<java-symbol type="id" name="language_picker_header" /> <java-symbol type="id" name="language_picker_header" />
<java-symbol type="dimen" name="status_bar_height_default" /> <java-symbol type="dimen" name="status_bar_height_default" />
<java-symbol type="bool" name="system_server_plays_face_haptics" />
</resources> </resources>

View File

@@ -27,8 +27,11 @@ import android.hardware.fingerprint.FingerprintManager;
import android.metrics.LogMaker; import android.metrics.LogMaker;
import android.os.Handler; import android.os.Handler;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.Process;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.Trace; import android.os.Trace;
import android.os.VibrationAttributes;
import android.os.VibrationEffect;
import android.util.Log; import android.util.Log;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@@ -61,6 +64,7 @@ import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.NotificationMediaManager; import com.android.systemui.statusbar.NotificationMediaManager;
import com.android.systemui.statusbar.NotificationShadeWindowController; import com.android.systemui.statusbar.NotificationShadeWindowController;
import com.android.systemui.statusbar.StatusBarState; import com.android.systemui.statusbar.StatusBarState;
import com.android.systemui.statusbar.VibratorHelper;
import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.statusbar.policy.KeyguardStateController;
import java.io.PrintWriter; import java.io.PrintWriter;
@@ -83,6 +87,12 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp
private static final String BIOMETRIC_WAKE_LOCK_NAME = "wake-and-unlock:wakelock"; private static final String BIOMETRIC_WAKE_LOCK_NAME = "wake-and-unlock:wakelock";
private static final UiEventLogger UI_EVENT_LOGGER = new UiEventLoggerImpl(); private static final UiEventLogger UI_EVENT_LOGGER = new UiEventLoggerImpl();
private static final int FP_ATTEMPTS_BEFORE_SHOW_BOUNCER = 2; private static final int FP_ATTEMPTS_BEFORE_SHOW_BOUNCER = 2;
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 = { @IntDef(prefix = { "MODE_" }, value = {
MODE_NONE, MODE_NONE,
@@ -158,6 +168,7 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp
private final NotificationShadeWindowController mNotificationShadeWindowController; private final NotificationShadeWindowController mNotificationShadeWindowController;
private final SessionTracker mSessionTracker; private final SessionTracker mSessionTracker;
private final int mConsecutiveFpFailureThreshold; private final int mConsecutiveFpFailureThreshold;
private final boolean mShouldVibrate;
private int mMode; private int mMode;
private BiometricSourceType mBiometricType; private BiometricSourceType mBiometricType;
private KeyguardViewController mKeyguardViewController; private KeyguardViewController mKeyguardViewController;
@@ -174,6 +185,7 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp
private final AuthController mAuthController; private final AuthController mAuthController;
private final StatusBarStateController mStatusBarStateController; private final StatusBarStateController mStatusBarStateController;
private final LatencyTracker mLatencyTracker; private final LatencyTracker mLatencyTracker;
private final VibratorHelper mVibratorHelper;
private long mLastFpFailureUptimeMillis; private long mLastFpFailureUptimeMillis;
private int mNumConsecutiveFpFailures; private int mNumConsecutiveFpFailures;
@@ -278,7 +290,8 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp
KeyguardUnlockAnimationController keyguardUnlockAnimationController, KeyguardUnlockAnimationController keyguardUnlockAnimationController,
SessionTracker sessionTracker, SessionTracker sessionTracker,
LatencyTracker latencyTracker, LatencyTracker latencyTracker,
ScreenOffAnimationController screenOffAnimationController) { ScreenOffAnimationController screenOffAnimationController,
VibratorHelper vibrator) {
mPowerManager = powerManager; mPowerManager = powerManager;
mShadeController = shadeController; mShadeController = shadeController;
mUpdateMonitor = keyguardUpdateMonitor; mUpdateMonitor = keyguardUpdateMonitor;
@@ -297,6 +310,8 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp
mHandler = handler; mHandler = handler;
mConsecutiveFpFailureThreshold = resources.getInteger( mConsecutiveFpFailureThreshold = resources.getInteger(
R.integer.fp_consecutive_failure_time_ms); R.integer.fp_consecutive_failure_time_ms);
mShouldVibrate = !(resources.getBoolean(
com.android.internal.R.bool.system_server_plays_face_haptics));
mKeyguardBypassController = keyguardBypassController; mKeyguardBypassController = keyguardBypassController;
mKeyguardBypassController.setUnlockController(this); mKeyguardBypassController.setUnlockController(this);
mMetricsLogger = metricsLogger; mMetricsLogger = metricsLogger;
@@ -305,6 +320,8 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp
mKeyguardUnlockAnimationController = keyguardUnlockAnimationController; mKeyguardUnlockAnimationController = keyguardUnlockAnimationController;
mSessionTracker = sessionTracker; mSessionTracker = sessionTracker;
mScreenOffAnimationController = screenOffAnimationController; mScreenOffAnimationController = screenOffAnimationController;
mVibratorHelper = vibrator;
dumpManager.registerDumpable(getClass().getName(), this); dumpManager.registerDumpable(getClass().getName(), this);
} }
@@ -407,8 +424,14 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp
} }
public void startWakeAndUnlock(BiometricSourceType biometricSourceType, public void startWakeAndUnlock(BiometricSourceType biometricSourceType,
boolean isStrongBiometric) { boolean isStrongBiometric) {
startWakeAndUnlock(calculateMode(biometricSourceType, isStrongBiometric)); int mode = calculateMode(biometricSourceType, isStrongBiometric);
if (BiometricSourceType.FACE == biometricSourceType && (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();
}
startWakeAndUnlock(mode);
} }
public void startWakeAndUnlock(@WakeAndUnlockMode int mode) { public void startWakeAndUnlock(@WakeAndUnlockMode int mode) {
@@ -652,6 +675,11 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp
mNumConsecutiveFpFailures = 0; mNumConsecutiveFpFailures = 0;
} }
} }
if (biometricSourceType == BiometricSourceType.FACE) {
vibrateError();
}
cleanup(); cleanup();
} }
@@ -674,9 +702,34 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp
startWakeAndUnlock(MODE_SHOW_BOUNCER); startWakeAndUnlock(MODE_SHOW_BOUNCER);
UI_EVENT_LOGGER.log(BiometricUiEvent.BIOMETRIC_BOUNCER_SHOWN, getSessionId()); UI_EVENT_LOGGER.log(BiometricUiEvent.BIOMETRIC_BOUNCER_SHOWN, getSessionId());
} }
if (biometricSourceType == BiometricSourceType.FACE) {
vibrateError();
}
cleanup(); cleanup();
} }
private void vibrateSuccess() {
if (mShouldVibrate) {
mVibratorHelper.vibrate(Process.myUid(),
"com.android.systemui",
SUCCESS_VIBRATION_EFFECT,
getClass().getSimpleName() + "::success",
HARDWARE_FEEDBACK_VIBRATION_ATTRIBUTES);
}
}
private void vibrateError() {
if (mShouldVibrate) {
mVibratorHelper.vibrate(Process.myUid(),
"com.android.systemui",
ERROR_VIBRATION_EFFECT,
getClass().getSimpleName() + "::error",
HARDWARE_FEEDBACK_VIBRATION_ATTRIBUTES);
}
}
private void cleanup() { private void cleanup() {
releaseBiometricWakeLock(); releaseBiometricWakeLock();
} }

View File

@@ -51,6 +51,7 @@ import com.android.systemui.log.SessionTracker;
import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.NotificationMediaManager; import com.android.systemui.statusbar.NotificationMediaManager;
import com.android.systemui.statusbar.NotificationShadeWindowController; import com.android.systemui.statusbar.NotificationShadeWindowController;
import com.android.systemui.statusbar.VibratorHelper;
import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.statusbar.policy.KeyguardStateController;
import org.junit.Before; import org.junit.Before;
@@ -115,6 +116,8 @@ public class BiometricsUnlockControllerTest extends SysuiTestCase {
private LatencyTracker mLatencyTracker; private LatencyTracker mLatencyTracker;
@Mock @Mock
private ScreenOffAnimationController mScreenOffAnimationController; private ScreenOffAnimationController mScreenOffAnimationController;
@Mock
private VibratorHelper mVibratorHelper;
private BiometricUnlockController mBiometricUnlockController; private BiometricUnlockController mBiometricUnlockController;
@Before @Before
@@ -136,7 +139,7 @@ public class BiometricsUnlockControllerTest extends SysuiTestCase {
mMetricsLogger, mDumpManager, mPowerManager, mMetricsLogger, mDumpManager, mPowerManager,
mNotificationMediaManager, mWakefulnessLifecycle, mScreenLifecycle, mNotificationMediaManager, mWakefulnessLifecycle, mScreenLifecycle,
mAuthController, mStatusBarStateController, mKeyguardUnlockAnimationController, mAuthController, mStatusBarStateController, mKeyguardUnlockAnimationController,
mSessionTracker, mLatencyTracker, mScreenOffAnimationController); mSessionTracker, mLatencyTracker, mScreenOffAnimationController, mVibratorHelper);
mBiometricUnlockController.setKeyguardViewController(mStatusBarKeyguardViewManager); mBiometricUnlockController.setKeyguardViewController(mStatusBarKeyguardViewManager);
mBiometricUnlockController.setBiometricModeListener(mBiometricModeListener); mBiometricUnlockController.setBiometricModeListener(mBiometricModeListener);
} }

View File

@@ -99,7 +99,10 @@ class FaceAuthenticationClient extends AuthenticationClient<AidlSession>
super(context, lazyDaemon, token, listener, targetUserId, operationId, restricted, super(context, lazyDaemon, token, listener, targetUserId, operationId, restricted,
owner, cookie, requireConfirmation, sensorId, logger, biometricContext, owner, cookie, requireConfirmation, sensorId, logger, biometricContext,
isStrongBiometric, null /* taskStackListener */, lockoutCache, isStrongBiometric, null /* taskStackListener */, lockoutCache,
allowBackgroundAuthentication, true /* shouldVibrate */, allowBackgroundAuthentication,
context.getResources().getBoolean(
com.android.internal.R.bool.system_server_plays_face_haptics)
/* shouldVibrate */,
isKeyguardBypassEnabled); isKeyguardBypassEnabled);
setRequestId(requestId); setRequestId(requestId);
mUsageStats = usageStats; mUsageStats = usageStats;