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.statusbar.notification.shared 18 19 import android.os.SystemProperties 20 import com.android.server.notification.Flags 21 import com.android.systemui.flags.FlagToken 22 import com.android.systemui.flags.RefactorFlagUtils 23 24 /** Helper for reading or using the minimalism prototype flag state. */ 25 @Suppress("NOTHING_TO_INLINE") 26 object NotificationMinimalism { 27 const val FLAG_NAME = Flags.FLAG_NOTIFICATION_MINIMALISM 28 29 /** A token used for dependency declaration */ 30 val token: FlagToken 31 get() = FlagToken(FLAG_NAME, isEnabled) 32 33 /** Is the notification minimalism enabled */ 34 @JvmStatic 35 inline val isEnabled 36 get() = Flags.notificationMinimalism() 37 38 /** 39 * The prototype will (by default) use a promoter to ensure that the top unseen notification is 40 * not grouped, but this property read allows that behavior to be disabled. 41 */ 42 val ungroupTopUnseen: Boolean 43 get() = 44 if (isUnexpectedlyInLegacyMode()) false 45 else 46 SystemProperties.getBoolean( 47 "persist.notification_minimalism_prototype.ungroup_top_unseen", 48 false 49 ) 50 51 /** 52 * Called to ensure code is only run when the flag is enabled. This protects users from the 53 * unintended behaviors caused by accidentally running new logic, while also crashing on an eng 54 * build to ensure that the refactor author catches issues in testing. 55 */ 56 @JvmStatic isUnexpectedlyInLegacyModenull57 inline fun isUnexpectedlyInLegacyMode() = 58 RefactorFlagUtils.isUnexpectedlyInLegacyMode(isEnabled, FLAG_NAME) 59 60 /** 61 * Called to ensure code is only run when the flag is disabled. This will throw an exception if 62 * the flag is enabled to ensure that the refactor author catches issues in testing. 63 */ 64 @JvmStatic 65 inline fun assertInLegacyMode() = RefactorFlagUtils.assertInLegacyMode(isEnabled, FLAG_NAME) 66 } 67