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

Commit 7b05f4bb authored by Yining Liu's avatar Yining Liu Committed by Android (Google) Code Review
Browse files

Merge changes I68368ecf,I780273eb into main

* changes:
  Optimize the alpha reset of notification content views
  Add aconfig flag: notification_content_alpha_optimization
parents 19f81ba5 7c34cb44
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -75,6 +75,16 @@ flag {
    bug: "243302608"
}

flag {
    name: "notification_content_alpha_optimization"
    namespace: "systemui"
    description: "Only reset alpha values of needed content views"
    bug: "292024656"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "notifications_live_data_store_refactor"
    namespace: "systemui"
+14 −7
Original line number Diff line number Diff line
@@ -547,19 +547,26 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
    }

    private void setContentAlpha(float contentAlpha) {
        View contentView = getContentView();
        if (contentView.hasOverlappingRendering()) {
            int layerType = contentAlpha == 0.0f || contentAlpha == 1.0f ? LAYER_TYPE_NONE
                    : LAYER_TYPE_HARDWARE;
            contentView.setLayerType(layerType, null);
        }
        contentView.setAlpha(contentAlpha);
        setAlphaAndLayerType(getContentView(), contentAlpha);
        // After updating the current view, reset all views.
        if (contentAlpha == 1f) {
            resetAllContentAlphas();
        }
    }

    /**
     * Set a content view's alpha value and hardware layer type for fluent animations
     * @param contentView the view to set
     * @param alpha the alpha value to set
     */
    protected void setAlphaAndLayerType(View contentView, float alpha) {
        if (contentView.hasOverlappingRendering()) {
            int layerType = alpha == 0.0f || alpha == 1.0f ? LAYER_TYPE_NONE : LAYER_TYPE_HARDWARE;
            contentView.setLayerType(layerType, null);
        }
        contentView.setAlpha(alpha);
    }

    /**
     * If a subclass's {@link #getContentView()} returns different views depending on state,
     * this method is an opportunity to reset the alpha of ALL content views, not just the
+9 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ import com.android.systemui.statusbar.notification.people.PeopleNotificationIden
import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag;
import com.android.systemui.statusbar.notification.row.shared.AsyncGroupHeaderViewInflation;
import com.android.systemui.statusbar.notification.row.wrapper.NotificationViewWrapper;
import com.android.systemui.statusbar.notification.shared.NotificationContentAlphaOptimization;
import com.android.systemui.statusbar.notification.stack.AmbientState;
import com.android.systemui.statusbar.notification.stack.AnimationProperties;
import com.android.systemui.statusbar.notification.stack.ExpandableViewState;
@@ -2918,6 +2919,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) {
            return;
        }
        float oldAlpha = getContentView().getAlpha();

        if (!animated) {
            mPublicLayout.animate().cancel();
@@ -2928,6 +2930,13 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
            resetAllContentAlphas();
            mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE);
            updateChildrenVisibility();
            if (NotificationContentAlphaOptimization.isEnabled()) {
                // We want to set the old alpha to the now-showing layout to avoid breaking an
                // on-going animation
                if (oldAlpha != 1f) {
                    setAlphaAndLayerType(mShowingPublic ? mPublicLayout : mPrivateLayout, oldAlpha);
                }
            }
        } else {
            animateShowingPublic(delay, duration, mShowingPublic);
        }
+53 −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.shared

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

/** Helper for reading or using the Async Group Header Inflation flag state. */
@Suppress("NOTHING_TO_INLINE")
object NotificationContentAlphaOptimization {
    /** The aconfig flag name */
    const val FLAG_NAME = Flags.FLAG_NOTIFICATION_CONTENT_ALPHA_OPTIMIZATION

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

    /** Is the async inflation of group header views enabled */
    @JvmStatic
    inline val isEnabled
        get() = Flags.notificationContentAlphaOptimization()

    /**
     * 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 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)
}
+56 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ import com.android.systemui.statusbar.notification.SourceType;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.row.ExpandableView.OnHeightChangedListener;
import com.android.systemui.statusbar.notification.row.wrapper.NotificationViewWrapper;
import com.android.systemui.statusbar.notification.shared.NotificationContentAlphaOptimization;
import com.android.systemui.statusbar.notification.stack.NotificationChildrenContainer;
import com.android.systemui.statusbar.phone.KeyguardBypassController;

@@ -329,6 +330,61 @@ public class ExpandableNotificationRowTest extends SysuiTestCase {
                + "seems out of sync.", group.getChildrenContainer().isUserLocked());
    }

    @Test
    @EnableFlags(NotificationContentAlphaOptimization.FLAG_NAME)
    public void setHideSensitive_shouldNotDisturbAnimation() throws Exception {
        //Given: A row that is during alpha animation
        ExpandableNotificationRow row = mNotificationTestHelper.createRow();

        assertEquals(row.getPrivateLayout(), row.getContentView());
        row.setContentAlpha(0.5f);

        //When: Set its hideSensitive without changing the content view to show
        row.setHideSensitive(
                /* hideSensitive= */ false,
                /* animated= */ false,
                /* delay=  */ 0L,
                /* duration=  */ 0L
        );
        assertEquals(row.getPrivateLayout(), row.getContentView());

        //Then: The alpha value should not be reset
        assertEquals(0.5f, row.getPrivateLayout().getAlpha(), 0);
    }

    @Test
    @EnableFlags(NotificationContentAlphaOptimization.FLAG_NAME)
    public void setHideSensitive_changeContent_shouldNotDisturbAnimation() throws Exception {

        // Given: A sensitive row that has public version but is not hiding sensitive,
        // and is during an animation that sets its alpha value to be 0.5f
        Notification publicNotif = mNotificationTestHelper.createNotification();
        publicNotif.publicVersion = mNotificationTestHelper.createNotification();
        ExpandableNotificationRow row = mNotificationTestHelper.createRow(publicNotif);
        row.setSensitive(true, false);
        row.setContentAlpha(0.5f);

        assertEquals(0.5f, row.getPrivateLayout().getAlpha(), 0);
        assertEquals(View.VISIBLE, row.getPrivateLayout().getVisibility());

        // When: Change its hideSensitive and changes the content view to show the public version
        row.setHideSensitive(
                /* hideSensitive= */ true,
                /* animated= */ false,
                /* delay=  */ 0L,
                /* duration=  */ 0L
        );

        // Then: The alpha value of private layout should be reset to 1, private layout be
        // INVISIBLE;
        // The alpha value of public layout should be 0.5 to preserve the animation state, public
        // layout should be VISIBLE
        assertEquals(View.INVISIBLE, row.getPrivateLayout().getVisibility());
        assertEquals(1f, row.getPrivateLayout().getAlpha(), 0);
        assertEquals(View.VISIBLE, row.getPublicLayout().getVisibility());
        assertEquals(0.5f, row.getPublicLayout().getAlpha(), 0);
    }

    @Test
    public void testReinflatedOnDensityChange() throws Exception {
        ExpandableNotificationRow row = mNotificationTestHelper.createRow();