Merge "Give ongoing ringtone vibrations priority over new incoming vibrations." into tm-dev am: 42f9419307

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17567809

Change-Id: I4ccb0dec4463cb195e7c1896c4314622b80b14fb
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Simon Bowden
2022-04-06 17:24:16 +00:00
committed by Automerger Merge Worker
3 changed files with 39 additions and 0 deletions

View File

@@ -66,6 +66,7 @@ final class Vibration {
IGNORED_FOR_ONGOING,
IGNORED_FOR_POWER,
IGNORED_FOR_RINGER_MODE,
IGNORED_FOR_RINGTONE,
IGNORED_FOR_SETTINGS,
IGNORED_SUPERSEDED,
}

View File

@@ -733,6 +733,12 @@ public class VibratorManagerService extends IVibratorManagerService.Stub {
+ attrs);
}
break;
case IGNORED_FOR_RINGTONE:
if (DEBUG) {
Slog.d(TAG, "Ignoring incoming vibration in favor of ringtone vibration");
}
break;
default:
if (DEBUG) {
Slog.d(TAG, "Vibration for uid=" + uid + " and with attrs=" + attrs
@@ -809,6 +815,10 @@ public class VibratorManagerService extends IVibratorManagerService.Stub {
return Vibration.Status.IGNORED_FOR_ALARM;
}
if (currentVibration.attrs.getUsage() == VibrationAttributes.USAGE_RINGTONE) {
return Vibration.Status.IGNORED_FOR_RINGTONE;
}
if (currentVibration.isRepeating()) {
return Vibration.Status.IGNORED_FOR_ONGOING;
}

View File

@@ -602,10 +602,15 @@ public class VibratorManagerServiceTest {
VibrationEffect.EFFECT_HEAVY_CLICK, VibrationEffect.EFFECT_DOUBLE_CLICK);
VibratorManagerService service = createSystemReadyService();
mRegisteredPowerModeListener.onLowPowerModeChanged(LOW_POWER_STATE);
// The haptic feedback should be ignored in low power, but not the ringtone. The end
// of the test asserts which actual effects ended up playing.
vibrate(service, VibrationEffect.get(VibrationEffect.EFFECT_TICK), HAPTIC_FEEDBACK_ATTRS);
vibrate(service, VibrationEffect.get(VibrationEffect.EFFECT_CLICK), RINGTONE_ATTRS);
assertTrue(waitUntil(s -> fakeVibrator.getAllEffectSegments().size() == 1,
service, TEST_TIMEOUT_MILLIS));
// Allow the ringtone to complete, as the other vibrations won't cancel it.
assertTrue(waitUntil(s -> !s.isVibrating(1), service, TEST_TIMEOUT_MILLIS));
mRegisteredPowerModeListener.onLowPowerModeChanged(NORMAL_POWER_STATE);
vibrate(service, VibrationEffect.get(VibrationEffect.EFFECT_HEAVY_CLICK),
@@ -814,6 +819,29 @@ public class VibratorManagerServiceTest {
service, /* timeout= */ 50));
}
@Test
public void vibrate_withOngoingRingtoneVibration_ignoresEffect() throws Exception {
mockVibrators(1);
mVibratorProviders.get(1).setCapabilities(IVibrator.CAP_AMPLITUDE_CONTROL);
VibratorManagerService service = createSystemReadyService();
VibrationEffect alarmEffect = VibrationEffect.createWaveform(
new long[]{10_000, 10_000}, new int[]{128, 255}, -1);
vibrate(service, alarmEffect, new VibrationAttributes.Builder().setUsage(
VibrationAttributes.USAGE_RINGTONE).build());
// VibrationThread will start this vibration async, so wait before checking it started.
assertTrue(waitUntil(s -> !mVibratorProviders.get(1).getAllEffectSegments().isEmpty(),
service, TEST_TIMEOUT_MILLIS));
vibrate(service, VibrationEffect.get(VibrationEffect.EFFECT_CLICK),
HAPTIC_FEEDBACK_ATTRS);
// Wait before checking it never played a second effect.
assertFalse(waitUntil(s -> mVibratorProviders.get(1).getAllEffectSegments().size() > 1,
service, /* timeout= */ 50));
}
@Test
public void vibrate_withInputDevices_vibratesInputDevices() throws Exception {
mockVibrators(1);