diff options
| author | 2017-10-05 14:04:14 -0400 | |
|---|---|---|
| committer | 2017-10-09 15:19:47 +0000 | |
| commit | 58c4631c29b4f36737f261d1a2888e66592eda32 (patch) | |
| tree | f9352af6061e912269d8da3b86a3ec55ae72b755 | |
| parent | 942aaf5ae89b21795fef76ea54b156bc8b646b9f (diff) | |
Ignore non-repeating vibrations in favor of repeating vibrations.
This way we don't inadvertently cancel things like alarms and ring
tone vibrations in favor of one shot vibrations, which are typically
shorter and meant to be feedback rather than attention getting.
Test: start alarm, hit home button, see alarm vibration isn't cancelled.
Bug: 65621937
Change-Id: Ib7fcaea7bc7f101d738b72112c8d5096c4b34ca2
| -rw-r--r-- | services/core/java/com/android/server/VibratorService.java | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/VibratorService.java b/services/core/java/com/android/server/VibratorService.java index 046eb761d1c0..8b79b9ddfef2 100644 --- a/services/core/java/com/android/server/VibratorService.java +++ b/services/core/java/com/android/server/VibratorService.java @@ -373,12 +373,24 @@ public class VibratorService extends IVibratorService.Stub if (mCurrentVibration.hasLongerTimeout(newOneShot.getTiming()) && newOneShot.getAmplitude() == currentOneShot.getAmplitude()) { if (DEBUG) { - Slog.e(TAG, "Ignoring incoming vibration in favor of current vibration"); + Slog.d(TAG, "Ignoring incoming vibration in favor of current vibration"); } return; } } + // If the current vibration is repeating and the incoming one is non-repeating, then ignore + // the non-repeating vibration. This is so that we don't cancel vibrations that are meant + // to grab the attention of the user, like ringtones and alarms, in favor of one-shot + // vibrations that are likely quite short. + if (!isRepeatingVibration(effect) + && mCurrentVibration != null && isRepeatingVibration(mCurrentVibration.mEffect)) { + if (DEBUG) { + Slog.d(TAG, "Ignoring incoming vibration in favor of alarm vibration"); + } + return; + } + Vibration vib = new Vibration(token, effect, usageHint, uid, opPkg); // Only link against waveforms since they potentially don't have a finish if @@ -404,6 +416,16 @@ public class VibratorService extends IVibratorService.Stub } } + private static boolean isRepeatingVibration(VibrationEffect effect) { + if (effect instanceof VibrationEffect.Waveform) { + final VibrationEffect.Waveform waveform = (VibrationEffect.Waveform) effect; + if (waveform.getRepeatIndex() >= 0) { + return true; + } + } + return false; + } + private void addToPreviousVibrationsLocked(Vibration vib) { if (mPreviousVibrations.size() > mPreviousVibrationsLimit) { mPreviousVibrations.removeFirst(); |