From fa727c7facbad0d590bd1f008046c97b90091b26 Mon Sep 17 00:00:00 2001 From: Lais Andrade Date: Tue, 2 Jun 2020 14:26:55 +0000 Subject: [PATCH] Add more options to cmd vibrator - Add option -s to prekabed, to enable fallback on unsupported effect; - Add command capabilities to print HAL capabilities; - Add attribute USAGE_TOUCH to apply Settings.System.HAPTIC_FEEDBACK_INTENSITY to scale effects; Fix: 157984210 Test: manual Change-Id: Ie2d63a46d16387abe853ae12c20fb6a808020662 Merged-In: Ie77c4309e7c464b32e8dd6150a7840f1dc385e14 --- .../com/android/server/VibratorService.java | 60 +++++++++++++++---- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/services/core/java/com/android/server/VibratorService.java b/services/core/java/com/android/server/VibratorService.java index e066d99147ba2..a153d4191a5c5 100644 --- a/services/core/java/com/android/server/VibratorService.java +++ b/services/core/java/com/android/server/VibratorService.java @@ -1894,6 +1894,8 @@ public class VibratorService extends IVibratorService.Stub return runWaveform(); } else if ("prebaked".equals(cmd)) { return runPrebaked(); + } else if ("capabilities".equals(cmd)) { + return runCapabilities(); } else if ("cancel".equals(cmd)) { cancelVibrate(mToken); return 0; @@ -2016,10 +2018,15 @@ public class VibratorService extends IVibratorService.Stub Trace.traceBegin(Trace.TRACE_TAG_VIBRATOR, "runPrebaked"); try { CommonOptions commonOptions = new CommonOptions(); + boolean shouldFallback = false; String opt; while ((opt = getNextOption()) != null) { - commonOptions.check(opt); + if ("-b".equals(opt)) { + shouldFallback = true; + } else { + commonOptions.check(opt); + } } if (checkDoNotDisturb(commonOptions)) { @@ -2033,8 +2040,7 @@ public class VibratorService extends IVibratorService.Stub description = "Shell command"; } - VibrationEffect effect = - VibrationEffect.get(id, false); + VibrationEffect effect = VibrationEffect.get(id, shouldFallback); VibrationAttributes attrs = createVibrationAttributes(commonOptions); vibrate(Binder.getCallingUid(), description, effect, attrs, "Shell Command", mToken); @@ -2044,12 +2050,39 @@ public class VibratorService extends IVibratorService.Stub } } + private int runCapabilities() { + Trace.traceBegin(Trace.TRACE_TAG_VIBRATOR, "runCapabilities"); + try (PrintWriter pw = getOutPrintWriter();) { + pw.println("Vibrator capabilities:"); + if (hasCapability(IVibrator.CAP_ALWAYS_ON_CONTROL)) { + pw.println(" Always on effects"); + } + if (hasCapability(IVibrator.CAP_COMPOSE_EFFECTS)) { + pw.println(" Compose effects"); + } + if (mSupportsAmplitudeControl || hasCapability(IVibrator.CAP_AMPLITUDE_CONTROL)) { + pw.println(" Amplitude control"); + } + if (mSupportsExternalControl || hasCapability(IVibrator.CAP_EXTERNAL_CONTROL)) { + pw.println(" External control"); + } + if (hasCapability(IVibrator.CAP_EXTERNAL_AMPLITUDE_CONTROL)) { + pw.println(" External amplitude control"); + } + pw.println(""); + return 0; + } finally { + Trace.traceEnd(Trace.TRACE_TAG_VIBRATOR); + } + } + private VibrationAttributes createVibrationAttributes(CommonOptions commonOptions) { final int flags = commonOptions.force ? VibrationAttributes.FLAG_BYPASS_INTERRUPTION_POLICY : 0; return new VibrationAttributes.Builder() - .setUsage(VibrationAttributes.USAGE_UNKNOWN) + // Used to apply Settings.System.HAPTIC_FEEDBACK_INTENSITY to scale effects. + .setUsage(VibrationAttributes.USAGE_TOUCH) .replaceFlags(flags) .build(); } @@ -2062,19 +2095,26 @@ public class VibratorService extends IVibratorService.Stub pw.println(" Prints this help text."); pw.println(""); pw.println(" vibrate duration [description]"); - pw.println(" Vibrates for duration milliseconds; ignored when device is on DND "); - pw.println(" (Do Not Disturb) mode."); + pw.println(" Vibrates for duration milliseconds; ignored when device is on "); + pw.println(" DND (Do Not Disturb) mode; touch feedback strength user setting "); + pw.println(" will be used to scale amplitude."); pw.println(" waveform [-d description] [-r index] [-a] duration [amplitude] ..."); - pw.println(" Vibrates for durations and amplitudes in list;"); - pw.println(" ignored when device is on DND (Do Not Disturb) mode."); + pw.println(" Vibrates for durations and amplitudes in list; ignored when "); + pw.println(" device is on DND (Do Not Disturb) mode; touch feedback strength "); + pw.println(" user setting will be used to scale amplitude."); pw.println(" If -r is provided, the waveform loops back to the specified"); pw.println(" index (e.g. 0 loops from the beginning)"); pw.println(" If -a is provided, the command accepts duration-amplitude pairs;"); pw.println(" otherwise, it accepts durations only and alternates off/on"); pw.println(" Duration is in milliseconds; amplitude is a scale of 1-255."); - pw.println(" prebaked effect-id [description]"); + pw.println(" prebaked [-b] effect-id [description]"); pw.println(" Vibrates with prebaked effect; ignored when device is on DND "); - pw.println(" (Do Not Disturb) mode."); + pw.println(" (Do Not Disturb) mode; touch feedback strength user setting "); + pw.println(" will be used to scale amplitude."); + pw.println(" If -b is provided, the prebaked fallback effect will be played if"); + pw.println(" the device doesn't support the given effect-id."); + pw.println(" capabilities"); + pw.println(" Prints capabilities of this device."); pw.println(" cancel"); pw.println(" Cancels any active vibration"); pw.println("Common Options:");