diff options
| author | 2024-12-04 09:48:24 -0500 | |
|---|---|---|
| committer | 2024-12-04 09:51:18 -0500 | |
| commit | 3d8a5de4965f769c3a685660a0a2433ff64d267e (patch) | |
| tree | 9d6150d7a0f5273eaf1252e98dc0a56c4b95b71d | |
| parent | 9789ec8298f358c3858257148a33ca12f39484ea (diff) | |
Add nullability and type guarantees
This will help understand how State can be null. Also, make sure that
it's never null in QSTileViewModelAdapter.
Test: manual with both flags on
Test: atest com.android.systemui.qs
Fixes: 382127614
Flag: com.android.systemui.qs_ui_refactor_compose_fragment
Flag: com.android.systemui.qs_new_tiles
Change-Id: Ie44dd2dca702253317eb82bba60a397de01f2349
6 files changed, 13 insertions, 3 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/customize/TileQueryHelperTest.java b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/customize/TileQueryHelperTest.java index 09a6c2c7f1f7..1899b7d1f1bb 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/customize/TileQueryHelperTest.java +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/customize/TileQueryHelperTest.java @@ -44,6 +44,7 @@ import android.testing.TestableLooper; import android.text.TextUtils; import android.util.ArraySet; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; @@ -384,6 +385,7 @@ public class TileQueryHelperTest extends SysuiTestCase { return mSpec; } + @NonNull @Override public State getState() { return mState; diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QSTile.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QSTile.java index e3cbd6643e5f..322da322ff0c 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QSTile.java +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QSTile.java @@ -14,7 +14,6 @@ package com.android.systemui.plugins.qs; -import android.annotation.NonNull; import android.content.Context; import android.content.res.Resources; import android.graphics.drawable.Drawable; @@ -22,6 +21,7 @@ import android.metrics.LogMaker; import android.service.quicksettings.Tile; import android.text.TextUtils; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.android.internal.logging.InstanceId; @@ -92,6 +92,7 @@ public interface QSTile { CharSequence getTileLabel(); + @NonNull State getState(); default LogMaker populate(LogMaker logMaker) { @@ -269,6 +270,7 @@ public interface QSTile { return sb.append(']'); } + @NonNull public State copy() { State state = new State(); copyTo(state); @@ -304,6 +306,7 @@ public interface QSTile { return rt; } + @androidx.annotation.NonNull @Override public State copy() { AdapterState state = new AdapterState(); @@ -316,6 +319,7 @@ public interface QSTile { class BooleanState extends AdapterState { public static final int VERSION = 1; + @androidx.annotation.NonNull @Override public State copy() { BooleanState state = new BooleanState(); diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/Tile.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/Tile.kt index abdf923ebe73..a319f036ef71 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/Tile.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/Tile.kt @@ -125,7 +125,7 @@ fun Tile( modifier: Modifier = Modifier, detailsViewModel: DetailsViewModel?, ) { - val state by tile.state.collectAsStateWithLifecycle(tile.currentState) + val state: QSTile.State by tile.state.collectAsStateWithLifecycle(tile.currentState) val currentBounceableInfo by rememberUpdatedState(bounceableInfo) val resources = resources() val uiState = remember(state, resources) { state.toUiState(resources) } diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/TileViewModel.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/TileViewModel.kt index 44dd801a8b9f..9462321ad9fd 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/TileViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/TileViewModel.kt @@ -24,6 +24,7 @@ import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.onStart @Immutable @@ -37,6 +38,7 @@ class TileViewModel(private val tile: QSTile, val spec: TileSpec) { awaitClose { tile.removeCallback(callback) } } .onStart { emit(tile.state) } + .filterNotNull() .distinctUntilChanged() val currentState: QSTile.State diff --git a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileImpl.java b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileImpl.java index 464eeda6a0a8..1d1e9911884c 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileImpl.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileImpl.java @@ -369,6 +369,7 @@ public abstract class QSTileImpl<TState extends State> implements QSTile, Lifecy mHandler.sendEmptyMessage(H.INITIALIZE); } + @androidx.annotation.NonNull public TState getState() { return mState; } diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/viewmodel/QSTileViewModelAdapter.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/viewmodel/QSTileViewModelAdapter.kt index ab3862b75ee8..af920888c714 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/viewmodel/QSTileViewModelAdapter.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/viewmodel/QSTileViewModelAdapter.kt @@ -196,8 +196,9 @@ constructor( qsTileViewModel.destroy() } - override fun getState(): QSTile.State? = + override fun getState(): QSTile.State = qsTileViewModel.currentState?.let { mapState(context, it, qsTileViewModel.config) } + ?: QSTile.State() override fun getInstanceId(): InstanceId = qsTileViewModel.config.instanceId |