Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 33238f21 authored by Michael Wright's avatar Michael Wright Committed by Android (Google) Code Review
Browse files

Merge "Ignore non-repeating vibrations in favor of repeating vibrations." into oc-mr1-dev

parents ad545464 58c4631c
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
@@ -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();