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.modes.shared 18 19 import android.app.Flags 20 import com.android.systemui.flags.RefactorFlagUtils 21 22 /** Helper for reading or using the modes ui flag state. */ 23 @Suppress("NOTHING_TO_INLINE") 24 object ModesUi { 25 /** Is the refactor enabled */ 26 @JvmStatic 27 inline val isEnabled 28 get() = Flags.modesUi() 29 30 /** 31 * Called to ensure code is only run when the flag is enabled. This protects users from the 32 * unintended behaviors caused by accidentally running new logic, while also crashing on an eng 33 * build to ensure that the refactor author catches issues in testing. 34 */ 35 @JvmStatic isUnexpectedlyInLegacyModenull36 inline fun isUnexpectedlyInLegacyMode() = 37 RefactorFlagUtils.isUnexpectedlyInLegacyMode(isEnabled, Flags.FLAG_MODES_UI) 38 39 /** 40 * Called to ensure code is only run when the flag is disabled. This will throw an exception if 41 * the flag is not enabled to ensure that the refactor author catches issues in testing. 42 * Caution!! Using this check incorrectly will cause crashes in nextfood builds! 43 */ 44 @JvmStatic 45 @Deprecated("Avoid crashing.", ReplaceWith("if (this.isUnexpectedlyInLegacyMode()) return")) 46 inline fun unsafeAssertInNewMode() = 47 RefactorFlagUtils.unsafeAssertInNewMode(isEnabled, Flags.FLAG_MODES_UI) 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 inline fun assertInLegacyMode() = 55 RefactorFlagUtils.assertInLegacyMode(isEnabled, Flags.FLAG_MODES_UI) 56 } 57