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
This commit is contained in:
Lais Andrade
2020-11-18 14:34:19 +00:00
parent 4b7c4adc31
commit 5f6bbb5726
2 changed files with 12 additions and 4 deletions

View File

@@ -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,

View File

@@ -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();
}