[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
This commit is contained in:
Christina Tao
2023-05-05 20:46:54 +00:00
committed by christinatao
parent 6593d03bc6
commit 344e47b4a4
3 changed files with 91 additions and 11 deletions

View File

@@ -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

View File

@@ -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<VibrationEffect>())
verify(vibratorHelper)
.vibrate(
any(),
any(),
any<VibrationEffect>(),
any(),
any<VibrationAttributes>(),
)
}
@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<VibrationEffect>())
verify(vibratorHelper)
.vibrate(
any(),
any(),
any<VibrationEffect>(),
any(),
any<VibrationAttributes>(),
)
}
@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<VibrationEffect>())
verify(vibratorHelper)
.vibrate(
any(),
any(),
any<VibrationEffect>(),
any(),
any<VibrationAttributes>(),
)
}
@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<VibrationEffect>())
verify(vibratorHelper)
.vibrate(
any(),
any(),
any<VibrationEffect>(),
any(),
any<VibrationAttributes>(),
)
}
@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<VibrationEffect>())
verify(vibratorHelper, never())
.vibrate(
any(),
any(),
any<VibrationEffect>(),
any(),
any<VibrationAttributes>(),
)
}
@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<VibrationEffect>())
verify(vibratorHelper, never())
.vibrate(
any(),
any(),
any<VibrationEffect>(),
any(),
any<VibrationAttributes>(),
)
}
@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<VibrationEffect>())
verify(vibratorHelper)
.vibrate(
any(),
any(),
any<VibrationEffect>(),
any(),
any<VibrationAttributes>(),
)
}
@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<VibrationEffect>())
verify(vibratorHelper)
.vibrate(
any(),
any(),
any<VibrationEffect>(),
any(),
any<VibrationAttributes>(),
)
}
@Test

View File

@@ -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. */