Merge "Fix NPE on VibratorInfo.getPrimitiveDuration" into sc-dev

This commit is contained in:
TreeHugger Robot
2021-04-27 18:12:51 +00:00
committed by Android (Google) Code Review
2 changed files with 3 additions and 1 deletions

View File

@@ -260,7 +260,7 @@ public class VibratorInfo implements Parcelable {
*/
public int getPrimitiveDuration(
@VibrationEffect.Composition.PrimitiveType int primitiveId) {
return mSupportedPrimitives.get(primitiveId);
return mSupportedPrimitives != null ? mSupportedPrimitives.get(primitiveId) : 0;
}
/**

View File

@@ -108,6 +108,8 @@ public class VibratorInfoTest {
.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