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

Commit fbd7063f authored by Lais Andrade's avatar Lais Andrade
Browse files

Add adaptive scale to vibration stats metrics

Introduce new field to vibration stats with adaptive scale value applied
to the vibration, only if the value is set to the VibratorControlService.

Report adaptive scale values from vibration effects and audio-coupled
haptics.

Bug: 342013027
Test: atest com.android.server.vibrator
Flag: Unable to flag proto auto generated method changes
Change-Id: I9b10ff24b21d68ac6d7b6629cda370c6d4371bc6
parent 4e21ef74
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -133,6 +133,7 @@ final class HalVibration extends Vibration {
        // Save scale values for debugging purposes.
        mScaleLevel = scaler.getScaleLevel(vibrationUsage);
        mAdaptiveScale = scaler.getAdaptiveHapticsScale(vibrationUsage);
        stats.reportAdaptiveScale(mAdaptiveScale);

        // Scale all VibrationEffect instances in given CombinedVibration.
        CombinedVibration newEffect = mEffectToPlay.transform(scaler::scale, vibrationUsage);
+15 −1
Original line number Diff line number Diff line
@@ -61,6 +61,10 @@ final class VibrationStats {
    private int mEndedByUsage;
    private int mInterruptedUsage;

    // Vibration parameters.
    // Set by VibrationThread only (single-threaded).
    private float mAdaptiveScale;

    // All following counters are set by VibrationThread only (single-threaded):
    // Counts how many times the VibrationEffect was repeated.
    private int mRepeatCount;
@@ -188,6 +192,14 @@ final class VibrationStats {
        }
    }

    /** Report the adaptive scale that was applied to this vibration. */
    void reportAdaptiveScale(float scale) {
        // Only report adaptive scale if it was set for this vibration.
        if (Float.compare(scale, VibrationScaler.ADAPTIVE_SCALE_NONE) != 0) {
            mAdaptiveScale = scale;
        }
    }

    /** Report the vibration has looped a few more times. */
    void reportRepetition(int loops) {
        mRepeatCount += loops;
@@ -287,6 +299,7 @@ final class VibrationStats {
        public final int vibrationType;
        public final int usage;
        public final int status;
        public final float adaptiveScale;
        public final boolean endedBySameUid;
        public final int endedByUsage;
        public final int interruptedUsage;
@@ -316,6 +329,7 @@ final class VibrationStats {
            this.vibrationType = vibrationType;
            this.usage = usage;
            this.status = status.getProtoEnumValue();
            this.adaptiveScale = stats.mAdaptiveScale;
            endedBySameUid = (uid == stats.mEndedByUid);
            endedByUsage = stats.mEndedByUsage;
            interruptedUsage = stats.mInterruptedUsage;
@@ -376,7 +390,7 @@ final class VibrationStats {
                    halOnCount, halOffCount, halPerformCount, halSetAmplitudeCount,
                    halSetExternalControlCount, halSupportedCompositionPrimitivesUsed,
                    halSupportedEffectsUsed, halUnsupportedCompositionPrimitivesUsed,
                    halUnsupportedEffectsUsed, halCompositionSize, halPwleSize);
                    halUnsupportedEffectsUsed, halCompositionSize, halPwleSize, adaptiveScale);
        }

        private static int[] filteredKeys(SparseBooleanArray supportArray, boolean supported) {
+7 −3
Original line number Diff line number Diff line
@@ -1628,6 +1628,12 @@ public class VibratorManagerService extends IVibratorManagerService.Stub {
            mStatus = Vibration.Status.RUNNING;
        }

        public void scale(VibrationScaler scaler, int usage) {
            scale.scaleLevel = scaler.getScaleLevel(usage);
            scale.adaptiveHapticsScale = scaler.getAdaptiveHapticsScale(usage);
            stats.reportAdaptiveScale(scale.adaptiveHapticsScale);
        }

        public void mute() {
            externalVibration.mute();
        }
@@ -2042,9 +2048,7 @@ public class VibratorManagerService extends IVibratorManagerService.Stub {
                }
                mCurrentExternalVibration = vibHolder;
                vibHolder.linkToDeath();
                vibHolder.scale.scaleLevel = mVibrationScaler.getScaleLevel(attrs.getUsage());
                vibHolder.scale.adaptiveHapticsScale =
                        mVibrationScaler.getAdaptiveHapticsScale(attrs.getUsage());
                vibHolder.scale(mVibrationScaler, attrs.getUsage());
            }

            if (waitForCompletion) {