Default vibration amplitude resolution added
Test: On sailfish, set vibration intensity to High, lock the phone and
unlock with FPS. Vibration should be played.
Bug: 76129874
Change-Id: I546341e55fa0e6de0af1d22c8e8e07d67670f0b9
Merged-In: I546341e55fa0e6de0af1d22c8e8e07d67670f0b9
diff --git a/core/java/android/os/VibrationEffect.java b/core/java/android/os/VibrationEffect.java
index 3a2e485..62359ec 100644
--- a/core/java/android/os/VibrationEffect.java
+++ b/core/java/android/os/VibrationEffect.java
@@ -359,6 +359,26 @@
return new OneShot(mDuration, newAmplitude);
}
+ /**
+ * Resolve default values into integer amplitude numbers.
+ *
+ * @param defaultAmplitude the default amplitude to apply, must be between 0 and
+ * MAX_AMPLITUDE
+ * @return A {@link OneShot} effect with same physical meaning but explicitly set amplitude
+ *
+ * @hide
+ */
+ public OneShot resolve(int defaultAmplitude) {
+ if (defaultAmplitude > MAX_AMPLITUDE || defaultAmplitude < 0) {
+ throw new IllegalArgumentException(
+ "Amplitude is negative or greater than MAX_AMPLITUDE");
+ }
+ if (mAmplitude == DEFAULT_AMPLITUDE) {
+ return new OneShot(mDuration, defaultAmplitude);
+ }
+ return this;
+ }
+
@Override
public void validate() {
if (mAmplitude < -1 || mAmplitude == 0 || mAmplitude > 255) {
@@ -487,6 +507,30 @@
return new Waveform(mTimings, scaledAmplitudes, mRepeat);
}
+ /**
+ * Resolve default values into integer amplitude numbers.
+ *
+ * @param defaultAmplitude the default amplitude to apply, must be between 0 and
+ * MAX_AMPLITUDE
+ * @return A {@link Waveform} effect with same physical meaning but explicitly set
+ * amplitude
+ *
+ * @hide
+ */
+ public Waveform resolve(int defaultAmplitude) {
+ if (defaultAmplitude > MAX_AMPLITUDE || defaultAmplitude < 0) {
+ throw new IllegalArgumentException(
+ "Amplitude is negative or greater than MAX_AMPLITUDE");
+ }
+ int[] resolvedAmplitudes = Arrays.copyOf(mAmplitudes, mAmplitudes.length);
+ for (int i = 0; i < resolvedAmplitudes.length; i++) {
+ if (resolvedAmplitudes[i] == DEFAULT_AMPLITUDE) {
+ resolvedAmplitudes[i] = defaultAmplitude;
+ }
+ }
+ return new Waveform(mTimings, resolvedAmplitudes, mRepeat);
+ }
+
@Override
public void validate() {
if (mTimings.length != mAmplitudes.length) {