1 /*
2 * Copyright (C) 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.android.systemui.flags
18
19 import android.platform.test.annotations.EnableFlags
20 import android.platform.test.flag.junit.FlagsParameterization
21 import com.android.systemui.Flags.FLAG_SCENE_CONTAINER
22
23 /** The name of the one flag to be disabled for OFF parameterization */
24 private const val flagNameToDisable = FLAG_SCENE_CONTAINER
25
26 /** Cache of the flags to be enabled for ON parameterization */
27 private val flagNamesToEnable =
28 EnableSceneContainer::class.java.getAnnotation(EnableFlags::class.java)!!.value.toList()
29
30 /**
31 * Provides one or two copies of this [FlagsParameterization]; one which disabled
32 * [FLAG_SCENE_CONTAINER] and if none of the dependencies of it are disabled by this, a second copy
33 * which enables [FLAG_SCENE_CONTAINER] and all the dependencies (just like [EnableSceneContainer]).
34 */
<lambda>null35 fun FlagsParameterization.andSceneContainer(): Sequence<FlagsParameterization> = sequence {
36 check(flagNameToDisable !in mOverrides) {
37 "Can't add $flagNameToDisable to FlagsParameterization: $this"
38 }
39 yield(FlagsParameterization(mOverrides + mapOf(flagNameToDisable to false)))
40 if (flagNamesToEnable.all { mOverrides[it] != false }) {
41 // Can't add the parameterization of enabling SceneContainerFlag to a parameterization that
42 // explicitly disables one of the prerequisite flags.
43 yield(FlagsParameterization(mOverrides + flagNamesToEnable.associateWith { true }))
44 }
45 }
46
47 /**
48 * Doubles (roughly; see below) the given list of [FlagsParameterization] for enabling and disabling
49 * SceneContainerFlag.
50 *
51 * The input parameterization may not define [FLAG_SCENE_CONTAINER].
52 *
53 * Any [FlagsParameterization] which disables any flag that is a dependency of
54 * [FLAG_SCENE_CONTAINER], will not add a state for enabling, and the state will simply be converted
55 * to one which disables. Just like [EnableSceneContainer], enabling will also enable all the other
56 * dependencies. For any flag parameterization where a dependency is disabled, an "enabled"
57 * parameterization is inconsistent, so it will not be added.
58 */
andSceneContainernull59 fun List<FlagsParameterization>.andSceneContainer(): List<FlagsParameterization> =
60 flatMap { it.andSceneContainer() }.toList()
61
62 /** Parameterizes only the scene container flag. */
parameterizeSceneContainerFlagnull63 fun parameterizeSceneContainerFlag(): List<FlagsParameterization> {
64 return FlagsParameterization.allCombinationsOf().andSceneContainer()
65 }
66