From bebf04aaaf9ba3ceef2695d2c8e5d0bfcc30703b Mon Sep 17 00:00:00 2001 From: Alexey Kuzmin Date: Thu, 4 Apr 2019 18:39:38 +0100 Subject: [PATCH] Add fallback for TEXTURE_TICK TEXTURE_TICK vibration effect should fallback to TICK effect if not supported by HAL (and, if necessary, fallback further to TICK effect fallback) Bug: 129275029 Test: atest VibrationEffectTest Test: adb cmd vibrator prebaked 21 on a phone which does not support TEXTURE_TICK - you should feel the device vibrates Change-Id: I788b0835312e2b2ab590c26ef2f9961fe542cf77 --- api/test-current.txt | 1 + core/java/android/os/VibrationEffect.java | 1 + services/core/java/com/android/server/VibratorService.java | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/api/test-current.txt b/api/test-current.txt index 17199fa3c7a45..983930e3066d1 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -1895,6 +1895,7 @@ package android.os { field public static final int EFFECT_STRENGTH_LIGHT = 0; // 0x0 field public static final int EFFECT_STRENGTH_MEDIUM = 1; // 0x1 field public static final int EFFECT_STRENGTH_STRONG = 2; // 0x2 + field public static final int EFFECT_TEXTURE_TICK = 21; // 0x15 field public static final int EFFECT_THUD = 3; // 0x3 field public static final int[] RINGTONES; } diff --git a/core/java/android/os/VibrationEffect.java b/core/java/android/os/VibrationEffect.java index 7958ddd29c70f..035061b614f87 100644 --- a/core/java/android/os/VibrationEffect.java +++ b/core/java/android/os/VibrationEffect.java @@ -104,6 +104,7 @@ public abstract class VibrationEffect implements Parcelable { * @see #get(int) * @hide */ + @TestApi public static final int EFFECT_TEXTURE_TICK = Effect.TEXTURE_TICK; /** {@hide} */ diff --git a/services/core/java/com/android/server/VibratorService.java b/services/core/java/com/android/server/VibratorService.java index 5d0fa26f640ed..ba562610c7b89 100644 --- a/services/core/java/com/android/server/VibratorService.java +++ b/services/core/java/com/android/server/VibratorService.java @@ -236,6 +236,7 @@ public class VibratorService extends IVibratorService.Stub case VibrationEffect.EFFECT_CLICK: case VibrationEffect.EFFECT_DOUBLE_CLICK: case VibrationEffect.EFFECT_HEAVY_CLICK: + case VibrationEffect.EFFECT_TEXTURE_TICK: case VibrationEffect.EFFECT_TICK: case VibrationEffect.EFFECT_POP: case VibrationEffect.EFFECT_THUD: @@ -379,6 +380,9 @@ public class VibratorService extends IVibratorService.Stub mFallbackEffects.put(VibrationEffect.EFFECT_TICK, tickEffect); mFallbackEffects.put(VibrationEffect.EFFECT_HEAVY_CLICK, heavyClickEffect); + mFallbackEffects.put(VibrationEffect.EFFECT_TEXTURE_TICK, + VibrationEffect.get(VibrationEffect.EFFECT_TICK, false)); + mScaleLevels = new SparseArray<>(); mScaleLevels.put(SCALE_VERY_LOW, new ScaleLevel(SCALE_VERY_LOW_GAMMA, SCALE_VERY_LOW_MAX_AMPLITUDE));