1 /*
2  * Copyright (C) 2023 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.statusbar.notification.row.shared
18 
19 import com.android.systemui.Flags
20 import com.android.systemui.flags.FlagToken
21 import com.android.systemui.flags.RefactorFlagUtils
22 
23 /** Helper for reading or using the async hybrid view inflation flag state. */
24 @Suppress("NOTHING_TO_INLINE")
25 object AsyncHybridViewInflation {
26     const val FLAG_NAME = Flags.FLAG_NOTIFICATION_ASYNC_HYBRID_VIEW_INFLATION
27 
28     /** A token used for dependency declaration */
29     val token: FlagToken
30         get() = FlagToken(FLAG_NAME, isEnabled)
31 
32     /** Is async hybrid (single-line) view inflation enabled */
33     @JvmStatic
34     inline val isEnabled
35         get() = Flags.notificationAsyncHybridViewInflation()
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     inline fun isUnexpectedlyInLegacyMode() =
44         RefactorFlagUtils.isUnexpectedlyInLegacyMode(isEnabled, FLAG_NAME)
45 
46     /**
47      * Called to ensure code is only run when the flag is disabled. This will throw an exception if
48      * the flag is enabled to ensure that the refactor author catches issues in testing.
49      */
50     @JvmStatic
51     inline fun assertInLegacyMode() = RefactorFlagUtils.assertInLegacyMode(isEnabled, FLAG_NAME)
52 }
53