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 package com.android.systemui.statusbar.phone.ongoingcall 17 18 import com.android.systemui.Flags 19 import com.android.systemui.flags.FlagToken 20 import com.android.systemui.flags.RefactorFlagUtils 21 22 /** Helper for reading or using the status_bar_use_interactor_for_call_chip flag state. */ 23 @Suppress("NOTHING_TO_INLINE") 24 object StatusBarChipsModernization { 25 /** The aconfig flag name */ 26 @Deprecated( 27 "For tests, use @EnableChipsModernization or @DisableChipsModernization " + 28 "annotations instead" 29 ) 30 const val FLAG_NAME = Flags.FLAG_STATUS_BAR_CHIPS_MODERNIZATION 31 32 /** A token used for dependency declaration */ 33 val token: FlagToken 34 get() = FlagToken(FLAG_NAME, isEnabled) 35 36 /** Is the refactor enabled */ 37 @JvmStatic 38 inline val isEnabled 39 get() = Flags.statusBarChipsModernization() && Flags.statusBarRootModernization() 40 41 /** 42 * Called to ensure code is only run when the flag is enabled. This protects users from the 43 * unintended behaviors caused by accidentally running new logic, while also crashing on an eng 44 * build to ensure that the refactor author catches issues in testing. 45 */ 46 @JvmStatic isUnexpectedlyInLegacyModenull47 inline fun isUnexpectedlyInLegacyMode() = 48 RefactorFlagUtils.isUnexpectedlyInLegacyMode(isEnabled, FLAG_NAME) 49 50 /** 51 * Called to ensure code is only run when the flag is enabled. This will throw an exception if 52 * the flag is not enabled to ensure that the refactor author catches issues in testing. 53 */ 54 @JvmStatic 55 @Deprecated("Avoid crashing.", ReplaceWith("if (this.isUnexpectedlyInLegacyMode()) return")) 56 inline fun unsafeAssertInNewMode() = 57 RefactorFlagUtils.unsafeAssertInNewMode(isEnabled, FLAG_NAME) 58 59 /** 60 * Called to ensure code is only run when the flag is disabled. This will throw an exception if 61 * the flag is enabled to ensure that the refactor author catches issues in testing. 62 */ 63 @JvmStatic 64 inline fun assertInLegacyMode() = RefactorFlagUtils.assertInLegacyMode(isEnabled, FLAG_NAME) 65 } 66