Loading services/core/java/com/android/server/VibratorService.java +4 −0 Original line number Diff line number Diff line Loading @@ -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, Loading services/tests/servicestests/src/com/android/server/VibratorServiceTest.java +8 −4 Original line number Diff line number Diff line Loading @@ -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(); } Loading @@ -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); Loading @@ -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(); } Loading Loading
services/core/java/com/android/server/VibratorService.java +4 −0 Original line number Diff line number Diff line Loading @@ -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, Loading
services/tests/servicestests/src/com/android/server/VibratorServiceTest.java +8 −4 Original line number Diff line number Diff line Loading @@ -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(); } Loading @@ -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); Loading @@ -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(); } Loading