From 0dbb516a4383f022420d57b7af1865eb37cb3021 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Fri, 25 May 2018 15:13:36 +0100 Subject: [PATCH] Allow for any default vibration intensity level. Because we can't always create the range of effects we'd like, we may need different default intensity levels for different devices. This works fine for prebaked effects, but for application defined amplitudes we need to provide a scaling function. In addition, this scaling function should leave amplitude values untouched in the default state so that application developers produce the effects they expect. Bug: 80275800 Test: manual Merged-In: Ibb552ddfa60891853ebcb1a5567ed6745bb5defe Change-Id: Ibb552ddfa60891853ebcb1a5567ed6745bb5defe --- core/java/android/os/Vibrator.java | 23 +++- core/res/res/values/config.xml | 9 ++ core/res/res/values/symbols.xml | 3 + .../com/android/server/VibratorService.java | 103 ++++++++++++------ 4 files changed, 105 insertions(+), 33 deletions(-) diff --git a/core/java/android/os/Vibrator.java b/core/java/android/os/Vibrator.java index f1f6f414eba88..d2d8f1e159e59 100644 --- a/core/java/android/os/Vibrator.java +++ b/core/java/android/os/Vibrator.java @@ -72,12 +72,23 @@ public abstract class Vibrator { public @interface VibrationIntensity{} private final String mPackageName; + // The default vibration intensity level for haptic feedback. + @VibrationIntensity + private final int mDefaultHapticFeedbackIntensity; + // The default vibration intensity level for notifications. + @VibrationIntensity + private final int mDefaultNotificationVibrationIntensity; /** * @hide to prevent subclassing from outside of the framework */ public Vibrator() { mPackageName = ActivityThread.currentPackageName(); + final Context ctx = ActivityThread.currentActivityThread().getSystemContext(); + mDefaultHapticFeedbackIntensity = loadDefaultIntensity(ctx, + com.android.internal.R.integer.config_defaultHapticFeedbackIntensity); + mDefaultNotificationVibrationIntensity = loadDefaultIntensity(ctx, + com.android.internal.R.integer.config_defaultNotificationVibrationIntensity); } /** @@ -85,6 +96,14 @@ public abstract class Vibrator { */ protected Vibrator(Context context) { mPackageName = context.getOpPackageName(); + mDefaultHapticFeedbackIntensity = loadDefaultIntensity(context, + com.android.internal.R.integer.config_defaultHapticFeedbackIntensity); + mDefaultNotificationVibrationIntensity = loadDefaultIntensity(context, + com.android.internal.R.integer.config_defaultNotificationVibrationIntensity); + } + + private int loadDefaultIntensity(Context ctx, int resId) { + return ctx != null ? ctx.getResources().getInteger(resId) : VIBRATION_INTENSITY_MEDIUM; } /** @@ -92,7 +111,7 @@ public abstract class Vibrator { * @hide */ public int getDefaultHapticFeedbackIntensity() { - return VIBRATION_INTENSITY_MEDIUM; + return mDefaultHapticFeedbackIntensity; } /** @@ -100,7 +119,7 @@ public abstract class Vibrator { * @hide */ public int getDefaultNotificationVibrationIntensity() { - return VIBRATION_INTENSITY_HIGH; + return mDefaultNotificationVibrationIntensity; } /** diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index b0ecb3ecf11df..c856ed81d5758 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -1108,6 +1108,15 @@ + + 2 + + 2 + false