summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2021-06-17 20:12:14 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2021-06-17 20:12:14 +0000
commitc100aeabbc8c83e2ba7b0a2b7a989f0b414a65ac (patch)
tree8a9270973828b84980be125b0b649d5cf0182dcb
parent6b1067a79f438e7cc62accbc19524682d1d507ba (diff)
parentba57b002d3b465aafeda2704bd342262c82f0a27 (diff)
Merge "Fix usage filter over UNKNOWN vibration" into sc-dev
-rw-r--r--core/java/android/os/SystemVibratorManager.java2
-rw-r--r--core/java/android/os/VibrationAttributes.java5
-rw-r--r--services/core/java/com/android/server/vibrator/VibratorManagerService.java8
-rw-r--r--services/tests/servicestests/src/com/android/server/vibrator/VibratorManagerServiceTest.java39
4 files changed, 49 insertions, 5 deletions
diff --git a/core/java/android/os/SystemVibratorManager.java b/core/java/android/os/SystemVibratorManager.java
index c33603d26ded..04165564ce1e 100644
--- a/core/java/android/os/SystemVibratorManager.java
+++ b/core/java/android/os/SystemVibratorManager.java
@@ -146,7 +146,7 @@ public class SystemVibratorManager extends VibratorManager {
@Override
public void cancel() {
- cancelVibration(/* usageFilter= */ -1);
+ cancelVibration(VibrationAttributes.USAGE_FILTER_MATCH_ALL);
}
@Override
diff --git a/core/java/android/os/VibrationAttributes.java b/core/java/android/os/VibrationAttributes.java
index cec323f8b423..43ea2e7810bc 100644
--- a/core/java/android/os/VibrationAttributes.java
+++ b/core/java/android/os/VibrationAttributes.java
@@ -63,6 +63,11 @@ public final class VibrationAttributes implements Parcelable {
public @interface Usage{}
/**
+ * Vibration usage filter value to match all usages.
+ * @hide
+ */
+ public static final int USAGE_FILTER_MATCH_ALL = -1;
+ /**
* Vibration usage class value to use when the vibration usage class is unknown.
*/
public static final int USAGE_CLASS_UNKNOWN = 0x0;
diff --git a/services/core/java/com/android/server/vibrator/VibratorManagerService.java b/services/core/java/com/android/server/vibrator/VibratorManagerService.java
index 2f0ed19d867a..79706ead555c 100644
--- a/services/core/java/com/android/server/vibrator/VibratorManagerService.java
+++ b/services/core/java/com/android/server/vibrator/VibratorManagerService.java
@@ -723,6 +723,12 @@ public class VibratorManagerService extends IVibratorManagerService.Stub {
* VibrationAttributes.USAGE_* values.
*/
private boolean shouldCancelVibration(VibrationAttributes attrs, int usageFilter) {
+ if (attrs.getUsage() == VibrationAttributes.USAGE_UNKNOWN) {
+ // Special case, usage UNKNOWN would match all filters. Instead it should only match if
+ // it's cancelling that usage specifically, or if cancelling all usages.
+ return usageFilter == VibrationAttributes.USAGE_UNKNOWN
+ || usageFilter == VibrationAttributes.USAGE_FILTER_MATCH_ALL;
+ }
return (usageFilter & attrs.getUsage()) == attrs.getUsage();
}
@@ -1535,7 +1541,7 @@ public class VibratorManagerService extends IVibratorManagerService.Stub {
}
private int runCancel() {
- cancelVibrate(/* usageFilter= */ -1, mToken);
+ cancelVibrate(VibrationAttributes.USAGE_FILTER_MATCH_ALL, mToken);
return 0;
}
diff --git a/services/tests/servicestests/src/com/android/server/vibrator/VibratorManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/vibrator/VibratorManagerServiceTest.java
index ea2dc0a8a345..9117ae696e9f 100644
--- a/services/tests/servicestests/src/com/android/server/vibrator/VibratorManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/vibrator/VibratorManagerServiceTest.java
@@ -234,7 +234,7 @@ public class VibratorManagerServiceTest {
CombinedVibration effect = CombinedVibration.createParallel(
VibrationEffect.createPredefined(VibrationEffect.EFFECT_CLICK));
vibrate(service, effect, HAPTIC_FEEDBACK_ATTRS);
- service.cancelVibrate(/* usageFilter= */ -1, service);
+ service.cancelVibrate(VibrationAttributes.USAGE_FILTER_MATCH_ALL, service);
assertTrue(service.setAlwaysOnEffect(UID, PACKAGE_NAME, 1, effect, ALARM_ATTRS));
@@ -889,13 +889,13 @@ public class VibratorManagerServiceTest {
mockVibrators(1);
VibratorManagerService service = createSystemReadyService();
- service.cancelVibrate(/* usageFilter= */ -1, service);
+ service.cancelVibrate(VibrationAttributes.USAGE_FILTER_MATCH_ALL, service);
assertFalse(service.isVibrating(1));
vibrate(service, VibrationEffect.createOneShot(10 * TEST_TIMEOUT_MILLIS, 100), ALARM_ATTRS);
assertTrue(waitUntil(s -> s.isVibrating(1), service, TEST_TIMEOUT_MILLIS));
- service.cancelVibrate(/* usageFilter= */ -1, service);
+ service.cancelVibrate(VibrationAttributes.USAGE_FILTER_MATCH_ALL, service);
assertTrue(waitUntil(s -> !s.isVibrating(1), service, TEST_TIMEOUT_MILLIS));
}
@@ -924,6 +924,39 @@ public class VibratorManagerServiceTest {
assertTrue(waitUntil(s -> !s.isVibrating(1), service, TEST_TIMEOUT_MILLIS));
}
+ @Test
+ public void cancelVibrate_withoutUnknownUsage_onlyStopsIfFilteringUnknownOrAllUsages()
+ throws Exception {
+ mockVibrators(1);
+ VibrationAttributes attrs = new VibrationAttributes.Builder()
+ .setUsage(VibrationAttributes.USAGE_UNKNOWN)
+ .build();
+ VibratorManagerService service = createSystemReadyService();
+
+ vibrate(service, VibrationEffect.createOneShot(10 * TEST_TIMEOUT_MILLIS, 100), attrs);
+ assertTrue(waitUntil(s -> s.isVibrating(1), service, TEST_TIMEOUT_MILLIS));
+
+ // Do not cancel UNKNOWN vibration when filter is being applied for other usages.
+ service.cancelVibrate(VibrationAttributes.USAGE_RINGTONE, service);
+ assertFalse(waitUntil(s -> !s.isVibrating(1), service, /* timeout= */ 50));
+
+ service.cancelVibrate(
+ VibrationAttributes.USAGE_CLASS_ALARM | ~VibrationAttributes.USAGE_CLASS_MASK,
+ service);
+ assertFalse(waitUntil(s -> !s.isVibrating(1), service, /* timeout= */ 50));
+
+ // Cancel UNKNOWN vibration when filtered for that vibration specifically.
+ service.cancelVibrate(VibrationAttributes.USAGE_UNKNOWN, service);
+ assertTrue(waitUntil(s -> !s.isVibrating(1), service, TEST_TIMEOUT_MILLIS));
+
+ vibrate(service, VibrationEffect.createOneShot(10 * TEST_TIMEOUT_MILLIS, 100), attrs);
+ assertTrue(waitUntil(s -> s.isVibrating(1), service, TEST_TIMEOUT_MILLIS));
+
+ // Cancel UNKNOWN vibration when all vibrations are being cancelled.
+ service.cancelVibrate(VibrationAttributes.USAGE_FILTER_MATCH_ALL, service);
+ assertTrue(waitUntil(s -> !s.isVibrating(1), service, TEST_TIMEOUT_MILLIS));
+ }
+
private void mockCapabilities(long... capabilities) {
when(mNativeWrapperMock.getCapabilities()).thenReturn(
Arrays.stream(capabilities).reduce(0, (a, b) -> a | b));