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

Commit 4b43ec32 authored by Juan Sebastian Martinez's avatar Juan Sebastian Martinez Committed by Automerger Merge Worker
Browse files

Merge "Extension to VibratorHelper to use the new oneway haptics API" into...

Merge "Extension to VibratorHelper to use the new oneway haptics API" into udc-qpr-dev am: 865d7d3a

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



Change-Id: I13274f7987d9b0672505644aa6954dd3ad8baad5
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents f7480310 865d7d3a
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.os.Process;
import android.os.VibrationAttributes;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.view.View;

import androidx.annotation.VisibleForTesting;

@@ -151,4 +152,20 @@ public class VibratorHelper {
                BIOMETRIC_ERROR_VIBRATION_EFFECT, reason,
                HARDWARE_FEEDBACK_VIBRATION_ATTRIBUTES);
    }

    /**
     * Perform a vibration using a view and the one-way API with flags
     * @see View#performHapticFeedback(int feedbackConstant, int flags)
     */
    public void performHapticFeedback(@NonNull View view, int feedbackConstant, int flags) {
        view.performHapticFeedback(feedbackConstant, flags);
    }

    /**
     * Perform a vibration using a view and the one-way API
     * @see View#performHapticFeedback(int feedbackConstant)
     */
    public void performHapticFeedback(@NonNull View view, int feedbackConstant) {
        view.performHapticFeedback(feedbackConstant);
    }
}
+18 −0
Original line number Diff line number Diff line
@@ -6,6 +6,8 @@ import android.os.VibrationAttributes
import android.os.VibrationEffect
import android.os.Vibrator
import android.testing.AndroidTestingRunner
import android.view.HapticFeedbackConstants
import android.view.View
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.util.mockito.eq
@@ -33,6 +35,7 @@ class VibratorHelperTest : SysuiTestCase() {

    @Mock lateinit var vibrator: Vibrator
    @Mock lateinit var executor: Executor
    @Mock lateinit var view: View
    @Captor lateinit var backgroundTaskCaptor: ArgumentCaptor<Runnable>
    lateinit var vibratorHelper: VibratorHelper

@@ -71,6 +74,21 @@ class VibratorHelperTest : SysuiTestCase() {
        verifyAsync().vibrate(any(VibrationEffect::class.java))
    }

    @Test
    fun testPerformHapticFeedback() {
        val constant = HapticFeedbackConstants.CONFIRM
        vibratorHelper.performHapticFeedback(view, constant)
        verify(view).performHapticFeedback(eq(constant))
    }

    @Test
    fun testPerformHapticFeedback_withFlags() {
        val constant = HapticFeedbackConstants.CONFIRM
        val flag = HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING
        vibratorHelper.performHapticFeedback(view, constant, flag)
        verify(view).performHapticFeedback(eq(constant), eq(flag))
    }

    @Test
    fun testHasVibrator() {
        assertThat(vibratorHelper.hasVibrator()).isTrue()