1 /* <lambda>null2 * 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.qs.flags 18 19 import com.android.systemui.Flags 20 import com.android.systemui.flags.FlagToken 21 import com.android.systemui.flags.RefactorFlagUtils 22 import com.android.systemui.scene.shared.flag.SceneContainerFlag 23 24 /** Helper for reading or using the QS Detailed View flag state. */ 25 @Suppress("NOTHING_TO_INLINE") 26 object QsDetailedView { 27 /** The aconfig flag name */ 28 const val FLAG_NAME = Flags.FLAG_QS_TILE_DETAILED_VIEW 29 30 /** A token used for dependency declaration */ 31 val token: FlagToken 32 get() = FlagToken(FLAG_NAME, isEnabled) 33 34 /** Is the flag enabled */ 35 @JvmStatic 36 inline val isEnabled 37 get() = 38 Flags.qsTileDetailedView() && // mainAconfigFlag 39 SceneContainerFlag.isEnabled 40 41 // NOTE: Changes should also be made in getSecondaryFlags 42 43 /** The main aconfig flag. */ 44 inline fun getMainAconfigFlag() = FlagToken(FLAG_NAME, Flags.qsTileDetailedView()) 45 46 /** The set of secondary flags which must be enabled for qs detailed view to work properly */ 47 inline fun getSecondaryFlags(): Sequence<FlagToken> = 48 // NOTE: Changes should also be made in isEnabled 49 SceneContainerFlag.getAllRequirements() 50 51 /** The full set of requirements for QsDetailedView */ 52 inline fun getAllRequirements(): Sequence<FlagToken> { 53 return sequenceOf(getMainAconfigFlag()) + getSecondaryFlags() 54 } 55 56 /** Return all dependencies of this flag in pairs where [Pair.first] depends on [Pair.second] */ 57 inline fun getFlagDependencies(): Sequence<Pair<FlagToken, FlagToken>> { 58 val mainAconfigFlag = getMainAconfigFlag() 59 return getSecondaryFlags().map { mainAconfigFlag to it } 60 } 61 62 /** 63 * Called to ensure code is only run when the flag is enabled. This protects users from the 64 * unintended behaviors caused by accidentally running new logic, while also crashing on an eng 65 * build to ensure that the refactor author catches issues in testing. 66 */ 67 @JvmStatic 68 inline fun isUnexpectedlyInLegacyMode() = 69 RefactorFlagUtils.isUnexpectedlyInLegacyMode(isEnabled, FLAG_NAME) 70 71 /** 72 * Called to ensure code is only run when the flag is disabled. This will throw an exception if 73 * the flag is enabled to ensure that the refactor author catches issues in testing. 74 */ 75 @JvmStatic 76 inline fun assertInLegacyMode() = RefactorFlagUtils.assertInLegacyMode(isEnabled, FLAG_NAME) 77 78 /** 79 * Called to ensure code is only run when the flag is enabled. This will throw an exception if 80 * the flag is not enabled to ensure that the refactor author catches issues in testing. 81 * Caution!! Using this check incorrectly will cause crashes in nextfood builds! 82 */ 83 @JvmStatic 84 @Deprecated("Avoid crashing.", ReplaceWith("if (this.isUnexpectedlyInLegacyMode()) return")) 85 inline fun unsafeAssertInNewMode() = 86 RefactorFlagUtils.unsafeAssertInNewMode(isEnabled, FLAG_NAME) 87 88 /** Returns a developer-readable string that describes the current requirement list. */ 89 @JvmStatic 90 fun requirementDescription(): String { 91 return buildString { 92 getAllRequirements().forEach { requirement -> 93 append('\n') 94 append(if (requirement.isEnabled) " [MET]" else "[NOT MET]") 95 append(" ${requirement.name}") 96 } 97 } 98 } 99 } 100