Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c56bec4b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add more options to cmd vibrator" into rvc-dev am: 70efc10d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11691825

Change-Id: I92c103e264cecfb1e9961111681f8545dc2ddfad
parents 12e0ba73 70efc10d
Loading
Loading
Loading
Loading
+50 −10
Original line number Diff line number Diff line
@@ -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,11 +2018,16 @@ 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) {
                    if ("-b".equals(opt)) {
                        shouldFallback = true;
                    } else {
                        commonOptions.check(opt);
                    }
                }

                if (checkDoNotDisturb(commonOptions)) {
                    return 0;
@@ -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:");