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

Commit 085266a2 authored by Lais Andrade's avatar Lais Andrade Committed by Automerger Merge Worker
Browse files

Remove non-zero amplitude validation for waveforms am: c0c48273 am: 95c86568 am: 3164090c

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14703097

Change-Id: If8807f323e110dc604bab07657d29b7e173dec41
parents 3a3262b1 3164090c
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -182,6 +182,11 @@ public abstract class VibrationEffect implements Parcelable {
     * @return The desired effect.
     */
    public static VibrationEffect createOneShot(long milliseconds, int amplitude) {
        if (amplitude == 0) {
            throw new IllegalArgumentException(
                    "amplitude must either be DEFAULT_AMPLITUDE, "
                            + "or between 1 and 255 inclusive (amplitude=" + amplitude + ")");
        }
        return createWaveform(new long[]{milliseconds}, new int[]{amplitude}, -1 /* repeat */);
    }

@@ -581,22 +586,16 @@ public abstract class VibrationEffect implements Parcelable {
        public void validate() {
            int segmentCount = mSegments.size();
            boolean hasNonZeroDuration = false;
            boolean hasNonZeroAmplitude = false;
            for (int i = 0; i < segmentCount; i++) {
                VibrationEffectSegment segment = mSegments.get(i);
                segment.validate();
                // A segment with unknown duration = -1 still counts as a non-zero duration.
                hasNonZeroDuration |= segment.getDuration() != 0;
                hasNonZeroAmplitude |= segment.hasNonZeroAmplitude();
            }
            if (!hasNonZeroDuration) {
                throw new IllegalArgumentException("at least one timing must be non-zero"
                        + " (segments=" + mSegments + ")");
            }
            if (!hasNonZeroAmplitude) {
                throw new IllegalArgumentException("at least one amplitude must be non-zero"
                        + " (segments=" + mSegments + ")");
            }
            if (mRepeatIndex != -1) {
                Preconditions.checkArgumentInRange(mRepeatIndex, 0, segmentCount - 1,
                        "repeat index must be within the bounds of the segments (segments.length="
+4 −1
Original line number Diff line number Diff line
@@ -102,7 +102,9 @@ public class VibrationEffectTest {
        assertThrows(IllegalArgumentException.class,
                () -> VibrationEffect.createOneShot(1, -2).validate());
        assertThrows(IllegalArgumentException.class,
                () -> VibrationEffect.createOneShot(1, 256).validate());
                () -> VibrationEffect.createOneShot(1, 0).validate());
        assertThrows(IllegalArgumentException.class,
                () -> VibrationEffect.createOneShot(-1, 255).validate());
    }

    @Test
@@ -117,6 +119,7 @@ public class VibrationEffectTest {
    @Test
    public void testValidateWaveform() {
        VibrationEffect.createWaveform(TEST_TIMINGS, TEST_AMPLITUDES, -1).validate();
        VibrationEffect.createWaveform(new long[]{10, 10}, new int[] {0, 0}, -1).validate();
        VibrationEffect.createWaveform(TEST_TIMINGS, TEST_AMPLITUDES, 0).validate();
        VibrationEffect.startWaveform()
                .addStep(/* amplitude= */ 1, /* duration= */ 10)