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

Commit bd33f597 authored by Ben Lin's avatar Ben Lin
Browse files

[flexiglass] Check if there are duplicate scenes with the same key.

At Module level when init-ing with the scenes, do a check to see if
there are any duplicate scenes with the same SceneKey since that is not
expected.

Bug: None
Test: Manually provide module with the same key, see crash
Flag: ACONFIG com.android.systemui.scene_container DEVELOPMENT
Change-Id: I3e555e2492b2328c66a221f68e07a9f6b52bd4e0
parent ab57e5b3
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.Handler
import android.view.LayoutInflater
import android.view.ViewStub
import androidx.constraintlayout.motion.widget.MotionLayout
import com.android.compose.animation.scene.SceneKey
import com.android.keyguard.logging.ScrimLogger
import com.android.systemui.battery.BatteryMeterView
import com.android.systemui.battery.BatteryMeterViewController
@@ -76,6 +77,7 @@ abstract class ShadeViewProviderModule {
            sceneDataSourceDelegator: Provider<SceneDataSourceDelegator>,
        ): WindowRootView {
            return if (sceneContainerFlags.isEnabled()) {
                checkNoSceneDuplicates(scenesProvider.get())
                val sceneWindowRootView =
                    layoutInflater.inflate(R.layout.scene_window_root, null) as SceneWindowRootView
                sceneWindowRootView.init(
@@ -271,5 +273,21 @@ abstract class ShadeViewProviderModule {
        ): StatusIconContainer {
            return header.requireViewById(R.id.statusIcons)
        }

        private fun checkNoSceneDuplicates(scenes: Set<Scene>) {
            val keys = mutableSetOf<SceneKey>()
            val duplicates = mutableSetOf<SceneKey>()
            scenes
                .map { it.key }
                .forEach { sceneKey ->
                    if (keys.contains(sceneKey)) {
                        duplicates.add(sceneKey)
                    } else {
                        keys.add(sceneKey)
                    }
                }

            check(duplicates.isEmpty()) { "Duplicate scenes detected: $duplicates" }
        }
    }
}