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

Commit 17cab654 authored by Alexey Kuzmin's avatar Alexey Kuzmin
Browse files

Fallback added for HEAVY_CLICK effect

Test: Do any UI gesture causing HEAVY_CLICK (for example, long press
home button). HEAVY_CLICK should be played, and adb logcat should not
show message "Failed to play prebaked effect, no fallback"
Bug: 74882420
Fixes: 74776434

Change-Id: I151e0b02842c29fe67802d77411ae0f7d0f63c39
parent e81b500d
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.util.DebugUtils;
import android.util.Slog;
import android.util.SparseArray;
import android.view.InputDevice;
import android.media.AudioAttributes;

@@ -91,7 +92,7 @@ public class VibratorService extends IVibratorService.Stub
    private final boolean mAllowPriorityVibrationsInLowPowerMode;
    private final boolean mSupportsAmplitudeControl;
    private final int mDefaultVibrationAmplitude;
    private final VibrationEffect[] mFallbackEffects;
    private final SparseArray<VibrationEffect> mFallbackEffects;
    private final WorkSource mTmpWorkSource = new WorkSource();
    private final Handler mH = new Handler();
    private final Object mLock = new Object();
@@ -177,6 +178,7 @@ public class VibratorService extends IVibratorService.Stub
                switch (prebaked.getId()) {
                    case VibrationEffect.EFFECT_CLICK:
                    case VibrationEffect.EFFECT_DOUBLE_CLICK:
                    case VibrationEffect.EFFECT_HEAVY_CLICK:
                    case VibrationEffect.EFFECT_TICK:
                        return true;
                    default:
@@ -293,7 +295,11 @@ public class VibratorService extends IVibratorService.Stub
                com.android.internal.R.array.config_clockTickVibePattern);
        VibrationEffect tickEffect = createEffect(tickEffectTimings);

        mFallbackEffects = new VibrationEffect[] { clickEffect, doubleClickEffect, tickEffect };
        mFallbackEffects = new SparseArray<VibrationEffect>();
        mFallbackEffects.put(VibrationEffect.EFFECT_CLICK, clickEffect);
        mFallbackEffects.put(VibrationEffect.EFFECT_DOUBLE_CLICK, doubleClickEffect);
        mFallbackEffects.put(VibrationEffect.EFFECT_TICK, tickEffect);
        mFallbackEffects.put(VibrationEffect.EFFECT_HEAVY_CLICK, clickEffect);
    }

    private static VibrationEffect createEffect(long[] timings) {
@@ -960,10 +966,7 @@ public class VibratorService extends IVibratorService.Stub
    }

    private VibrationEffect getFallbackEffect(int effectId) {
        if (effectId < 0 || effectId >= mFallbackEffects.length) {
            return null;
        }
        return mFallbackEffects[effectId];
        return mFallbackEffects.get(effectId);
    }

    /**