Merge "Fix NPE on VibratorInfo.getPrimitiveDuration" into sc-dev
diff --git a/core/java/android/os/VibratorInfo.java b/core/java/android/os/VibratorInfo.java
index d73469c..597df08 100644
--- a/core/java/android/os/VibratorInfo.java
+++ b/core/java/android/os/VibratorInfo.java
@@ -260,7 +260,7 @@
*/
public int getPrimitiveDuration(
@VibrationEffect.Composition.PrimitiveType int primitiveId) {
- return mSupportedPrimitives.get(primitiveId);
+ return mSupportedPrimitives != null ? mSupportedPrimitives.get(primitiveId) : 0;
}
/**
diff --git a/core/tests/coretests/src/android/os/VibratorInfoTest.java b/core/tests/coretests/src/android/os/VibratorInfoTest.java
index 9880f8c..8c7d10c 100644
--- a/core/tests/coretests/src/android/os/VibratorInfoTest.java
+++ b/core/tests/coretests/src/android/os/VibratorInfoTest.java
@@ -108,6 +108,8 @@
.build();
assertEquals(20, info.getPrimitiveDuration(VibrationEffect.Composition.PRIMITIVE_CLICK));
assertEquals(0, info.getPrimitiveDuration(VibrationEffect.Composition.PRIMITIVE_TICK));
+ assertEquals(0, new VibratorInfo.Builder(TEST_VIBRATOR_ID).build()
+ .getPrimitiveDuration(VibrationEffect.Composition.PRIMITIVE_TICK));
}
@Test