Loading core/java/android/os/vibrator/PrimitiveSegment.java +1 −1 Original line number Diff line number Diff line Loading @@ -108,7 +108,7 @@ public final class PrimitiveSegment extends VibrationEffectSegment { Preconditions.checkArgumentInRange(mPrimitiveId, VibrationEffect.Composition.PRIMITIVE_NOOP, VibrationEffect.Composition.PRIMITIVE_LOW_TICK, "primitiveId"); Preconditions.checkArgumentInRange(mScale, 0f, 1f, "scale"); Preconditions.checkArgumentNonnegative(mDelay, "primitive delay should be >= 0"); VibrationEffectSegment.checkDurationArgument(mDelay, "delay"); } @Override Loading core/java/android/os/vibrator/RampSegment.java +3 −8 Original line number Diff line number Diff line Loading @@ -108,14 +108,9 @@ public final class RampSegment extends VibrationEffectSegment { /** @hide */ @Override public void validate() { Preconditions.checkArgumentNonNegative(mStartFrequencyHz, "Frequencies must all be >= 0, got start frequency of " + mStartFrequencyHz); Preconditions.checkArgumentFinite(mStartFrequencyHz, "startFrequencyHz"); Preconditions.checkArgumentNonNegative(mEndFrequencyHz, "Frequencies must all be >= 0, got end frequency of " + mEndFrequencyHz); Preconditions.checkArgumentFinite(mEndFrequencyHz, "endFrequencyHz"); Preconditions.checkArgumentNonnegative(mDuration, "Durations must all be >= 0, got " + mDuration); VibrationEffectSegment.checkFrequencyArgument(mStartFrequencyHz, "startFrequencyHz"); VibrationEffectSegment.checkFrequencyArgument(mEndFrequencyHz, "endFrequencyHz"); VibrationEffectSegment.checkDurationArgument(mDuration, "duration"); Preconditions.checkArgumentInRange(mStartAmplitude, 0f, 1f, "startAmplitude"); Preconditions.checkArgumentInRange(mEndAmplitude, 0f, 1f, "endAmplitude"); } Loading core/java/android/os/vibrator/StepSegment.java +2 −5 Original line number Diff line number Diff line Loading @@ -95,11 +95,8 @@ public final class StepSegment extends VibrationEffectSegment { /** @hide */ @Override public void validate() { Preconditions.checkArgumentNonNegative(mFrequencyHz, "Frequencies must all be >= 0, got " + mFrequencyHz); Preconditions.checkArgumentFinite(mFrequencyHz, "frequencyHz"); Preconditions.checkArgumentNonnegative(mDuration, "Durations must all be >= 0, got " + mDuration); VibrationEffectSegment.checkFrequencyArgument(mFrequencyHz, "frequencyHz"); VibrationEffectSegment.checkDurationArgument(mDuration, "duration"); if (Float.compare(mAmplitude, VibrationEffect.DEFAULT_AMPLITUDE) != 0) { Preconditions.checkArgumentInRange(mAmplitude, 0f, 1f, "amplitude"); } Loading core/java/android/os/vibrator/VibrationEffectSegment.java +37 −0 Original line number Diff line number Diff line Loading @@ -112,6 +112,43 @@ public abstract class VibrationEffectSegment implements Parcelable { @NonNull public abstract <T extends VibrationEffectSegment> T applyEffectStrength(int effectStrength); /** * Checks the given frequency argument is valid to represent a vibration effect frequency in * hertz, i.e. a finite non-negative value. * * @param value the frequency argument value to be checked * @param name the argument name for the error message. * * @hide */ public static void checkFrequencyArgument(float value, @NonNull String name) { // Similar to combining Preconditions checkArgumentFinite + checkArgumentNonnegative, // but this implementation doesn't create the error message unless a check fail. if (Float.isNaN(value)) { throw new IllegalArgumentException(name + " must not be NaN"); } if (Float.isInfinite(value)) { throw new IllegalArgumentException(name + " must not be infinite"); } if (value < 0) { throw new IllegalArgumentException(name + " must be >= 0, got " + value); } } /** * Checks the given duration argument is valid, i.e. a non-negative value. * * @param value the duration value to be checked * @param name the argument name for the error message. * * @hide */ public static void checkDurationArgument(long value, @NonNull String name) { if (value < 0) { throw new IllegalArgumentException(name + " must be >= 0, got " + value); } } @NonNull public static final Creator<VibrationEffectSegment> CREATOR = new Creator<VibrationEffectSegment>() { Loading Loading
core/java/android/os/vibrator/PrimitiveSegment.java +1 −1 Original line number Diff line number Diff line Loading @@ -108,7 +108,7 @@ public final class PrimitiveSegment extends VibrationEffectSegment { Preconditions.checkArgumentInRange(mPrimitiveId, VibrationEffect.Composition.PRIMITIVE_NOOP, VibrationEffect.Composition.PRIMITIVE_LOW_TICK, "primitiveId"); Preconditions.checkArgumentInRange(mScale, 0f, 1f, "scale"); Preconditions.checkArgumentNonnegative(mDelay, "primitive delay should be >= 0"); VibrationEffectSegment.checkDurationArgument(mDelay, "delay"); } @Override Loading
core/java/android/os/vibrator/RampSegment.java +3 −8 Original line number Diff line number Diff line Loading @@ -108,14 +108,9 @@ public final class RampSegment extends VibrationEffectSegment { /** @hide */ @Override public void validate() { Preconditions.checkArgumentNonNegative(mStartFrequencyHz, "Frequencies must all be >= 0, got start frequency of " + mStartFrequencyHz); Preconditions.checkArgumentFinite(mStartFrequencyHz, "startFrequencyHz"); Preconditions.checkArgumentNonNegative(mEndFrequencyHz, "Frequencies must all be >= 0, got end frequency of " + mEndFrequencyHz); Preconditions.checkArgumentFinite(mEndFrequencyHz, "endFrequencyHz"); Preconditions.checkArgumentNonnegative(mDuration, "Durations must all be >= 0, got " + mDuration); VibrationEffectSegment.checkFrequencyArgument(mStartFrequencyHz, "startFrequencyHz"); VibrationEffectSegment.checkFrequencyArgument(mEndFrequencyHz, "endFrequencyHz"); VibrationEffectSegment.checkDurationArgument(mDuration, "duration"); Preconditions.checkArgumentInRange(mStartAmplitude, 0f, 1f, "startAmplitude"); Preconditions.checkArgumentInRange(mEndAmplitude, 0f, 1f, "endAmplitude"); } Loading
core/java/android/os/vibrator/StepSegment.java +2 −5 Original line number Diff line number Diff line Loading @@ -95,11 +95,8 @@ public final class StepSegment extends VibrationEffectSegment { /** @hide */ @Override public void validate() { Preconditions.checkArgumentNonNegative(mFrequencyHz, "Frequencies must all be >= 0, got " + mFrequencyHz); Preconditions.checkArgumentFinite(mFrequencyHz, "frequencyHz"); Preconditions.checkArgumentNonnegative(mDuration, "Durations must all be >= 0, got " + mDuration); VibrationEffectSegment.checkFrequencyArgument(mFrequencyHz, "frequencyHz"); VibrationEffectSegment.checkDurationArgument(mDuration, "duration"); if (Float.compare(mAmplitude, VibrationEffect.DEFAULT_AMPLITUDE) != 0) { Preconditions.checkArgumentInRange(mAmplitude, 0f, 1f, "amplitude"); } Loading
core/java/android/os/vibrator/VibrationEffectSegment.java +37 −0 Original line number Diff line number Diff line Loading @@ -112,6 +112,43 @@ public abstract class VibrationEffectSegment implements Parcelable { @NonNull public abstract <T extends VibrationEffectSegment> T applyEffectStrength(int effectStrength); /** * Checks the given frequency argument is valid to represent a vibration effect frequency in * hertz, i.e. a finite non-negative value. * * @param value the frequency argument value to be checked * @param name the argument name for the error message. * * @hide */ public static void checkFrequencyArgument(float value, @NonNull String name) { // Similar to combining Preconditions checkArgumentFinite + checkArgumentNonnegative, // but this implementation doesn't create the error message unless a check fail. if (Float.isNaN(value)) { throw new IllegalArgumentException(name + " must not be NaN"); } if (Float.isInfinite(value)) { throw new IllegalArgumentException(name + " must not be infinite"); } if (value < 0) { throw new IllegalArgumentException(name + " must be >= 0, got " + value); } } /** * Checks the given duration argument is valid, i.e. a non-negative value. * * @param value the duration value to be checked * @param name the argument name for the error message. * * @hide */ public static void checkDurationArgument(long value, @NonNull String name) { if (value < 0) { throw new IllegalArgumentException(name + " must be >= 0, got " + value); } } @NonNull public static final Creator<VibrationEffectSegment> CREATOR = new Creator<VibrationEffectSegment>() { Loading