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

Commit 5ac09e58 authored by Lucas Dupin's avatar Lucas Dupin Committed by Automerger Merge Worker
Browse files

Merge "Move VibratorHelper to a single threaded executor" into tm-qpr-dev am:...

Merge "Move VibratorHelper to a single threaded executor" into tm-qpr-dev am: 91d2c6f5 am: 92f82dc7

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



Change-Id: I2437e81da335d17374073298ec748d8f058e4a78
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 47d0b2b8 92f82dc7
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -24,17 +24,21 @@ import android.os.VibrationAttributes;
import android.os.VibrationEffect;
import android.os.Vibrator;

import androidx.annotation.VisibleForTesting;

import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Background;

import org.jetbrains.annotations.NotNull;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import javax.inject.Inject;

/**
 *
 * A Helper class that offloads {@link Vibrator} calls to a different thread.
 * {@link Vibrator} makes blocking calls that may cause SysUI to ANR.
 * TODO(b/245528624): Use regular Vibrator instance once new APIs are available.
 */
@SysUISingleton
public class VibratorHelper {
@@ -53,10 +57,18 @@ public class VibratorHelper {
    private final Executor mExecutor;

    /**
     *
     * Creates a vibrator helper on a new single threaded {@link Executor}.
     */
    @Inject
    public VibratorHelper(@Nullable Vibrator vibrator, @Background Executor executor) {
    public VibratorHelper(@Nullable Vibrator vibrator) {
        this(vibrator, Executors.newSingleThreadExecutor());
    }

    /**
     * Creates new vibrator helper on a specific {@link Executor}.
     */
    @VisibleForTesting
    public VibratorHelper(@Nullable Vibrator vibrator, Executor executor) {
        mExecutor = executor;
        mVibrator = vibrator;
    }