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

Commit 5f6bbb57 authored by Lais Andrade's avatar Lais Andrade
Browse files

Turn vibrator off explicitly on waveforms when amplitude is zero

This makes sure the drive will be off for the period of time described in the waveform pattern with amplitude = 0.

Bug: 172492945
Test: atest FrameworksServicesTests:VibratorServiceTest
Change-Id: I753e4846fce3066b78e818afa5c794b113244ab0
parent 4b7c4adc
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1684,6 +1684,10 @@ public class VibratorService extends IVibratorService.Stub
                                    // Vibrator is already ON, so just change its amplitude.
                                    doVibratorSetAmplitude(amplitude);
                                }
                            } else {
                                // Previous vibration should have already finished, but we make sure
                                // the vibrator will be off for the next step when amplitude is 0.
                                doVibratorOff();
                            }

                            // We wait until the time this waveform step was supposed to end,
+8 −4
Original line number Diff line number Diff line
@@ -512,8 +512,7 @@ public class VibratorServiceTest {

        InOrder inOrderVerifier = inOrder(mNativeWrapperMock);
        inOrderVerifier.verify(mNativeWrapperMock).vibratorOff();
        inOrderVerifier.verify(mNativeWrapperMock).vibratorOn(eq(100L),
                gt(0L));
        inOrderVerifier.verify(mNativeWrapperMock).vibratorOn(eq(100L), gt(0L));
        inOrderVerifier.verify(mNativeWrapperMock).vibratorOff();
    }

@@ -540,9 +539,13 @@ public class VibratorServiceTest {
    }

    @Test
    public void vibrate_withWaveformAndNativeCallback_callbackCannotBeTriggeredByNative()
    public void vibrate_withWaveformAndNativeCallback_callbackIgnoredAndWaveformPlaysCompletely()
            throws Exception {
        VibratorService service = createService();
        doAnswer(invocation -> {
            service.onVibrationComplete(invocation.getArgument(1));
            return null;
        }).when(mNativeWrapperMock).vibratorOn(anyLong(), anyLong());
        Mockito.clearInvocations(mNativeWrapperMock);

        VibrationEffect effect = VibrationEffect.createWaveform(new long[]{1, 3, 1, 2}, -1);
@@ -551,8 +554,9 @@ public class VibratorServiceTest {
        // Wait for VibrateThread to finish: 1ms OFF, 3ms ON, 1ms OFF, 2ms ON.
        Thread.sleep(15);
        InOrder inOrderVerifier = inOrder(mNativeWrapperMock);
        inOrderVerifier.verify(mNativeWrapperMock).vibratorOff();
        inOrderVerifier.verify(mNativeWrapperMock, times(2)).vibratorOff();
        inOrderVerifier.verify(mNativeWrapperMock).vibratorOn(eq(3L), anyLong());
        inOrderVerifier.verify(mNativeWrapperMock).vibratorOff();
        inOrderVerifier.verify(mNativeWrapperMock).vibratorOn(eq(2L), anyLong());
        inOrderVerifier.verify(mNativeWrapperMock).vibratorOff();
    }