Loading packages/SystemUI/src/com/android/systemui/qs/TileStateToProto.kt +3 −2 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 } packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java +3 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); } } Loading packages/SystemUI/tests/src/com/android/systemui/qs/TileStateToProtoTest.kt +35 −3 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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() Loading @@ -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 = Loading Loading
packages/SystemUI/src/com/android/systemui/qs/TileStateToProto.kt +3 −2 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 }
packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java +3 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); } } Loading
packages/SystemUI/tests/src/com/android/systemui/qs/TileStateToProtoTest.kt +35 −3 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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() Loading @@ -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 = Loading