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

Commit 2f59a1fd authored by Ibrahim Yilmaz's avatar Ibrahim Yilmaz
Browse files

[Inline Reply] Use Pinned info separately for expanded check

Bug: 373279035
Test: atest StatusBarRemoteInputCallbackTest
atest ExpandableNotificationRowTest.java
manual: Receive a HUN with WA and reply using inline reply feature. Let this HUN dismiss. Receive again a HUN from WA from same sender for same chat and reply.

Flag: com.android.systemui.expand_heads_up_on_inline_reply
Change-Id: I232cca6ec8c405fd497608dc10cad2bb0b34708b
parent aac44eb3
Loading
Loading
Loading
Loading
+56 −0
Original line number Diff line number Diff line
@@ -261,6 +261,7 @@ public class StatusBarRemoteInputCallbackTest extends SysuiTestCase {
        when(enr.getPrivateLayout()).thenReturn(privateLayout);
        when(enr.getEntry()).thenReturn(enrEntry);
        when(enr.isChildInGroup()).thenReturn(false);
        when(enr.isPinned()).thenReturn(false);
        when(enr.isExpanded()).thenReturn(false);

        // WHEN
@@ -287,6 +288,7 @@ public class StatusBarRemoteInputCallbackTest extends SysuiTestCase {
        when(enr.getPrivateLayout()).thenReturn(privateLayout);
        when(enr.getEntry()).thenReturn(enrEntry);
        when(enr.isChildInGroup()).thenReturn(false);
        when(enr.isPinned()).thenReturn(false);
        when(enr.isExpanded()).thenReturn(true);

        // WHEN
@@ -299,4 +301,58 @@ public class StatusBarRemoteInputCallbackTest extends SysuiTestCase {
        verify(enr, never()).setUserExpanded(anyBoolean());
        verify(mGroupExpansionManager, never()).toggleGroupExpansion(any());
    }

    @Test
    @EnableFlags(ExpandHeadsUpOnInlineReply.FLAG_NAME)
    public void onMakeExpandedVisibleForRemoteInput_notExpandedPinnedHUN_toggleExpansion() {
        // GIVEN
        final Runnable onExpandedVisibleRunner = mock(Runnable.class);

        final ExpandableNotificationRow enr = mock(ExpandableNotificationRow.class);
        final NotificationContentView privateLayout = mock(NotificationContentView.class);
        final NotificationEntry enrEntry = mock(NotificationEntry.class);

        when(enr.getPrivateLayout()).thenReturn(privateLayout);
        when(enr.getEntry()).thenReturn(enrEntry);
        when(enr.isChildInGroup()).thenReturn(false);
        when(enr.isPinned()).thenReturn(true);
        when(enr.isPinnedAndExpanded()).thenReturn(false);

        // WHEN
        mRemoteInputCallback.onMakeExpandedVisibleForRemoteInput(
                enr, mock(View.class), false, onExpandedVisibleRunner);

        // THEN
        verify(enr).toggleExpansionState();
        verify(privateLayout).setOnExpandedVisibleListener(onExpandedVisibleRunner);
        verify(enr, never()).setUserExpanded(anyBoolean());
        verify(mGroupExpansionManager, never()).toggleGroupExpansion(any());
    }

    @Test
    @EnableFlags(ExpandHeadsUpOnInlineReply.FLAG_NAME)
    public void onMakeExpandedVisibleForRemoteInput_expandedPinnedHUN_notToggleExpansion() {
        // GIVEN
        final Runnable onExpandedVisibleRunner = mock(Runnable.class);

        final ExpandableNotificationRow enr = mock(ExpandableNotificationRow.class);
        final NotificationContentView privateLayout = mock(NotificationContentView.class);
        final NotificationEntry enrEntry = mock(NotificationEntry.class);

        when(enr.getPrivateLayout()).thenReturn(privateLayout);
        when(enr.getEntry()).thenReturn(enrEntry);
        when(enr.isChildInGroup()).thenReturn(false);
        when(enr.isPinned()).thenReturn(true);
        when(enr.isPinnedAndExpanded()).thenReturn(true);

        // WHEN
        mRemoteInputCallback.onMakeExpandedVisibleForRemoteInput(
                enr, mock(View.class), false, onExpandedVisibleRunner);

        // THEN
        verify(enr, never()).toggleExpansionState();
        verify(privateLayout, never()).setOnExpandedVisibleListener(onExpandedVisibleRunner);
        verify(enr, never()).setUserExpanded(anyBoolean());
        verify(mGroupExpansionManager, never()).toggleGroupExpansion(any());
    }
}
+2 −11
Original line number Diff line number Diff line
@@ -116,7 +116,6 @@ import com.android.systemui.statusbar.notification.stack.NotificationChildrenCon
import com.android.systemui.statusbar.notification.stack.NotificationChildrenContainerLogger;
import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
import com.android.systemui.statusbar.notification.stack.SwipeableView;
import com.android.systemui.statusbar.phone.ExpandHeadsUpOnInlineReply;
import com.android.systemui.statusbar.phone.KeyguardBypassController;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.statusbar.policy.InflatedSmartReplyState;
@@ -2948,18 +2947,10 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    }

    public boolean isExpanded(boolean allowOnKeyguard) {
        final boolean isHeadsUpState = ExpandHeadsUpOnInlineReply.isEnabled()
                && canShowHeadsUp() && isHeadsUpState();
        // System expanded should be ignored in pinned heads up state
        final boolean isPinned = isHeadsUpState && isPinned();
        // Heads Up Notification can be expanded when it is pinned.
        final boolean isPinnedAndExpanded =
                isHeadsUpState && isPinnedAndExpanded();

        return (!shouldShowPublic()) && (!mOnKeyguard || allowOnKeyguard)
                && (!hasUserChangedExpansion() && !isPinned
                && (!hasUserChangedExpansion()
                && (isSystemExpanded() || isSystemChildExpanded())
                || isUserExpanded() || isPinnedAndExpanded);
                || isUserExpanded());
    }

    private boolean isSystemChildExpanded() {
+13 −4
Original line number Diff line number Diff line
@@ -216,11 +216,20 @@ public class StatusBarRemoteInputCallback implements Callback, Callbacks,
                if (row.isChildInGroup() && !row.areChildrenExpanded()) {
                    // The group isn't expanded, let's make sure it's visible!
                    mGroupExpansionManager.toggleGroupExpansion(row.getEntry());
                } else if (!row.isChildInGroup() && !row.isExpanded()) {
                    // notification isn't expanded, let's make sure it's visible!
                } else if (!row.isChildInGroup()) {
                    final boolean expandNotification;
                    if (row.isPinned()) {
                        expandNotification = !row.isPinnedAndExpanded();
                    } else {
                        expandNotification = !row.isExpanded();
                    }

                    if (expandNotification) {
                        // notification isn't expanded, let's make sure it's expanded!
                        row.toggleExpansionState();
                        row.getPrivateLayout().setOnExpandedVisibleListener(runnable);
                    }
                }
            } else {
                if (row.isChildInGroup() && !row.areChildrenExpanded()) {
                    // The group isn't expanded, let's make sure it's visible!
+0 −144
Original line number Diff line number Diff line
@@ -71,7 +71,6 @@ import com.android.systemui.statusbar.notification.row.ExpandableView.OnHeightCh
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.ExpandHeadsUpOnInlineReply;
import com.android.systemui.statusbar.phone.KeyguardBypassController;

import org.junit.Assert;
@@ -862,149 +861,6 @@ public class ExpandableNotificationRowTest extends SysuiTestCase {
        assertThat(row.isExpanded()).isFalse();
    }

    @Test
    @EnableFlags(ExpandHeadsUpOnInlineReply.FLAG_NAME)
    public void isExpanded_HUNsystemExpandedTrueForPinned_notExpanded() throws Exception {
        // GIVEN
        final ExpandableNotificationRow row = mNotificationTestHelper.createRow();
        row.setOnKeyguard(false);
        row.setSystemExpanded(true);
        row.setPinned(true);
        row.setHeadsUp(true);

        // THEN
        assertThat(row.isExpanded()).isFalse();
    }

    @Test
    @EnableFlags(ExpandHeadsUpOnInlineReply.FLAG_NAME)
    public void isExpanded_HUNsystemExpandedTrueForNotPinned_expanded() throws Exception {
        // GIVEN
        final ExpandableNotificationRow row = mNotificationTestHelper.createRow();
        row.setOnKeyguard(false);
        row.setSystemExpanded(true);
        row.setPinned(false);
        row.setHeadsUp(true);

        // THEN
        assertThat(row.isExpanded()).isTrue();
    }

    @Test
    @EnableFlags(ExpandHeadsUpOnInlineReply.FLAG_NAME)
    public void isExpanded_HUNDisappearingsystemExpandedTrueForPinned_notExpanded()
            throws Exception {
        // GIVEN
        final ExpandableNotificationRow row = mNotificationTestHelper.createRow();
        row.setOnKeyguard(false);
        row.setSystemExpanded(true);
        row.setPinned(true);
        row.setHeadsUpAnimatingAway(true);

        // THEN
        assertThat(row.isExpanded()).isFalse();
    }

    @Test
    @EnableFlags(ExpandHeadsUpOnInlineReply.FLAG_NAME)
    public void isExpanded_HUNDisappearingsystemExpandedTrueForNotPinned_expanded()
            throws Exception {
        // GIVEN
        final ExpandableNotificationRow row = mNotificationTestHelper.createRow();
        row.setOnKeyguard(false);
        row.setSystemExpanded(true);
        row.setPinned(false);
        row.setHeadsUpAnimatingAway(true);

        // THEN
        assertThat(row.isExpanded()).isTrue();
    }

    @Test
    @EnableFlags(ExpandHeadsUpOnInlineReply.FLAG_NAME)
    public void isExpanded_userExpandedTrueForHeadsUp_expanded() throws Exception {
        // GIVEN
        final ExpandableNotificationRow row = mNotificationTestHelper.createRow();
        row.setOnKeyguard(false);
        row.setSystemExpanded(true);
        row.setHeadsUpAnimatingAway(true);
        row.setUserExpanded(true);

        // THEN
        assertThat(row.isExpanded()).isTrue();
    }
    @Test
    @EnableFlags(ExpandHeadsUpOnInlineReply.FLAG_NAME)
    public void isExpanded_userExpandedTrueForHeadsUpDisappearRunning_expanded() throws Exception {
        // GIVEN
        final ExpandableNotificationRow row = mNotificationTestHelper.createRow();
        row.setOnKeyguard(false);
        row.setSystemExpanded(true);
        row.setHeadsUpAnimatingAway(true);
        row.setUserExpanded(true);

        // THEN
        assertThat(row.isExpanded()).isTrue();
    }

    @Test
    @EnableFlags(ExpandHeadsUpOnInlineReply.FLAG_NAME)
    public void isExpanded_userExpandedFalseForHeadsUp_notExpanded() throws Exception {
        // GIVEN
        final ExpandableNotificationRow row = mNotificationTestHelper.createRow();
        row.setOnKeyguard(false);
        row.setSystemExpanded(true);
        row.setHeadsUpAnimatingAway(true);
        row.setUserExpanded(false);

        // THEN
        assertThat(row.isExpanded()).isFalse();
    }
    @Test
    @EnableFlags(ExpandHeadsUpOnInlineReply.FLAG_NAME)
    public void isExpanded_userExpandedFalseForHeadsUpDisappearRunning_notExpanded()
            throws Exception {
        // GIVEN
        final ExpandableNotificationRow row = mNotificationTestHelper.createRow();
        row.setOnKeyguard(false);
        row.setSystemExpanded(true);
        row.setHeadsUpAnimatingAway(true);
        row.setUserExpanded(false);

        // THEN
        assertThat(row.isExpanded()).isFalse();
    }

    @Test
    @EnableFlags(ExpandHeadsUpOnInlineReply.FLAG_NAME)
    public void isExpanded_HUNexpandedWhenPinningTrue_expanded() throws Exception {
        // GIVEN
        final ExpandableNotificationRow row = mNotificationTestHelper.createRow();
        row.setOnKeyguard(false);
        row.setSystemExpanded(true);
        row.setHeadsUp(true);
        row.setPinned(true);

        // WHEN
        row.expandNotification();

        // THEN
        assertThat(row.isExpanded()).isTrue();
    }

    @Test
    @EnableFlags(ExpandHeadsUpOnInlineReply.FLAG_NAME)
    public void isExpanded_HUNexpandedWhenPinningFalse_notExpanded() throws Exception {
        // GIVEN
        final ExpandableNotificationRow row = mNotificationTestHelper.createRow();
        row.setOnKeyguard(false);
        row.setSystemExpanded(false);
        row.setHeadsUp(true);
        row.setPinned(true);

        // THEN
        assertThat(row.isExpanded()).isFalse();
    }
    @Test
    public void onDisappearAnimationFinished_shouldSetFalse_headsUpAnimatingAway()
            throws Exception {