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

Commit 2a9d5d3c authored by Lais Andrade's avatar Lais Andrade
Browse files

Fix VibrationThread handling old HAL callbacks

The VibrationThread does not differentiate between HAL callbacks from
different IVibrator calls, causing older callbacks to affect the
vibration playback. This can be seen when the VibrationThread or
Vibrator HAL are slower to schedule the steps / callbacks execution,
breaking the execution of pattern waveforms that depends on strict
timings.

This fix adds an extra id to the vibrate calls, which will be sent back
by the HAL callback once complete. The VibrationThread can use this to
control which callbacks should be ignored during the vibration playback.

A regression test was introduced where a latency is set to the fake HAL
implementation to check the vibration is executed as expected. This test
replicates the flaky failure caught by a separate test.

Fix: 395005081
Test: VibrationThreadTest
Flag: android.os.vibrator.fix_vibration_thread_callback_handling
Change-Id: I1d2bc2d15698e71127e87c164d9b147135cff1a1
parent 703ee5ae
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -145,3 +145,13 @@ flag {
        purpose: PURPOSE_FEATURE
    }
}

flag {
    namespace: "haptics"
    name: "fix_vibration_thread_callback_handling"
    description: "Fix how the VibrationThread handles late callbacks from the vibrator HAL"
    bug: "395005081"
    metadata {
      purpose: PURPOSE_BUGFIX
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -124,6 +124,8 @@ abstract class AbstractVibratorStep extends Step {
            Slog.d(VibrationThread.TAG,
                    "Turning off vibrator " + getVibratorId());
        }
        // Make sure we ignore any pending callback from old vibration commands.
        conductor.nextVibratorCallbackStepId(getVibratorId());
        controller.off();
        getVibration().stats.reportVibratorOff();
        mPendingVibratorOffDeadline = 0;
+2 −1
Original line number Diff line number Diff line
@@ -73,7 +73,8 @@ final class ComposePrimitivesVibratorStep extends AbstractComposedVibratorStep {

            PrimitiveSegment[] primitivesArray =
                    primitives.toArray(new PrimitiveSegment[primitives.size()]);
            long vibratorOnResult = controller.on(primitivesArray, getVibration().id);
            int stepId = conductor.nextVibratorCallbackStepId(getVibratorId());
            long vibratorOnResult = controller.on(primitivesArray, getVibration().id, stepId);
            handleVibratorOnResult(vibratorOnResult);
            getVibration().stats.reportComposePrimitives(vibratorOnResult, primitivesArray);

+2 −1
Original line number Diff line number Diff line
@@ -72,7 +72,8 @@ final class ComposePwleV2VibratorStep extends AbstractComposedVibratorStep {
                        + controller.getVibratorInfo().getId());
            }
            PwlePoint[] pwlesArray = pwles.toArray(new PwlePoint[pwles.size()]);
            long vibratorOnResult = controller.on(pwlesArray, getVibration().id);
            int stepId = conductor.nextVibratorCallbackStepId(getVibratorId());
            long vibratorOnResult = controller.on(pwlesArray, getVibration().id, stepId);
            handleVibratorOnResult(vibratorOnResult);
            getVibration().stats.reportComposePwle(vibratorOnResult, pwlesArray);

+2 −1
Original line number Diff line number Diff line
@@ -71,7 +71,8 @@ final class ComposePwleVibratorStep extends AbstractComposedVibratorStep {
                        + controller.getVibratorInfo().getId());
            }
            RampSegment[] pwlesArray = pwles.toArray(new RampSegment[pwles.size()]);
            long vibratorOnResult = controller.on(pwlesArray, getVibration().id);
            int stepId = conductor.nextVibratorCallbackStepId(getVibratorId());
            long vibratorOnResult = controller.on(pwlesArray, getVibration().id, stepId);
            handleVibratorOnResult(vibratorOnResult);
            getVibration().stats.reportComposePwle(vibratorOnResult, pwlesArray);

Loading