From ff5dc2b323ecc81af8bc585aac82059af7d8382a Mon Sep 17 00:00:00 2001 From: Ahmad Khalil Date: Wed, 26 Jul 2023 11:53:33 +0000 Subject: [PATCH] Fix test VibrationThreadTest#vibrate_singleVibratorRepeatingAlwaysOnWaveform_turnsVibratorBackOn We changed the test to check that after the vibrator was turned off midway through the first step on the second rotation. The vibrator is turned back on for a minimum of 5s (The fixed repeating-on duration in SetAmplitudeVibratorStep) + the remaining time of the step. Fix: 291713224 Test: atest com.android.server.vibrator.VibrationThreadTest Change-Id: I5e4f21ce6592265ed290f7eadf89f6295d9c7cc6 --- .../vibrator/SetAmplitudeVibratorStep.java | 2 +- .../server/vibrator/VibrationThreadTest.java | 21 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/services/core/java/com/android/server/vibrator/SetAmplitudeVibratorStep.java b/services/core/java/com/android/server/vibrator/SetAmplitudeVibratorStep.java index 6d01123f6ead4..e13ec6c2d4ceb 100644 --- a/services/core/java/com/android/server/vibrator/SetAmplitudeVibratorStep.java +++ b/services/core/java/com/android/server/vibrator/SetAmplitudeVibratorStep.java @@ -37,7 +37,7 @@ final class SetAmplitudeVibratorStep extends AbstractVibratorStep { * The repeating waveform keeps the vibrator ON all the time. Use a minimum duration to * prevent short patterns from turning the vibrator ON too frequently. */ - private static final int REPEATING_EFFECT_ON_DURATION = 5000; // 5s + static final int REPEATING_EFFECT_ON_DURATION = 5000; // 5s SetAmplitudeVibratorStep(VibrationStepConductor conductor, long startTime, VibratorController controller, VibrationEffect.Composed effect, int index, diff --git a/services/tests/vibrator/src/com/android/server/vibrator/VibrationThreadTest.java b/services/tests/vibrator/src/com/android/server/vibrator/VibrationThreadTest.java index 74d996c4bfdae..709e9c3a2cb18 100644 --- a/services/tests/vibrator/src/com/android/server/vibrator/VibrationThreadTest.java +++ b/services/tests/vibrator/src/com/android/server/vibrator/VibrationThreadTest.java @@ -69,7 +69,6 @@ import com.android.server.LocalServices; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.mockito.InOrder; @@ -451,21 +450,21 @@ public class VibrationThreadTest { fakeVibrator.getEffectSegments(vibrationId)); } - @Ignore("b/290940400") @LargeTest @Test public void vibrate_singleVibratorRepeatingAlwaysOnWaveform_turnsVibratorBackOn() throws Exception { FakeVibratorControllerProvider fakeVibrator = mVibratorProviders.get(VIBRATOR_ID); fakeVibrator.setCapabilities(IVibrator.CAP_AMPLITUDE_CONTROL); + int expectedOnDuration = SetAmplitudeVibratorStep.REPEATING_EFFECT_ON_DURATION; - int[] amplitudes = new int[]{1, 2}; VibrationEffect effect = VibrationEffect.createWaveform( - new long[]{4900, 50}, amplitudes, 0); + /* timings= */ new long[]{expectedOnDuration - 100, 50}, + /* amplitudes= */ new int[]{1, 2}, /* repeat= */ 0); long vibrationId = startThreadAndDispatcher(effect); assertTrue(waitUntil(() -> fakeVibrator.getEffectSegments(vibrationId).size() > 1, - 5000 + TEST_TIMEOUT_MILLIS)); + expectedOnDuration + TEST_TIMEOUT_MILLIS)); mVibrationConductor.notifyCancelled( new Vibration.EndInfo(Vibration.Status.CANCELLED_BY_USER), /* immediate= */ false); @@ -473,12 +472,12 @@ public class VibrationThreadTest { verifyCallbacksTriggered(vibrationId, Vibration.Status.CANCELLED_BY_USER); assertFalse(mControllers.get(VIBRATOR_ID).isVibrating()); - // First time turn vibrator ON for minimum of 5s. - assertEquals(5000L, fakeVibrator.getEffectSegments(vibrationId).get(0).getDuration()); - // Vibrator turns off in the middle of the second execution of first step, turn it back ON - // for another 5s + remaining of 850ms. - assertEquals(4900 + 50 + 4900, - fakeVibrator.getEffectSegments(vibrationId).get(1).getDuration(), /* delta= */ 20); + List effectSegments = fakeVibrator.getEffectSegments(vibrationId); + // First time, turn vibrator ON for the expected fixed duration. + assertEquals(expectedOnDuration, effectSegments.get(0).getDuration()); + // Vibrator turns off in the middle of the second execution of the first step. Expect it to + // be turned back ON at least for the fixed duration + the remaining duration of the step. + assertTrue(expectedOnDuration < effectSegments.get(1).getDuration()); // Set amplitudes for a cycle {1, 2}, start second loop then turn it back on to same value. assertEquals(expectedAmplitudes(1, 2, 1, 1), mVibratorProviders.get(VIBRATOR_ID).getAmplitudes().subList(0, 4));