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.bouncer.shared.flag
18 
19 import com.android.systemui.Flags
20 import com.android.systemui.flags.RefactorFlagUtils
21 import com.android.systemui.scene.shared.flag.SceneContainerFlag
22 
23 object ComposeBouncerFlags {
24 
25     /** @see [isComposeBouncerOrSceneContainerEnabled] */
26     val isEnabled: Boolean
27         get() = isComposeBouncerOrSceneContainerEnabled()
28 
29     /**
30      * Returns `true` if the Compose bouncer is enabled or if the scene container framework is
31      * enabled; `false` otherwise.
32      */
isComposeBouncerOrSceneContainerEnablednull33     fun isComposeBouncerOrSceneContainerEnabled(): Boolean {
34         return SceneContainerFlag.isEnabled || Flags.composeBouncer()
35     }
36 
37     /**
38      * Called to ensure code is only run when the flag is enabled. This protects users from the
39      * unintended behaviors caused by accidentally running new logic, while also crashing on an eng
40      * build to ensure that the refactor author catches issues in testing.
41      */
42     @JvmStatic
isUnexpectedlyInLegacyModenull43     fun isUnexpectedlyInLegacyMode() =
44         RefactorFlagUtils.isUnexpectedlyInLegacyMode(
45             isEnabled,
46             "SceneContainerFlag || ComposeBouncerFlag",
47         )
48 
49     /**
50      * Called to ensure code is only run when the flag is disabled. This will throw an exception if
51      * the flag is enabled to ensure that the refactor author catches issues in testing.
52      */
53     @JvmStatic
54     fun assertInLegacyMode() =
55         RefactorFlagUtils.assertInLegacyMode(isEnabled, "SceneContainerFlag || ComposeBouncerFlag")
56 
57     /**
58      * Returns `true` if only compose bouncer is enabled and scene container framework is not
59      * enabled.
60      */
61     @Deprecated(
62         "Avoid using this, this is meant to be used only by the glue code " +
63             "that includes compose bouncer in legacy keyguard.",
64         replaceWith = ReplaceWith("isComposeBouncerOrSceneContainerEnabled()"),
65     )
66     fun isOnlyComposeBouncerEnabled(): Boolean {
67         return !SceneContainerFlag.isEnabled && Flags.composeBouncer()
68     }
69 }
70