Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9d8a7016 authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

Add refactor checks for footer redesign.

Flag: com.android.systemui.notifications_redesign_footer_view
Bug: 375010573
Test: builds, doesn't crash
Change-Id: Ic4b8a8790f08d97ee83fbdb0d4518544d9064b65
parent 64f669ee
Loading
Loading
Loading
Loading
+61 −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.statusbar.notification.footer.shared

import com.android.systemui.Flags
import com.android.systemui.flags.FlagToken
import com.android.systemui.flags.RefactorFlagUtils

/** Helper for reading or using the flag state for the footer redesign. */
@Suppress("NOTHING_TO_INLINE")
object NotifRedesignFooter {
    /** The aconfig flag name */
    const val FLAG_NAME = Flags.FLAG_NOTIFICATIONS_REDESIGN_FOOTER_VIEW

    /** A token used for dependency declaration */
    val token: FlagToken
        get() = FlagToken(FLAG_NAME, isEnabled)

    /** Is the refactor enabled */
    @JvmStatic
    inline val isEnabled
        get() = Flags.notificationsRedesignFooterView()

    /**
     * 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, FLAG_NAME)

    /**
     * Called to ensure code is only run when the flag is enabled. 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, FLAG_NAME)

    /**
     * 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, FLAG_NAME)
}
+16 −4
Original line number Diff line number Diff line
@@ -40,10 +40,10 @@ import android.widget.TextView;
import androidx.annotation.NonNull;

import com.android.settingslib.Utils;
import com.android.systemui.Flags;
import com.android.systemui.res.R;
import com.android.systemui.statusbar.notification.ColorUpdateLogger;
import com.android.systemui.statusbar.notification.footer.shared.FooterViewRefactor;
import com.android.systemui.statusbar.notification.footer.shared.NotifRedesignFooter;
import com.android.systemui.statusbar.notification.row.FooterViewButton;
import com.android.systemui.statusbar.notification.row.StackScrollerDecorView;
import com.android.systemui.statusbar.notification.stack.AnimationProperties;
@@ -109,6 +109,7 @@ public class FooterView extends StackScrollerDecorView {

    /** Set the visibility of the "Manage"/"History" button to {@code visible}. */
    public void setManageOrHistoryButtonVisible(boolean visible) {
        NotifRedesignFooter.assertInLegacyMode();
        mManageOrHistoryButton.setVisibility(visible ? View.VISIBLE : View.GONE);
    }

@@ -187,6 +188,7 @@ public class FooterView extends StackScrollerDecorView {

    /** Set the text label for the "Manage"/"History" button. */
    public void setManageOrHistoryButtonText(@StringRes int textId) {
        NotifRedesignFooter.assertInLegacyMode();
        if (FooterViewRefactor.isUnexpectedlyInLegacyMode()) return;
        if (mManageOrHistoryButtonTextId == textId) {
            return; // nothing changed
@@ -196,6 +198,7 @@ public class FooterView extends StackScrollerDecorView {
    }

    private void updateManageOrHistoryButtonText() {
        NotifRedesignFooter.assertInLegacyMode();
        if (mManageOrHistoryButtonTextId == 0) {
            return; // not initialized yet
        }
@@ -204,6 +207,7 @@ public class FooterView extends StackScrollerDecorView {

    /** Set the accessibility content description for the "Clear all" button. */
    public void setManageOrHistoryButtonDescription(@StringRes int contentDescriptionId) {
        NotifRedesignFooter.assertInLegacyMode();
        if (FooterViewRefactor.isUnexpectedlyInLegacyMode()) {
            return;
        }
@@ -215,6 +219,7 @@ public class FooterView extends StackScrollerDecorView {
    }

    private void updateManageOrHistoryButtonDescription() {
        NotifRedesignFooter.assertInLegacyMode();
        if (mManageOrHistoryButtonDescriptionId == 0) {
            return; // not initialized yet
        }
@@ -273,7 +278,7 @@ public class FooterView extends StackScrollerDecorView {
        }
        super.onFinishInflate();
        mClearAllButton = (FooterViewButton) findSecondaryView();
        if (Flags.notificationsRedesignFooterView()) {
        if (NotifRedesignFooter.isEnabled()) {
            mSettingsButton = findViewById(R.id.settings_button);
            mHistoryButton = findViewById(R.id.history_button);
        } else {
@@ -311,11 +316,17 @@ public class FooterView extends StackScrollerDecorView {

    /** Set onClickListener for the notification settings button. */
    public void setSettingsButtonClickListener(OnClickListener listener) {
        if (NotifRedesignFooter.isUnexpectedlyInLegacyMode()) {
            return;
        }
        mSettingsButton.setOnClickListener(listener);
    }

    /** Set onClickListener for the notification history button. */
    public void setHistoryButtonClickListener(OnClickListener listener) {
        if (NotifRedesignFooter.isUnexpectedlyInLegacyMode()) {
            return;
        }
        mHistoryButton.setOnClickListener(listener);
    }

@@ -324,6 +335,7 @@ public class FooterView extends StackScrollerDecorView {
     * in the redesign.
     */
    public void setManageButtonClickListener(OnClickListener listener) {
        NotifRedesignFooter.assertInLegacyMode();
        mManageOrHistoryButton.setOnClickListener(listener);
    }

@@ -364,7 +376,7 @@ public class FooterView extends StackScrollerDecorView {
            updateClearAllButtonText();
            updateClearAllButtonDescription();

            if (!Flags.notificationsRedesignFooterView()) {
            if (!NotifRedesignFooter.isEnabled()) {
                updateManageOrHistoryButtonText();
                updateManageOrHistoryButtonDescription();
            }
@@ -444,7 +456,7 @@ public class FooterView extends StackScrollerDecorView {
        }
        mClearAllButton.setBackground(clearAllBg);
        mClearAllButton.setTextColor(onSurface);
        if (Flags.notificationsRedesignFooterView()) {
        if (NotifRedesignFooter.isEnabled()) {
            mSettingsButton.setBackground(manageBg);
            mSettingsButton.setCompoundDrawableTintList(ColorStateList.valueOf(onSurface));

+2 −2
Original line number Diff line number Diff line
@@ -20,11 +20,11 @@ import android.view.View
import androidx.lifecycle.lifecycleScope
import com.android.app.tracing.coroutines.launchTraced as launch
import com.android.internal.jank.InteractionJankMonitor
import com.android.systemui.Flags
import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.statusbar.notification.NotificationActivityStarter
import com.android.systemui.statusbar.notification.NotificationActivityStarter.SettingsIntent
import com.android.systemui.statusbar.notification.emptyshade.shared.ModesEmptyShadeFix
import com.android.systemui.statusbar.notification.footer.shared.NotifRedesignFooter
import com.android.systemui.statusbar.notification.footer.ui.view.FooterView
import com.android.systemui.statusbar.notification.footer.ui.viewmodel.FooterViewModel
import com.android.systemui.util.ui.isAnimating
@@ -66,7 +66,7 @@ object FooterViewBinder {
        notificationActivityStarter: NotificationActivityStarter,
    ) = coroutineScope {
        launch { bindClearAllButton(footer, viewModel, clearAllNotifications) }
        if (!Flags.notificationsRedesignFooterView()) {
        if (!NotifRedesignFooter.isEnabled) {
            launch {
                bindManageOrHistoryButton(
                    footer,
+2 −2
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import androidx.lifecycle.lifecycleScope
import com.android.app.tracing.TraceUtils.traceAsync
import com.android.internal.logging.MetricsLogger
import com.android.internal.logging.nano.MetricsProto
import com.android.systemui.Flags
import com.android.systemui.common.ui.ConfigurationState
import com.android.systemui.common.ui.view.setImportantForAccessibilityYesNo
import com.android.systemui.dagger.qualifiers.Background
@@ -40,6 +39,7 @@ import com.android.systemui.statusbar.notification.emptyshade.ui.view.EmptyShade
import com.android.systemui.statusbar.notification.emptyshade.ui.viewbinder.EmptyShadeViewBinder
import com.android.systemui.statusbar.notification.emptyshade.ui.viewmodel.EmptyShadeViewModel
import com.android.systemui.statusbar.notification.footer.shared.FooterViewRefactor
import com.android.systemui.statusbar.notification.footer.shared.NotifRedesignFooter
import com.android.systemui.statusbar.notification.footer.ui.view.FooterView
import com.android.systemui.statusbar.notification.footer.ui.viewbinder.FooterViewBinder
import com.android.systemui.statusbar.notification.footer.ui.viewmodel.FooterViewModel
@@ -146,7 +146,7 @@ constructor(
            // The footer needs to be re-inflated every time the theme or the font size changes.
            configuration
                .inflateLayout<FooterView>(
                    if (Flags.notificationsRedesignFooterView())
                    if (NotifRedesignFooter.isEnabled)
                        R.layout.status_bar_notification_footer_redesign
                    else R.layout.status_bar_notification_footer,
                    parentView,