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

Commit c9156f0c authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix failing CTS tile tests" into main

parents 37a405ee 72cde240
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.qs

import android.service.quicksettings.Tile
import android.text.TextUtils
import android.widget.Switch
import com.android.systemui.plugins.qs.QSTile
import com.android.systemui.qs.external.CustomTile
import com.android.systemui.qs.nano.QsTileState
@@ -44,8 +45,8 @@ fun QSTile.State.toProto(): QsTileState? {
        }
    label?.let { state.label = it.toString() }
    secondaryLabel?.let { state.secondaryLabel = it.toString() }
    if (this is QSTile.BooleanState) {
        state.booleanState = value
    if (expandedAccessibilityClassName == Switch::class.java.name) {
        state.booleanState = state.state == QsTileState.ACTIVE
    }
    return state
}
+3 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.text.format.DateUtils;
import android.util.Log;
import android.view.IWindowManager;
import android.view.WindowManagerGlobal;
import android.widget.Button;
import android.widget.Switch;

import androidx.annotation.Nullable;
@@ -502,6 +503,8 @@ public class CustomTile extends QSTileImpl<State> implements TileChangeListener,
        if (state instanceof BooleanState) {
            state.expandedAccessibilityClassName = Switch.class.getName();
            ((BooleanState) state).value = (state.state == Tile.STATE_ACTIVE);
        } else {
            state.expandedAccessibilityClassName = Button.class.getName();
        }

    }
+35 −3
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ package com.android.systemui.qs
import android.content.ComponentName
import android.service.quicksettings.Tile
import android.testing.AndroidTestingRunner
import android.widget.Switch
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.plugins.qs.QSTile
@@ -66,15 +67,19 @@ class TileStateToProtoTest : SysuiTestCase() {
        assertThat(proto?.hasBooleanState()).isFalse()
    }

    /**
     * The [QSTile.AdapterState.expandedAccessibilityClassName] setting to [Switch] results in the
     * proto having a booleanState. The value of that boolean is true iff the tile is active.
     */
    @Test
    fun booleanState_ACTIVE() {
    fun adapterState_ACTIVE() {
        val state =
            QSTile.BooleanState().apply {
            QSTile.AdapterState().apply {
                spec = TEST_SPEC
                label = TEST_LABEL
                secondaryLabel = TEST_SUBTITLE
                state = Tile.STATE_ACTIVE
                value = true
                expandedAccessibilityClassName = Switch::class.java.name
            }
        val proto = state.toProto()

@@ -89,6 +94,33 @@ class TileStateToProtoTest : SysuiTestCase() {
        assertThat(proto?.booleanState).isTrue()
    }

    /**
     * Similar to [adapterState_ACTIVE], the use of
     * [QSTile.AdapterState.expandedAccessibilityClassName] signals that the tile is toggleable.
     */
    @Test
    fun adapterState_INACTIVE() {
        val state =
            QSTile.AdapterState().apply {
                spec = TEST_SPEC
                label = TEST_LABEL
                secondaryLabel = TEST_SUBTITLE
                state = Tile.STATE_INACTIVE
                expandedAccessibilityClassName = Switch::class.java.name
            }
        val proto = state.toProto()

        assertThat(proto).isNotNull()
        assertThat(proto?.hasSpec()).isTrue()
        assertThat(proto?.spec).isEqualTo(TEST_SPEC)
        assertThat(proto?.hasComponentName()).isFalse()
        assertThat(proto?.label).isEqualTo(TEST_LABEL)
        assertThat(proto?.secondaryLabel).isEqualTo(TEST_SUBTITLE)
        assertThat(proto?.state).isEqualTo(Tile.STATE_INACTIVE)
        assertThat(proto?.hasBooleanState()).isTrue()
        assertThat(proto?.booleanState).isFalse()
    }

    @Test
    fun noSpec_returnsNull() {
        val state =