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

Commit b5e7def5 authored by Juan Sebastian Martinez's avatar Juan Sebastian Martinez
Browse files

Non-flaky slider haptics test

Removing the need of the animator test rule to replicate the desired
conditions. Additionally, the constants asserted are now integer types.

Test: atest SystemUITests:VolumeDialogImplTest
Flag: ACONFIG haptic_volume_slider TRUNKFOOD
Bug: 329282567

Change-Id: Ifa41920a133c74b4cd6d867ff7ab7786f570c3b1
parent 440df4b7
Loading
Loading
Loading
Loading
+24 −10
Original line number Diff line number Diff line
@@ -173,9 +173,9 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
    private static final String TYPE_DISMISS = "dismiss";
    /** Volume dialog slider animation. */
    private static final String TYPE_UPDATE = "update";
    static final short PROGRESS_HAPTICS_DISABLED = 0;
    static final short PROGRESS_HAPTICS_EAGER = 1;
    static final short PROGRESS_HAPTICS_ANIMATED = 2;
    static final int PROGRESS_HAPTICS_DISABLED = 0;
    static final int PROGRESS_HAPTICS_EAGER = 1;
    static final int PROGRESS_HAPTICS_ANIMATED = 2;

    /**
     *  TODO(b/290612381): remove lingering animations or tolerate them
@@ -851,10 +851,7 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
            row.header.setFilters(new InputFilter[] {new InputFilter.LengthFilter(13)});
        }
        row.slider = row.view.findViewById(R.id.volume_row_slider);
        if (hapticVolumeSlider()) {
            row.createPlugin(mVibratorHelper, mSystemClock);
            HapticSliderViewBinder.bind(row.slider, row.mHapticPlugin);
        }
        addSliderHapticsToRow(row);
        row.slider.setOnSeekBarChangeListener(new VolumeSeekBarChangeListener(row));
        row.number = row.view.findViewById(R.id.volume_number);

@@ -915,6 +912,23 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
        }
    }

    private void addSliderHapticsToRow(VolumeRow row) {
        if (hapticVolumeSlider()) {
            row.createPlugin(mVibratorHelper, mSystemClock);
            HapticSliderViewBinder.bind(row.slider, row.mHapticPlugin);
        }
    }

    @VisibleForTesting void addSliderHapticsToRows() {
        for (VolumeRow row: mRows) {
            addSliderHapticsToRow(row);
        }
    }

    @VisibleForTesting void removeDismissMessages() {
        mHandler.removeMessages(H.DISMISS);
    }

    private void setRingerMode(int newRingerMode) {
        Events.writeEvent(Events.EVENT_RINGER_TOGGLE, newRingerMode);
        incrementManualToggleCount();
@@ -2105,7 +2119,7 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
        }
    }

    @VisibleForTesting short progressHapticsForStream(int stream) {
    @VisibleForTesting int progressHapticsForStream(int stream) {
        for (VolumeRow row: mRows) {
            if (row.stream == stream) {
                return row.mProgressHapticsType;
@@ -2619,7 +2633,7 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
        private int animTargetProgress;
        private int lastAudibleLevel = 1;
        private SeekableSliderHapticPlugin mHapticPlugin;
        private short mProgressHapticsType = PROGRESS_HAPTICS_DISABLED;
        private int mProgressHapticsType = PROGRESS_HAPTICS_DISABLED;

        void setIcon(int iconRes, Resources.Theme theme) {
            if (icon != null) {
@@ -2661,7 +2675,7 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
            slider.setOnTouchListener(null);
        }

        void deliverOnProgressChangedHaptics(boolean fromUser, int progress, short hapticsType) {
        void deliverOnProgressChangedHaptics(boolean fromUser, int progress, int hapticsType) {
            if (mHapticPlugin == null) return;

            mHapticPlugin.onProgressChanged(slider, progress, fromUser);
+14 −12
Original line number Diff line number Diff line
@@ -95,7 +95,6 @@ import junit.framework.Assert;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -272,50 +271,53 @@ public class VolumeDialogImplTest extends SysuiTestCase {
    @Test
    @DisableFlags(FLAG_HAPTIC_VOLUME_SLIDER)
    public void testVolumeChange_noSliderHaptics_doesNotDeliverOnProgressChangedHaptics() {
        // Initialize the dialog again with haptic sliders disabled
        mDialog.init(0, null);
        final State shellState = createShellState();
        VolumeDialogController.StreamState musicStreamState =
                shellState.states.get(AudioSystem.STREAM_MUSIC);

        mDialog.show(SHOW_REASON_UNKNOWN);
        mTestableLooper.processMessages(1); //Only the SHOW message
        mDialog.removeDismissMessages(); // Temporarily remove the rescheduled DISMISS

        // Change the volume two times
        musicStreamState.level += 10;
        mDialog.onStateChangedH(shellState);
        mAnimatorTestRule.advanceTimeBy(10);
        musicStreamState.level += 10;
        mDialog.onStateChangedH(shellState);

        // expected: the type of the progress haptics for the stream should be DISABLED
        short type = mDialog.progressHapticsForStream(AudioSystem.STREAM_MUSIC);
        // expected: the type of the latest progress haptics for the stream should be DISABLED
        int type = mDialog.progressHapticsForStream(AudioSystem.STREAM_MUSIC);
        assertEquals(VolumeDialogImpl.PROGRESS_HAPTICS_DISABLED, type);

        mDialog.dismiss(DISMISS_REASON_UNKNOWN); // Dismiss
        mTestableLooper.processAllMessages();
    }

    @Ignore("Causing breakages so ignoring to resolve, b/329099861")
    @Test
    @EnableFlags(FLAG_HAPTIC_VOLUME_SLIDER)
    public void testVolumeChange_withSliderHaptics_deliversOnProgressChangedHapticsEagerly() {
       // Initialize the dialog again to create haptic plugins on the rows with the flag enabled
        mDialog.init(0, null);
        // create haptic plugins on the rows with the flag enabled
        mDialog.addSliderHapticsToRows();
        final State shellState = createShellState();
        VolumeDialogController.StreamState musicStreamState =
                shellState.states.get(AudioSystem.STREAM_MUSIC);

        mDialog.show(SHOW_REASON_UNKNOWN);
        mTestableLooper.processMessages(1); //Only the SHOW message
        mDialog.removeDismissMessages(); // Temporarily remove the rescheduled DISMISS

        // Change the volume two times
        musicStreamState.level += 10;
        mDialog.onStateChangedH(shellState);
        mAnimatorTestRule.advanceTimeBy(10);
        musicStreamState.level += 10;
        mDialog.onStateChangedH(shellState);

        // expected: the type of the progress haptics for the stream should be EAGER
        short type = mDialog.progressHapticsForStream(AudioSystem.STREAM_MUSIC);
        // expected: the type of the latest progress haptics for the stream should be EAGER
        int type = mDialog.progressHapticsForStream(AudioSystem.STREAM_MUSIC);
        assertEquals(VolumeDialogImpl.PROGRESS_HAPTICS_EAGER, type);

        mDialog.dismiss(DISMISS_REASON_UNKNOWN); // Dismiss
        mTestableLooper.processAllMessages();
    }

    @Test