From 344e47b4a4d2a195d045b159aff24bff07b31931 Mon Sep 17 00:00:00 2001 From: Christina Tao Date: Fri, 5 May 2023 20:46:54 +0000 Subject: [PATCH] [TTC] Override touch feedback haptic settings Test: Disabled "touch feedback" settings (slider all the way to 0). Performed TTC and verified that haptics still play despite "touch feedback" settings turned off Bug: 279050039 Change-Id: I626b25802f645ecaf66bda1f78719c7d791dc704 --- .../chipbar/ChipbarCoordinator.kt | 17 ++++- .../sender/MediaTttSenderCoordinatorTest.kt | 73 +++++++++++++++++-- .../chipbar/ChipbarCoordinatorTest.kt | 12 ++- 3 files changed, 91 insertions(+), 11 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinator.kt b/packages/SystemUI/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinator.kt index 4fbbc8915c196..ab6409b5f9b3f 100644 --- a/packages/SystemUI/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinator.kt +++ b/packages/SystemUI/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinator.kt @@ -21,6 +21,8 @@ import android.animation.ValueAnimator import android.content.Context import android.graphics.Rect import android.os.PowerManager +import android.os.Process +import android.os.VibrationAttributes import android.view.Gravity import android.view.MotionEvent import android.view.View @@ -226,7 +228,15 @@ constructor( maybeGetAccessibilityFocus(newInfo, currentView) // ---- Haptics ---- - newInfo.vibrationEffect?.let { vibratorHelper.vibrate(it) } + newInfo.vibrationEffect?.let { + vibratorHelper.vibrate( + Process.myUid(), + context.getApplicationContext().getPackageName(), + it, + newInfo.windowTitle, + VIBRATION_ATTRIBUTES, + ) + } } private fun maybeGetAccessibilityFocus(info: ChipbarInfo?, view: ViewGroup) { @@ -352,6 +362,11 @@ constructor( val loadingView: View, val animator: ObjectAnimator, ) + + companion object { + val VIBRATION_ATTRIBUTES: VibrationAttributes = + VibrationAttributes.createForUsage(VibrationAttributes.USAGE_HARDWARE_FEEDBACK) + } } @IdRes private val INFO_TAG = R.id.tag_chipbar_info diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinatorTest.kt index ca2b1da34766f..349fac0bf6ea9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinatorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinatorTest.kt @@ -22,6 +22,7 @@ import android.content.pm.PackageManager import android.graphics.drawable.Drawable import android.media.MediaRoute2Info import android.os.PowerManager +import android.os.VibrationAttributes import android.os.VibrationEffect import android.testing.AndroidTestingRunner import android.testing.TestableLooper @@ -210,7 +211,14 @@ class MediaTttSenderCoordinatorTest : SysuiTestCase() { assertThat(chipbarView.getErrorIcon().visibility).isEqualTo(View.GONE) assertThat(uiEventLoggerFake.eventId(0)) .isEqualTo(MediaTttSenderUiEvents.MEDIA_TTT_SENDER_ALMOST_CLOSE_TO_START_CAST.id) - verify(vibratorHelper).vibrate(any()) + verify(vibratorHelper) + .vibrate( + any(), + any(), + any(), + any(), + any(), + ) } @Test @@ -246,7 +254,14 @@ class MediaTttSenderCoordinatorTest : SysuiTestCase() { assertThat(chipbarView.getErrorIcon().visibility).isEqualTo(View.GONE) assertThat(uiEventLoggerFake.eventId(0)) .isEqualTo(MediaTttSenderUiEvents.MEDIA_TTT_SENDER_ALMOST_CLOSE_TO_END_CAST.id) - verify(vibratorHelper).vibrate(any()) + verify(vibratorHelper) + .vibrate( + any(), + any(), + any(), + any(), + any(), + ) } @Test @@ -267,7 +282,14 @@ class MediaTttSenderCoordinatorTest : SysuiTestCase() { assertThat(chipbarView.getErrorIcon().visibility).isEqualTo(View.GONE) assertThat(uiEventLoggerFake.eventId(0)) .isEqualTo(MediaTttSenderUiEvents.MEDIA_TTT_SENDER_TRANSFER_TO_RECEIVER_TRIGGERED.id) - verify(vibratorHelper).vibrate(any()) + verify(vibratorHelper) + .vibrate( + any(), + any(), + any(), + any(), + any(), + ) } @Test @@ -303,7 +325,14 @@ class MediaTttSenderCoordinatorTest : SysuiTestCase() { assertThat(chipbarView.getErrorIcon().visibility).isEqualTo(View.GONE) assertThat(uiEventLoggerFake.eventId(0)) .isEqualTo(MediaTttSenderUiEvents.MEDIA_TTT_SENDER_TRANSFER_TO_THIS_DEVICE_TRIGGERED.id) - verify(vibratorHelper).vibrate(any()) + verify(vibratorHelper) + .vibrate( + any(), + any(), + any(), + any(), + any(), + ) } @Test @@ -326,7 +355,14 @@ class MediaTttSenderCoordinatorTest : SysuiTestCase() { // Event index 1 since initially displaying the triggered chip would also log an event. assertThat(uiEventLoggerFake.eventId(1)) .isEqualTo(MediaTttSenderUiEvents.MEDIA_TTT_SENDER_TRANSFER_TO_RECEIVER_SUCCEEDED.id) - verify(vibratorHelper, never()).vibrate(any()) + verify(vibratorHelper, never()) + .vibrate( + any(), + any(), + any(), + any(), + any(), + ) } @Test @@ -403,7 +439,14 @@ class MediaTttSenderCoordinatorTest : SysuiTestCase() { // Event index 1 since initially displaying the triggered chip would also log an event. assertThat(uiEventLoggerFake.eventId(1)) .isEqualTo(MediaTttSenderUiEvents.MEDIA_TTT_SENDER_TRANSFER_TO_THIS_DEVICE_SUCCEEDED.id) - verify(vibratorHelper, never()).vibrate(any()) + verify(vibratorHelper, never()) + .vibrate( + any(), + any(), + any(), + any(), + any(), + ) } @Test @@ -483,7 +526,14 @@ class MediaTttSenderCoordinatorTest : SysuiTestCase() { // Event index 1 since initially displaying the triggered chip would also log an event. assertThat(uiEventLoggerFake.eventId(1)) .isEqualTo(MediaTttSenderUiEvents.MEDIA_TTT_SENDER_TRANSFER_TO_RECEIVER_FAILED.id) - verify(vibratorHelper).vibrate(any()) + verify(vibratorHelper) + .vibrate( + any(), + any(), + any(), + any(), + any(), + ) } @Test @@ -511,7 +561,14 @@ class MediaTttSenderCoordinatorTest : SysuiTestCase() { // Event index 1 since initially displaying the triggered chip would also log an event. assertThat(uiEventLoggerFake.eventId(1)) .isEqualTo(MediaTttSenderUiEvents.MEDIA_TTT_SENDER_TRANSFER_TO_THIS_DEVICE_FAILED.id) - verify(vibratorHelper).vibrate(any()) + verify(vibratorHelper) + .vibrate( + any(), + any(), + any(), + any(), + any(), + ) } @Test diff --git a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinatorTest.kt index 6e24941ac9374..d33271b9d88f9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinatorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinatorTest.kt @@ -17,6 +17,7 @@ package com.android.systemui.temporarydisplay.chipbar import android.os.PowerManager +import android.os.VibrationAttributes import android.os.VibrationEffect import android.testing.AndroidTestingRunner import android.testing.TestableLooper @@ -461,7 +462,7 @@ class ChipbarCoordinatorTest : SysuiTestCase() { } @Test - fun displayView_vibrationEffect_doubleClickEffect() { + fun displayView_vibrationEffect_doubleClickEffectWithHardwareFeedback() { underTest.displayView( createChipbarInfo( Icon.Resource(R.id.check_box, null), @@ -471,7 +472,14 @@ class ChipbarCoordinatorTest : SysuiTestCase() { ) ) - verify(vibratorHelper).vibrate(VibrationEffect.get(VibrationEffect.EFFECT_DOUBLE_CLICK)) + verify(vibratorHelper) + .vibrate( + any(), + any(), + eq(VibrationEffect.get(VibrationEffect.EFFECT_DOUBLE_CLICK)), + any(), + eq(VibrationAttributes.createForUsage(VibrationAttributes.USAGE_HARDWARE_FEEDBACK)), + ) } /** Regression test for b/266119467. */