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

Commit 2607057d authored by Lais Andrade's avatar Lais Andrade
Browse files

Fix flaky VibratorManagerService test

Change test conditions to use the played effects on the fake
vibrator instead of asserting on the vibrator state

Fix: 185989305
Test: VibratorManagerServiceTest
Change-Id: I85da0e16d3adbef654735cd766556710cdf1edf7
parent 1eb043a9
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
@@ -468,28 +468,33 @@ public class VibratorManagerServiceTest {
    @Test
    public void vibrate_withRingtone_usesRingtoneSettings() throws Exception {
        mockVibrators(1);
        FakeVibratorControllerProvider fakeVibrator = mVibratorProviders.get(1);
        mVibrator.setDefaultRingVibrationIntensity(Vibrator.VIBRATION_INTENSITY_MEDIUM);
        mVibratorProviders.get(1).setCapabilities(IVibrator.CAP_AMPLITUDE_CONTROL);
        fakeVibrator.setCapabilities(IVibrator.CAP_AMPLITUDE_CONTROL);

        setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        setUserSetting(Settings.System.VIBRATE_WHEN_RINGING, 0);
        setGlobalSetting(Settings.Global.APPLY_RAMPING_RINGER, 0);
        VibratorManagerService service = createSystemReadyService();
        vibrate(service, VibrationEffect.createOneShot(40, 1), RINGTONE_ATTRS);
        vibrate(service, VibrationEffect.createOneShot(1, 1), RINGTONE_ATTRS);
        // Wait before checking it never played.
        assertFalse(waitUntil(s -> !fakeVibrator.getEffectSegments().isEmpty(),
                service, /* timeout= */ 50));

        setUserSetting(Settings.System.VIBRATE_WHEN_RINGING, 0);
        setGlobalSetting(Settings.Global.APPLY_RAMPING_RINGER, 1);
        service = createSystemReadyService();
        vibrate(service, VibrationEffect.createOneShot(40, 10), RINGTONE_ATTRS);
        assertTrue(waitUntil(s -> s.isVibrating(1), service, TEST_TIMEOUT_MILLIS));
        vibrate(service, VibrationEffect.createOneShot(1, 10), RINGTONE_ATTRS);
        assertTrue(waitUntil(s -> fakeVibrator.getEffectSegments().size() == 1,
                service, TEST_TIMEOUT_MILLIS));

        setUserSetting(Settings.System.VIBRATE_WHEN_RINGING, 1);
        setGlobalSetting(Settings.Global.APPLY_RAMPING_RINGER, 0);
        service = createSystemReadyService();
        vibrate(service, VibrationEffect.createOneShot(40, 100), RINGTONE_ATTRS);
        assertTrue(waitUntil(s -> s.isVibrating(1), service, TEST_TIMEOUT_MILLIS));
        vibrate(service, VibrationEffect.createOneShot(1, 100), RINGTONE_ATTRS);
        assertTrue(waitUntil(s -> fakeVibrator.getEffectSegments().size() == 2,
                service, TEST_TIMEOUT_MILLIS));

        assertEquals(2, mVibratorProviders.get(1).getEffectSegments().size());
        assertEquals(Arrays.asList(10 / 255f, 100 / 255f),
                mVibratorProviders.get(1).getAmplitudes());
    }