summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorSimon Bowden <sbowden@google.com>2022-01-27 19:23:01 +0000
committerSimon Bowden <sbowden@google.com>2022-02-01 12:23:29 +0000
commit5b14477dc96997d89da047b30c86c60fdf7d7b95 (patch)
tree558369841df80851cb56bf9adfca0ac6e5121c15 /core/java
parenta1919f78058cbcd8e393d8eba5c7c8cd286dec22 (diff)
Directly implement areAllEffectsSupported and areAllPrimitivesSupported
rather than creating and throwing away an extra array to pass into the non-All version. Test: presubmit Change-Id: I8539e16272a591a193d846b490b02f72e95aba6a
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/os/Vibrator.java25
1 files changed, 15 insertions, 10 deletions
diff --git a/core/java/android/os/Vibrator.java b/core/java/android/os/Vibrator.java
index 8f5086021530..78f1cb12ded6 100644
--- a/core/java/android/os/Vibrator.java
+++ b/core/java/android/os/Vibrator.java
@@ -546,18 +546,22 @@ public abstract class Vibrator {
@VibrationEffectSupport
public final int areAllEffectsSupported(
@NonNull @VibrationEffect.EffectType int... effectIds) {
- int support = VIBRATION_EFFECT_SUPPORT_YES;
- for (int supported : areEffectsSupported(effectIds)) {
- if (supported == VIBRATION_EFFECT_SUPPORT_NO) {
- return VIBRATION_EFFECT_SUPPORT_NO;
- } else if (supported == VIBRATION_EFFECT_SUPPORT_UNKNOWN) {
- support = VIBRATION_EFFECT_SUPPORT_UNKNOWN;
+ VibratorInfo info = getInfo();
+ int allSupported = VIBRATION_EFFECT_SUPPORT_YES;
+ for (int effectId : effectIds) {
+ switch (info.isEffectSupported(effectId)) {
+ case VIBRATION_EFFECT_SUPPORT_NO:
+ return VIBRATION_EFFECT_SUPPORT_NO;
+ case VIBRATION_EFFECT_SUPPORT_YES:
+ continue;
+ default: // VIBRATION_EFFECT_SUPPORT_UNKNOWN
+ allSupported = VIBRATION_EFFECT_SUPPORT_UNKNOWN;
+ break;
}
}
- return support;
+ return allSupported;
}
-
/**
* Query whether the vibrator supports the given primitives.
*
@@ -598,8 +602,9 @@ public abstract class Vibrator {
*/
public final boolean areAllPrimitivesSupported(
@NonNull @VibrationEffect.Composition.PrimitiveType int... primitiveIds) {
- for (boolean supported : arePrimitivesSupported(primitiveIds)) {
- if (!supported) {
+ VibratorInfo info = getInfo();
+ for (int primitiveId : primitiveIds) {
+ if (!info.isPrimitiveSupported(primitiveId)) {
return false;
}
}