diff options
| author | Lais Andrade <lsandrade@google.com> | 2021-05-25 11:19:12 +0100 |
|---|---|---|
| committer | Lais Andrade <lsandrade@google.com> | 2021-06-02 12:26:35 +0100 |
| commit | c0c482736bfe698e262babdca99c79de888f0151 (patch) | |
| tree | 59f18450bb3a1b10589c6c6b78bc60c4fd4cabec /core/java/android/os/VibrationEffect.java | |
| parent | 0def72662fbca3c0181e19936cbec53b5b895eb4 (diff) | |
Remove non-zero amplitude validation for waveforms
The validation does not exist in Android R and is causing apps to start
crashing in S.
The validation for the static API createOneShot was maintained, as it
already existed in previous releases.
Fix: 184890231
Test: VibrationEffectTest
Change-Id: I606c943a35ddd68ccacab76f0047b9a276b5cf28
Diffstat (limited to 'core/java/android/os/VibrationEffect.java')
| -rw-r--r-- | core/java/android/os/VibrationEffect.java | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/core/java/android/os/VibrationEffect.java b/core/java/android/os/VibrationEffect.java index 781800dd49ce..a0cbbfe3327b 100644 --- a/core/java/android/os/VibrationEffect.java +++ b/core/java/android/os/VibrationEffect.java @@ -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=" |
