From 950bd77fb78dde252dea4799ec13726972b6773e Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Thu, 21 Mar 2019 21:26:05 +0000 Subject: [PATCH] Move TEXT_HANDLE_MOVE and CLOCK_TICK to TEXTURE_TICK. TEXTURE_TICK is a new constant that is expected to be called repeatedly in order to simulate a texture effect when a user is interacting with the device, like with TEXT_HANDLE_MOVE. Bug: 111461797 Test: Manual Change-Id: Ia21de3ce1755a908b4bd4fcbdda411864e5b9fe9 --- core/java/android/os/VibrationEffect.java | 19 ++++++++++++++++--- .../server/policy/PhoneWindowManager.java | 4 +++- .../com_android_server_VibratorService.cpp | 5 ++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/core/java/android/os/VibrationEffect.java b/core/java/android/os/VibrationEffect.java index c74cbff567c51..7958ddd29c70f 100644 --- a/core/java/android/os/VibrationEffect.java +++ b/core/java/android/os/VibrationEffect.java @@ -23,7 +23,7 @@ import android.annotation.TestApi; import android.content.ContentResolver; import android.content.Context; import android.hardware.vibrator.V1_0.EffectStrength; -import android.hardware.vibrator.V1_2.Effect; +import android.hardware.vibrator.V1_3.Effect; import android.net.Uri; import android.util.MathUtils; @@ -94,6 +94,18 @@ public abstract class VibrationEffect implements Parcelable { */ public static final int EFFECT_HEAVY_CLICK = Effect.HEAVY_CLICK; + /** + * A texture effect meant to replicate soft ticks. + * + * Unlike normal effects, texture effects are meant to be called repeatedly, generally in + * response to some motion, in order to replicate the feeling of some texture underneath the + * user's fingers. + * + * @see #get(int) + * @hide + */ + public static final int EFFECT_TEXTURE_TICK = Effect.TEXTURE_TICK; + /** {@hide} */ @TestApi public static final int EFFECT_STRENGTH_LIGHT = EffectStrength.LIGHT; @@ -746,6 +758,7 @@ public abstract class VibrationEffect implements Parcelable { case EFFECT_CLICK: case EFFECT_DOUBLE_CLICK: case EFFECT_TICK: + case EFFECT_TEXTURE_TICK: case EFFECT_THUD: case EFFECT_POP: case EFFECT_HEAVY_CLICK: @@ -798,7 +811,7 @@ public abstract class VibrationEffect implements Parcelable { out.writeInt(mEffectStrength); } - public static final @android.annotation.NonNull Parcelable.Creator CREATOR = + public static final @NonNull Parcelable.Creator CREATOR = new Parcelable.Creator() { @Override public Prebaked createFromParcel(Parcel in) { @@ -813,7 +826,7 @@ public abstract class VibrationEffect implements Parcelable { }; } - public static final @android.annotation.NonNull Parcelable.Creator CREATOR = + public static final @NonNull Parcelable.Creator CREATOR = new Parcelable.Creator() { @Override public VibrationEffect createFromParcel(Parcel in) { diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index 5a32aa0539ecd..eae83d2713b4d 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -5214,13 +5214,15 @@ public class PhoneWindowManager implements WindowManagerPolicy { private VibrationEffect getVibrationEffect(int effectId) { long[] pattern; switch (effectId) { - case HapticFeedbackConstants.CLOCK_TICK: case HapticFeedbackConstants.CONTEXT_CLICK: return VibrationEffect.get(VibrationEffect.EFFECT_TICK); case HapticFeedbackConstants.TEXT_HANDLE_MOVE: if (!mHapticTextHandleEnabled) { return null; } + // fallthrough + case HapticFeedbackConstants.CLOCK_TICK: + return VibrationEffect.get(VibrationEffect.EFFECT_TEXTURE_TICK); case HapticFeedbackConstants.KEYBOARD_RELEASE: case HapticFeedbackConstants.VIRTUAL_KEY_RELEASE: case HapticFeedbackConstants.ENTRY_BUMP: diff --git a/services/core/jni/com_android_server_VibratorService.cpp b/services/core/jni/com_android_server_VibratorService.cpp index 63dca62104a1e..d5fbd2b316e76 100644 --- a/services/core/jni/com_android_server_VibratorService.cpp +++ b/services/core/jni/com_android_server_VibratorService.cpp @@ -96,7 +96,7 @@ bool isValidEffect(jlong effect) { } R val = static_cast(effect); auto iter = hardware::hidl_enum_range(); - return val >= *iter.begin() && val < *std::prev(iter.end()); + return val >= *iter.begin() && val <= *std::prev(iter.end()); } static void vibratorInit(JNIEnv /* env */, jobject /* clazz */) @@ -170,6 +170,9 @@ static jlong vibratorPerformEffect(JNIEnv*, jobject, jlong effect, jint strength } else if (isValidEffect(effect)) { ret = halCall(&V1_2::IVibrator::perform_1_2, static_cast(effect), effectStrength, callback); + } else if (isValidEffect(effect)) { + ret = halCall(&V1_3::IVibrator::perform_1_3, static_cast(effect), + effectStrength, callback); } else { ALOGW("Unable to perform haptic effect, invalid effect ID (%" PRId32 ")", static_cast(effect));