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

Commit efe72e9d authored by Lais Andrade's avatar Lais Andrade Committed by Android (Google) Code Review
Browse files

Merge "Fix regression on VibratorService update settings callback"

parents 1257711e a03eafca
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -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");
+56 −0
Original line number Diff line number Diff line
@@ -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);