Merge "Fix long click a11y in QSTileViewImpl" into main
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewImpl.kt b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewImpl.kt
index dbfe818..abc0453 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewImpl.kt
@@ -586,6 +586,15 @@
)
)
)
+ } else {
+ if (isLongClickable) {
+ info.addAction(
+ AccessibilityNodeInfo.AccessibilityAction(
+ AccessibilityNodeInfo.AccessibilityAction.ACTION_LONG_CLICK.id,
+ resources.getString(R.string.accessibility_long_click_tile)
+ )
+ )
+ }
}
if (!TextUtils.isEmpty(accessibilityClass)) {
info.className =
@@ -597,14 +606,6 @@
if (Switch::class.java.name == accessibilityClass) {
info.isChecked = tileState
info.isCheckable = true
- if (isLongClickable) {
- info.addAction(
- AccessibilityNodeInfo.AccessibilityAction(
- AccessibilityNodeInfo.AccessibilityAction.ACTION_LONG_CLICK.id,
- resources.getString(R.string.accessibility_long_click_tile)
- )
- )
- }
}
}
if (position != INVALID) {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tileimpl/QSTileViewImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/tileimpl/QSTileViewImplTest.kt
index 988769f..90ffaf1 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/tileimpl/QSTileViewImplTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tileimpl/QSTileViewImplTest.kt
@@ -25,6 +25,7 @@
import android.view.ContextThemeWrapper
import android.view.View
import android.view.accessibility.AccessibilityNodeInfo
+import android.widget.Button
import android.widget.TextView
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
@@ -381,6 +382,47 @@
}
@Test
+ fun testNonSwitchA11yClass_longClickActionHasCorrectLabel() {
+ val state =
+ QSTile.State().apply {
+ expandedAccessibilityClassName = Button::class.java.name
+ handlesLongClick = true
+ }
+ tileView.changeState(state)
+ val info = AccessibilityNodeInfo(tileView)
+ tileView.onInitializeAccessibilityNodeInfo(info)
+
+ assertThat(
+ info.actionList
+ .find {
+ it.id == AccessibilityNodeInfo.AccessibilityAction.ACTION_LONG_CLICK.id
+ }
+ ?.label
+ )
+ .isEqualTo(context.getString(R.string.accessibility_long_click_tile))
+ }
+
+ @Test
+ fun testNonSwitchA11yClass_disabledByPolicy_noLongClickAction() {
+ val state =
+ QSTile.State().apply {
+ expandedAccessibilityClassName = Button::class.java.name
+ handlesLongClick = true
+ disabledByPolicy = true
+ }
+ tileView.changeState(state)
+ val info = AccessibilityNodeInfo(tileView)
+ tileView.onInitializeAccessibilityNodeInfo(info)
+
+ assertThat(
+ info.actionList.find {
+ it.id == AccessibilityNodeInfo.AccessibilityAction.ACTION_LONG_CLICK.id
+ }
+ )
+ .isNull()
+ }
+
+ @Test
fun onStateChange_longPressEffectActive_withInvalidDuration_doesNotInitializeEffect() {
val state = QSTile.State() // A state that handles longPress