Loading services/core/java/com/android/server/VibratorService.java +12 −4 Original line number Diff line number Diff line Loading @@ -679,15 +679,23 @@ public class VibratorService extends IVibratorService.Stub { } } private void updateVibrators() { @VisibleForTesting void updateVibrators() { synchronized (mLock) { mInputDeviceDelegate.updateInputDeviceVibrators( boolean inputDevicesChanged = mInputDeviceDelegate.updateInputDeviceVibrators( mVibrationSettings.shouldVibrateInputDevices()); if (mCurrentVibration == null) { return; } if (inputDevicesChanged || !mVibrationSettings.shouldVibrateForPowerMode( mCurrentVibration.attrs.getUsage())) { // If the state changes out from under us then just reset. doCancelVibrateLocked(Vibration.Status.CANCELLED); } } } private void doVibratorOff() { Trace.traceBegin(Trace.TRACE_TAG_VIBRATOR, "doVibratorOff"); Loading services/tests/servicestests/src/com/android/server/VibratorServiceTest.java +56 −0 Original line number Diff line number Diff line Loading @@ -403,6 +403,62 @@ public class VibratorServiceTest { assertTrue(mVibratorProvider.getEffects().isEmpty()); } @Test public void vibrate_enteringLowPowerMode_cancelVibration() throws Exception { VibratorService service = createService(); mRegisteredPowerModeListener.onLowPowerModeChanged(NORMAL_POWER_STATE); vibrate(service, VibrationEffect.createOneShot(1000, 100), HAPTIC_FEEDBACK_ATTRS); // VibrationThread will start this vibration async, so wait before triggering callbacks. Thread.sleep(10); assertTrue(service.isVibrating()); mRegisteredPowerModeListener.onLowPowerModeChanged(LOW_POWER_STATE); // Wait for callback to cancel vibration. Thread.sleep(10); assertFalse(service.isVibrating()); } @Test public void vibrate_enteringLowPowerModeAndRingtone_doNotCancelVibration() throws Exception { VibratorService service = createService(); mRegisteredPowerModeListener.onLowPowerModeChanged(NORMAL_POWER_STATE); vibrate(service, VibrationEffect.createOneShot(1000, 100), RINGTONE_ATTRS); // VibrationThread will start this vibration async, so wait before triggering callbacks. Thread.sleep(10); assertTrue(service.isVibrating()); mRegisteredPowerModeListener.onLowPowerModeChanged(LOW_POWER_STATE); // Wait for callback to cancel vibration. Thread.sleep(10); assertTrue(service.isVibrating()); } @Test public void vibrate_withSettingsChanged_doNotCancelVibration() throws Exception { VibratorService service = createService(); vibrate(service, VibrationEffect.createOneShot(1000, 100), HAPTIC_FEEDBACK_ATTRS); // VibrationThread will start this vibration async, so wait before triggering callbacks. Thread.sleep(10); assertTrue(service.isVibrating()); setUserSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_MEDIUM); // FakeSettingsProvider don't support testing triggering ContentObserver yet. service.updateVibrators(); // Wait for callback to cancel vibration. Thread.sleep(10); assertTrue(service.isVibrating()); } @Test public void vibrate_withComposed_performsEffect() throws Exception { mVibratorProvider.setCapabilities(IVibrator.CAP_COMPOSE_EFFECTS); Loading Loading
services/core/java/com/android/server/VibratorService.java +12 −4 Original line number Diff line number Diff line Loading @@ -679,15 +679,23 @@ public class VibratorService extends IVibratorService.Stub { } } private void updateVibrators() { @VisibleForTesting void updateVibrators() { synchronized (mLock) { mInputDeviceDelegate.updateInputDeviceVibrators( boolean inputDevicesChanged = mInputDeviceDelegate.updateInputDeviceVibrators( mVibrationSettings.shouldVibrateInputDevices()); if (mCurrentVibration == null) { return; } if (inputDevicesChanged || !mVibrationSettings.shouldVibrateForPowerMode( mCurrentVibration.attrs.getUsage())) { // If the state changes out from under us then just reset. doCancelVibrateLocked(Vibration.Status.CANCELLED); } } } private void doVibratorOff() { Trace.traceBegin(Trace.TRACE_TAG_VIBRATOR, "doVibratorOff"); Loading
services/tests/servicestests/src/com/android/server/VibratorServiceTest.java +56 −0 Original line number Diff line number Diff line Loading @@ -403,6 +403,62 @@ public class VibratorServiceTest { assertTrue(mVibratorProvider.getEffects().isEmpty()); } @Test public void vibrate_enteringLowPowerMode_cancelVibration() throws Exception { VibratorService service = createService(); mRegisteredPowerModeListener.onLowPowerModeChanged(NORMAL_POWER_STATE); vibrate(service, VibrationEffect.createOneShot(1000, 100), HAPTIC_FEEDBACK_ATTRS); // VibrationThread will start this vibration async, so wait before triggering callbacks. Thread.sleep(10); assertTrue(service.isVibrating()); mRegisteredPowerModeListener.onLowPowerModeChanged(LOW_POWER_STATE); // Wait for callback to cancel vibration. Thread.sleep(10); assertFalse(service.isVibrating()); } @Test public void vibrate_enteringLowPowerModeAndRingtone_doNotCancelVibration() throws Exception { VibratorService service = createService(); mRegisteredPowerModeListener.onLowPowerModeChanged(NORMAL_POWER_STATE); vibrate(service, VibrationEffect.createOneShot(1000, 100), RINGTONE_ATTRS); // VibrationThread will start this vibration async, so wait before triggering callbacks. Thread.sleep(10); assertTrue(service.isVibrating()); mRegisteredPowerModeListener.onLowPowerModeChanged(LOW_POWER_STATE); // Wait for callback to cancel vibration. Thread.sleep(10); assertTrue(service.isVibrating()); } @Test public void vibrate_withSettingsChanged_doNotCancelVibration() throws Exception { VibratorService service = createService(); vibrate(service, VibrationEffect.createOneShot(1000, 100), HAPTIC_FEEDBACK_ATTRS); // VibrationThread will start this vibration async, so wait before triggering callbacks. Thread.sleep(10); assertTrue(service.isVibrating()); setUserSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_MEDIUM); // FakeSettingsProvider don't support testing triggering ContentObserver yet. service.updateVibrators(); // Wait for callback to cancel vibration. Thread.sleep(10); assertTrue(service.isVibrating()); } @Test public void vibrate_withComposed_performsEffect() throws Exception { mVibratorProvider.setCapabilities(IVibrator.CAP_COMPOSE_EFFECTS); Loading