Loading packages/SystemUI/src/com/android/systemui/modes/shared/ModesUi.kt 0 → 100644 +54 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.modes.shared import android.app.Flags import com.android.systemui.flags.RefactorFlagUtils /** Helper for reading or using the modes ui flag state. */ @Suppress("NOTHING_TO_INLINE") object ModesUi { /** Is the refactor enabled */ @JvmStatic inline val isEnabled get() = Flags.modesApi() && Flags.modesUi() /** * Called to ensure code is only run when the flag is enabled. This protects users from the * unintended behaviors caused by accidentally running new logic, while also crashing on an eng * build to ensure that the refactor author catches issues in testing. */ @JvmStatic inline fun isUnexpectedlyInLegacyMode() = RefactorFlagUtils.isUnexpectedlyInLegacyMode(isEnabled, Flags.FLAG_MODES_UI) /** * Called to ensure code is only run when the flag is disabled. This will throw an exception if * the flag is not enabled to ensure that the refactor author catches issues in testing. * Caution!! Using this check incorrectly will cause crashes in nextfood builds! */ @JvmStatic inline fun assertInNewMode() = RefactorFlagUtils.assertInNewMode(isEnabled, Flags.FLAG_MODES_UI) /** * Called to ensure code is only run when the flag is disabled. This will throw an exception if * the flag is enabled to ensure that the refactor author catches issues in testing. */ @JvmStatic inline fun assertInLegacyMode() = RefactorFlagUtils.assertInLegacyMode(isEnabled, Flags.FLAG_MODES_UI) } packages/SystemUI/src/com/android/systemui/modes/shared/ModesUiIcons.kt 0 → 100644 +55 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.modes.shared import android.app.Flags import com.android.systemui.flags.RefactorFlagUtils /** Helper for reading or using the modes ui icons flag state. */ @Suppress("NOTHING_TO_INLINE") object ModesUiIcons { /** Is the refactor enabled */ @JvmStatic inline val isEnabled get() = ModesUi.isEnabled && Flags.modesUiIcons() /** * Called to ensure code is only run when the flag is enabled. This protects users from the * unintended behaviors caused by accidentally running new logic, while also crashing on an eng * build to ensure that the refactor author catches issues in testing. */ @JvmStatic inline fun isUnexpectedlyInLegacyMode() = RefactorFlagUtils.isUnexpectedlyInLegacyMode(isEnabled, Flags.FLAG_MODES_UI_ICONS) /** * Called to ensure code is only run when the flag is disabled. This will throw an exception if * the flag is not enabled to ensure that the refactor author catches issues in testing. * Caution!! Using this check incorrectly will cause crashes in nextfood builds! */ @JvmStatic inline fun assertInNewMode() = RefactorFlagUtils.assertInNewMode(isEnabled, Flags.FLAG_MODES_UI_ICONS) /** * Called to ensure code is only run when the flag is disabled. This will throw an exception if * the flag is enabled to ensure that the refactor author catches issues in testing. */ @JvmStatic inline fun assertInLegacyMode() = RefactorFlagUtils.assertInLegacyMode(isEnabled, Flags.FLAG_MODES_UI_ICONS) } packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java +2 −3 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ import com.android.systemui.animation.DialogTransitionAnimator; import com.android.systemui.animation.Expandable; import com.android.systemui.dagger.qualifiers.Background; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.flags.RefactorFlagUtils; import com.android.systemui.modes.shared.ModesUi; import com.android.systemui.plugins.ActivityStarter; import com.android.systemui.plugins.FalsingManager; import com.android.systemui.plugins.qs.QSTile.BooleanState; Loading Loading @@ -108,8 +108,7 @@ public class DndTile extends QSTileImpl<BooleanState> { statusBarStateController, activityStarter, qsLogger); // If the flag is on, this shouldn't run at all since the modes tile replaces the DND tile. RefactorFlagUtils.INSTANCE.assertInLegacyMode(android.app.Flags.modesUi(), android.app.Flags.FLAG_MODES_UI); ModesUi.assertInLegacyMode(); mController = zenModeController; mSharedPreferences = sharedPreferences; Loading packages/SystemUI/src/com/android/systemui/qs/tiles/ModesTile.kt +5 −5 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.systemui.qs.tiles import android.app.Flags import android.content.Intent import android.os.Handler import android.os.Looper Loading @@ -30,7 +29,8 @@ import com.android.internal.logging.MetricsLogger import com.android.systemui.animation.Expandable import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.flags.RefactorFlagUtils.isUnexpectedlyInLegacyMode import com.android.systemui.modes.shared.ModesUi import com.android.systemui.modes.shared.ModesUiIcons import com.android.systemui.plugins.ActivityStarter import com.android.systemui.plugins.FalsingManager import com.android.systemui.plugins.qs.QSTile Loading Loading @@ -77,14 +77,14 @@ constructor( metricsLogger, statusBarStateController, activityStarter, qsLogger qsLogger, ) { private lateinit var tileState: QSTileState private val config = qsTileConfigProvider.getConfig(TILE_SPEC) init { /* Check if */ isUnexpectedlyInLegacyMode(Flags.modesUi(), Flags.FLAG_MODES_UI) /* Check if */ ModesUiIcons.isUnexpectedlyInLegacyMode() lifecycle.coroutineScope.launch { lifecycle.repeatOnLifecycle(Lifecycle.State.RESUMED) { Loading @@ -93,7 +93,7 @@ constructor( } } override fun isAvailable(): Boolean = Flags.modesUi() override fun isAvailable(): Boolean = ModesUi.isEnabled override fun getTileLabel(): CharSequence = tileState.label Loading packages/SystemUI/src/com/android/systemui/qs/tiles/impl/modes/domain/interactor/ModesTileDataInteractor.kt +7 −8 Original line number Diff line number Diff line Loading @@ -16,13 +16,14 @@ package com.android.systemui.qs.tiles.impl.modes.domain.interactor import android.app.Flags import android.content.Context import android.os.UserHandle import com.android.app.tracing.coroutines.flow.map import com.android.systemui.common.shared.model.Icon import com.android.systemui.common.shared.model.asIcon import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.modes.shared.ModesUi import com.android.systemui.modes.shared.ModesUiIcons import com.android.systemui.qs.tiles.ModesTile import com.android.systemui.qs.tiles.base.interactor.DataUpdateTrigger import com.android.systemui.qs.tiles.base.interactor.QSTileDataInteractor Loading @@ -47,7 +48,7 @@ constructor( override fun tileData( user: UserHandle, triggers: Flow<DataUpdateTrigger> triggers: Flow<DataUpdateTrigger>, ): Flow<ModesTileModel> = tileData() /** Loading @@ -64,20 +65,20 @@ constructor( suspend fun getCurrentTileModel() = buildTileData(zenModeInteractor.getActiveModes()) private fun buildTileData(activeModes: ActiveZenModes): ModesTileModel { if (usesModeIcons()) { if (ModesUiIcons.isEnabled) { val tileIcon = getTileIcon(activeModes.mainMode) return ModesTileModel( isActivated = activeModes.isAnyActive(), icon = tileIcon.icon, iconResId = tileIcon.resId, activeModes = activeModes.modeNames activeModes = activeModes.modeNames, ) } else { return ModesTileModel( isActivated = activeModes.isAnyActive(), icon = context.getDrawable(ModesTile.ICON_RES_ID)!!.asIcon(), iconResId = ModesTile.ICON_RES_ID, activeModes = activeModes.modeNames activeModes = activeModes.modeNames, ) } } Loading @@ -97,7 +98,5 @@ constructor( } } override fun availability(user: UserHandle): Flow<Boolean> = flowOf(Flags.modesUi()) private fun usesModeIcons() = Flags.modesApi() && Flags.modesUi() && Flags.modesUiIcons() override fun availability(user: UserHandle): Flow<Boolean> = flowOf(ModesUi.isEnabled) } Loading
packages/SystemUI/src/com/android/systemui/modes/shared/ModesUi.kt 0 → 100644 +54 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.modes.shared import android.app.Flags import com.android.systemui.flags.RefactorFlagUtils /** Helper for reading or using the modes ui flag state. */ @Suppress("NOTHING_TO_INLINE") object ModesUi { /** Is the refactor enabled */ @JvmStatic inline val isEnabled get() = Flags.modesApi() && Flags.modesUi() /** * Called to ensure code is only run when the flag is enabled. This protects users from the * unintended behaviors caused by accidentally running new logic, while also crashing on an eng * build to ensure that the refactor author catches issues in testing. */ @JvmStatic inline fun isUnexpectedlyInLegacyMode() = RefactorFlagUtils.isUnexpectedlyInLegacyMode(isEnabled, Flags.FLAG_MODES_UI) /** * Called to ensure code is only run when the flag is disabled. This will throw an exception if * the flag is not enabled to ensure that the refactor author catches issues in testing. * Caution!! Using this check incorrectly will cause crashes in nextfood builds! */ @JvmStatic inline fun assertInNewMode() = RefactorFlagUtils.assertInNewMode(isEnabled, Flags.FLAG_MODES_UI) /** * Called to ensure code is only run when the flag is disabled. This will throw an exception if * the flag is enabled to ensure that the refactor author catches issues in testing. */ @JvmStatic inline fun assertInLegacyMode() = RefactorFlagUtils.assertInLegacyMode(isEnabled, Flags.FLAG_MODES_UI) }
packages/SystemUI/src/com/android/systemui/modes/shared/ModesUiIcons.kt 0 → 100644 +55 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.modes.shared import android.app.Flags import com.android.systemui.flags.RefactorFlagUtils /** Helper for reading or using the modes ui icons flag state. */ @Suppress("NOTHING_TO_INLINE") object ModesUiIcons { /** Is the refactor enabled */ @JvmStatic inline val isEnabled get() = ModesUi.isEnabled && Flags.modesUiIcons() /** * Called to ensure code is only run when the flag is enabled. This protects users from the * unintended behaviors caused by accidentally running new logic, while also crashing on an eng * build to ensure that the refactor author catches issues in testing. */ @JvmStatic inline fun isUnexpectedlyInLegacyMode() = RefactorFlagUtils.isUnexpectedlyInLegacyMode(isEnabled, Flags.FLAG_MODES_UI_ICONS) /** * Called to ensure code is only run when the flag is disabled. This will throw an exception if * the flag is not enabled to ensure that the refactor author catches issues in testing. * Caution!! Using this check incorrectly will cause crashes in nextfood builds! */ @JvmStatic inline fun assertInNewMode() = RefactorFlagUtils.assertInNewMode(isEnabled, Flags.FLAG_MODES_UI_ICONS) /** * Called to ensure code is only run when the flag is disabled. This will throw an exception if * the flag is enabled to ensure that the refactor author catches issues in testing. */ @JvmStatic inline fun assertInLegacyMode() = RefactorFlagUtils.assertInLegacyMode(isEnabled, Flags.FLAG_MODES_UI_ICONS) }
packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java +2 −3 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ import com.android.systemui.animation.DialogTransitionAnimator; import com.android.systemui.animation.Expandable; import com.android.systemui.dagger.qualifiers.Background; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.flags.RefactorFlagUtils; import com.android.systemui.modes.shared.ModesUi; import com.android.systemui.plugins.ActivityStarter; import com.android.systemui.plugins.FalsingManager; import com.android.systemui.plugins.qs.QSTile.BooleanState; Loading Loading @@ -108,8 +108,7 @@ public class DndTile extends QSTileImpl<BooleanState> { statusBarStateController, activityStarter, qsLogger); // If the flag is on, this shouldn't run at all since the modes tile replaces the DND tile. RefactorFlagUtils.INSTANCE.assertInLegacyMode(android.app.Flags.modesUi(), android.app.Flags.FLAG_MODES_UI); ModesUi.assertInLegacyMode(); mController = zenModeController; mSharedPreferences = sharedPreferences; Loading
packages/SystemUI/src/com/android/systemui/qs/tiles/ModesTile.kt +5 −5 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.systemui.qs.tiles import android.app.Flags import android.content.Intent import android.os.Handler import android.os.Looper Loading @@ -30,7 +29,8 @@ import com.android.internal.logging.MetricsLogger import com.android.systemui.animation.Expandable import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.flags.RefactorFlagUtils.isUnexpectedlyInLegacyMode import com.android.systemui.modes.shared.ModesUi import com.android.systemui.modes.shared.ModesUiIcons import com.android.systemui.plugins.ActivityStarter import com.android.systemui.plugins.FalsingManager import com.android.systemui.plugins.qs.QSTile Loading Loading @@ -77,14 +77,14 @@ constructor( metricsLogger, statusBarStateController, activityStarter, qsLogger qsLogger, ) { private lateinit var tileState: QSTileState private val config = qsTileConfigProvider.getConfig(TILE_SPEC) init { /* Check if */ isUnexpectedlyInLegacyMode(Flags.modesUi(), Flags.FLAG_MODES_UI) /* Check if */ ModesUiIcons.isUnexpectedlyInLegacyMode() lifecycle.coroutineScope.launch { lifecycle.repeatOnLifecycle(Lifecycle.State.RESUMED) { Loading @@ -93,7 +93,7 @@ constructor( } } override fun isAvailable(): Boolean = Flags.modesUi() override fun isAvailable(): Boolean = ModesUi.isEnabled override fun getTileLabel(): CharSequence = tileState.label Loading
packages/SystemUI/src/com/android/systemui/qs/tiles/impl/modes/domain/interactor/ModesTileDataInteractor.kt +7 −8 Original line number Diff line number Diff line Loading @@ -16,13 +16,14 @@ package com.android.systemui.qs.tiles.impl.modes.domain.interactor import android.app.Flags import android.content.Context import android.os.UserHandle import com.android.app.tracing.coroutines.flow.map import com.android.systemui.common.shared.model.Icon import com.android.systemui.common.shared.model.asIcon import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.modes.shared.ModesUi import com.android.systemui.modes.shared.ModesUiIcons import com.android.systemui.qs.tiles.ModesTile import com.android.systemui.qs.tiles.base.interactor.DataUpdateTrigger import com.android.systemui.qs.tiles.base.interactor.QSTileDataInteractor Loading @@ -47,7 +48,7 @@ constructor( override fun tileData( user: UserHandle, triggers: Flow<DataUpdateTrigger> triggers: Flow<DataUpdateTrigger>, ): Flow<ModesTileModel> = tileData() /** Loading @@ -64,20 +65,20 @@ constructor( suspend fun getCurrentTileModel() = buildTileData(zenModeInteractor.getActiveModes()) private fun buildTileData(activeModes: ActiveZenModes): ModesTileModel { if (usesModeIcons()) { if (ModesUiIcons.isEnabled) { val tileIcon = getTileIcon(activeModes.mainMode) return ModesTileModel( isActivated = activeModes.isAnyActive(), icon = tileIcon.icon, iconResId = tileIcon.resId, activeModes = activeModes.modeNames activeModes = activeModes.modeNames, ) } else { return ModesTileModel( isActivated = activeModes.isAnyActive(), icon = context.getDrawable(ModesTile.ICON_RES_ID)!!.asIcon(), iconResId = ModesTile.ICON_RES_ID, activeModes = activeModes.modeNames activeModes = activeModes.modeNames, ) } } Loading @@ -97,7 +98,5 @@ constructor( } } override fun availability(user: UserHandle): Flow<Boolean> = flowOf(Flags.modesUi()) private fun usesModeIcons() = Flags.modesApi() && Flags.modesUi() && Flags.modesUiIcons() override fun availability(user: UserHandle): Flow<Boolean> = flowOf(ModesUi.isEnabled) }