From 8ff8bd327c8e857001ebc53e701b7476111c971a Mon Sep 17 00:00:00 2001 From: Dan Sandler Date: Mon, 29 Mar 2021 21:40:15 -0400 Subject: [PATCH] Custom haptic composition for assistant launched via button. The effect is a small ramp, a 50ms gap, and a sharp tick, evoking the crisp snap of a sail, or a molecule's bonds approaching and then snapping together. It might be nice to start this effect slightly early, but that will require more tweaking to the keypress messaging and timers. We'll see if it's necessary. For devices without haptic composer support, fall back to EFFECT_DOUBLE_CLICK. Bug: 182381083 Test: manual (literally, you have to hold the device): adb shell settings put global power_button_long_press 5 adb shell input keyevent --longpress POWER (or just hold the power button, since you're holding the device) Change-Id: I0633efd46296ca3f34e5df60be37871fb1a9fb5d --- .../java/android/view/HapticFeedbackConstants.java | 6 ++++++ .../android/server/policy/PhoneWindowManager.java | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/HapticFeedbackConstants.java b/core/java/android/view/HapticFeedbackConstants.java index c62e934630484..9f63500fc8535 100644 --- a/core/java/android/view/HapticFeedbackConstants.java +++ b/core/java/android/view/HapticFeedbackConstants.java @@ -128,6 +128,12 @@ public class HapticFeedbackConstants { */ public static final int SAFE_MODE_ENABLED = 10001; + /** + * Invocation of the voice assistant via hardware button. + * @hide + */ + public static final int ASSISTANT_BUTTON = 10002; + /** * Flag for {@link View#performHapticFeedback(int, int) * View.performHapticFeedback(int, int)}: Ignore the setting in the diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index f18546474ecea..315103acc793e 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -1100,7 +1100,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { break; case LONG_PRESS_POWER_ASSISTANT: mPowerKeyHandled = true; - performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, false, + performHapticFeedback(HapticFeedbackConstants.ASSISTANT_BUTTON, false, "Power - Long Press - Go To Assistant"); final int powerKeyDeviceId = Integer.MIN_VALUE; launchAssistAction(null, powerKeyDeviceId, eventTime); @@ -5074,6 +5074,18 @@ public class PhoneWindowManager implements WindowManagerPolicy { pattern = mSafeModeEnabledVibePattern; break; + case HapticFeedbackConstants.ASSISTANT_BUTTON: + if (mVibrator.areAllPrimitivesSupported( + VibrationEffect.Composition.PRIMITIVE_QUICK_RISE)) { + // quiet ramp, short pause, then sharp tick + return VibrationEffect.startComposition() + .addPrimitive(VibrationEffect.Composition.PRIMITIVE_QUICK_RISE, 0.25f) + .addPrimitive(VibrationEffect.Composition.PRIMITIVE_TICK, 1f, 50) + .compose(); + } + // fallback for devices without composition support + return VibrationEffect.get(VibrationEffect.EFFECT_DOUBLE_CLICK); + default: return null; }