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

Commit 7b41ed78 authored by Lais Andrade's avatar Lais Andrade
Browse files

Improve VibratorManagerService dumpsys

Sometimes it can be hard to debug vibrations using a bugreport when the
user interacts with the keyboard during the bugreport generation. This
can create multiple touch vibrations that push all other touch
vibrations out of the buffer.

This change keeps the existing vibration records, now renamed to "recent
vibrations", and adds a new field "aggregated vibration history" which
aggregates vibrations by uid, attributes and effect when they are
requested  in close succession (less than 1s).

This change also introduces other improvements to dumpsys:

- Print VibrationSettings, VibrationConfig and VibratorController using
  multiple lines and indentation
- External vibration breakdown by usage
- Simplify each vibration text, printing a few lines for each vibration
  and simplifying the VibrationEffect string.

Fix: 260309860
Test: adb shell dumpsys vibrator_manager
Change-Id: I3d065a6264716185675f6a83ba61dcae71e8e38f
parent 19dae7cd
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
@@ -24,7 +24,9 @@ import com.android.internal.util.Preconditions;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.StringJoiner;

/**
 * A CombinedVibration describes a combination of haptic effects to be performed by one or more
@@ -150,6 +152,13 @@ public abstract class CombinedVibration implements Parcelable {
    /** @hide */
    public abstract boolean hasVibrator(int vibratorId);

    /**
     * Returns a compact version of the {@link #toString()} result for debugging purposes.
     *
     * @hide
     */
    public abstract String toDebugString();

    /**
     * Adapts a {@link VibrationEffect} to a specific device vibrator using the ID.
     *
@@ -437,6 +446,13 @@ public abstract class CombinedVibration implements Parcelable {
            return "Mono{mEffect=" + mEffect + '}';
        }

        /** @hide */
        @Override
        public String toDebugString() {
            // Simplify vibration string, use the single effect to represent it.
            return mEffect.toDebugString();
        }

        @Override
        public int describeContents() {
            return 0;
@@ -619,6 +635,17 @@ public abstract class CombinedVibration implements Parcelable {
            return "Stereo{mEffects=" + mEffects + '}';
        }

        /** @hide */
        @Override
        public String toDebugString() {
            StringJoiner sj = new StringJoiner(",", "Stereo{", "}");
            for (int i = 0; i < mEffects.size(); i++) {
                sj.add(String.format(Locale.ROOT, "vibrator(id=%d): %s",
                        mEffects.keyAt(i), mEffects.valueAt(i).toDebugString()));
            }
            return sj.toString();
        }

        @Override
        public int describeContents() {
            return 0;
@@ -833,6 +860,17 @@ public abstract class CombinedVibration implements Parcelable {
            return "Sequential{mEffects=" + mEffects + ", mDelays=" + mDelays + '}';
        }

        /** @hide */
        @Override
        public String toDebugString() {
            StringJoiner sj = new StringJoiner(",", "Sequential{", "}");
            for (int i = 0; i < mEffects.size(); i++) {
                sj.add(String.format(Locale.ROOT, "delayMs=%d, effect=%s",
                        mDelays.get(i), mEffects.get(i).toDebugString()));
            }
            return sj.toString();
        }

        @Override
        public int describeContents() {
            return 0;
+5 −4
Original line number Diff line number Diff line
@@ -336,10 +336,11 @@ public final class VibrationAttributes implements Parcelable {

    @Override
    public String toString() {
        return "VibrationAttributes:"
                + " Usage=" + usageToString()
                + " Audio Usage= " + AudioAttributes.usageToString(mOriginalAudioUsage)
                + " Flags=" + mFlags;
        return "VibrationAttributes{"
                + "mUsage=" + usageToString()
                + ", mAudioUsage= " + AudioAttributes.usageToString(mOriginalAudioUsage)
                + ", mFlags=" + mFlags
                + '}';
    }

    /** @hide */
+35 −9
Original line number Diff line number Diff line
@@ -44,7 +44,9 @@ import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.StringJoiner;

/**
 * A VibrationEffect describes a haptic effect to be performed by a {@link Vibrator}.
@@ -629,6 +631,13 @@ public abstract class VibrationEffect implements Parcelable {
        return MathUtils.constrain(a * fx, 0f, 1f);
    }

    /**
     * Returns a compact version of the {@link #toString()} result for debugging purposes.
     *
     * @hide
     */
    public abstract String toDebugString();

    /** @hide */
    public static String effectIdToString(int effectId) {
        switch (effectId) {
@@ -925,6 +934,23 @@ public abstract class VibrationEffect implements Parcelable {
                    + "}";
        }

        /** @hide */
        @Override
        public String toDebugString() {
            if (mSegments.size() == 1 && mRepeatIndex < 0) {
                // Simplify effect string, use the single segment to represent it.
                return mSegments.get(0).toDebugString();
            }
            StringJoiner sj = new StringJoiner(",", "[", "]");
            for (int i = 0; i < mSegments.size(); i++) {
                sj.add(mSegments.get(i).toDebugString());
            }
            if (mRepeatIndex >= 0) {
                return String.format(Locale.ROOT, "%s, repeat=%d", sj, mRepeatIndex);
            }
            return sj.toString();
        }

        @Override
        public int describeContents() {
            return 0;
@@ -1250,23 +1276,23 @@ public abstract class VibrationEffect implements Parcelable {
        public static String primitiveToString(@PrimitiveType int id) {
            switch (id) {
                case PRIMITIVE_NOOP:
                    return "PRIMITIVE_NOOP";
                    return "NOOP";
                case PRIMITIVE_CLICK:
                    return "PRIMITIVE_CLICK";
                    return "CLICK";
                case PRIMITIVE_THUD:
                    return "PRIMITIVE_THUD";
                    return "THUD";
                case PRIMITIVE_SPIN:
                    return "PRIMITIVE_SPIN";
                    return "SPIN";
                case PRIMITIVE_QUICK_RISE:
                    return "PRIMITIVE_QUICK_RISE";
                    return "QUICK_RISE";
                case PRIMITIVE_SLOW_RISE:
                    return "PRIMITIVE_SLOW_RISE";
                    return "SLOW_RISE";
                case PRIMITIVE_QUICK_FALL:
                    return "PRIMITIVE_QUICK_FALL";
                    return "QUICK_FALL";
                case PRIMITIVE_TICK:
                    return "PRIMITIVE_TICK";
                    return "TICK";
                case PRIMITIVE_LOW_TICK:
                    return "PRIMITIVE_LOW_TICK";
                    return "LOW_TICK";
                default:
                    return Integer.toString(id);
            }
+22 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.hardware.vibrator.Braking;
import android.hardware.vibrator.IVibrator;
import android.util.IndentingPrintWriter;
import android.util.MathUtils;
import android.util.Range;
import android.util.SparseBooleanArray;
@@ -207,6 +208,25 @@ public class VibratorInfo implements Parcelable {
                + '}';
    }

    /** @hide */
    public void dump(IndentingPrintWriter pw) {
        pw.println("VibratorInfo:");
        pw.increaseIndent();
        pw.println("id = " + mId);
        pw.println("capabilities = " + Arrays.toString(getCapabilitiesNames()));
        pw.println("capabilitiesFlags = " + Long.toBinaryString(mCapabilities));
        pw.println("supportedEffects = " + Arrays.toString(getSupportedEffectsNames()));
        pw.println("supportedPrimitives = " + Arrays.toString(getSupportedPrimitivesNames()));
        pw.println("supportedBraking = " + Arrays.toString(getSupportedBrakingNames()));
        pw.println("primitiveDelayMax = " + mPrimitiveDelayMax);
        pw.println("compositionSizeMax = " + mCompositionSizeMax);
        pw.println("pwlePrimitiveDurationMax = " + mPwlePrimitiveDurationMax);
        pw.println("pwleSizeMax = " + mPwleSizeMax);
        pw.println("q-factor = " + mQFactor);
        pw.println("frequencyProfile = " + mFrequencyProfile);
        pw.decreaseIndent();
    }

    /** Return the id of this vibrator. */
    public int getId() {
        return mId;
+9 −0
Original line number Diff line number Diff line
@@ -209,6 +209,15 @@ public final class PrebakedSegment extends VibrationEffectSegment {
                + "}";
    }

    /** @hide */
    @Override
    public String toDebugString() {
        return String.format("Prebaked=%s(%s, %s fallback)",
                VibrationEffect.effectIdToString(mEffectId),
                VibrationEffect.effectStrengthToString(mEffectStrength),
                mFallback ? "with" : "no");
    }

    @Override
    public int describeContents() {
        return 0;
Loading