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

Commit f999fded authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

[Notif redesign] Adjust setSensitive behavior

The height of the sensitive row is no longer different from the height
of the normal collapsed row, so onHeightChange is correctly not being
called anymore.

However, the layout should still be updated even if the height hasn't
changed.

Bug: 396421144
Test: ExpandableNotificationRowTest
Flag: TEST_ONLY
Change-Id: Ie5869fc709940af70b7a6d86d948341248927517
parent 7cf697d9
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -3187,12 +3187,20 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    }

    public void setSensitive(boolean sensitive, boolean hideSensitive) {
        if (notificationsRedesignTemplates()
                && sensitive == mSensitive && hideSensitive == mSensitiveHiddenInGeneral) {
            return; // nothing has changed
        }

        int intrinsicBefore = getIntrinsicHeight();
        mSensitive = sensitive;
        mSensitiveHiddenInGeneral = hideSensitive;
        int intrinsicAfter = getIntrinsicHeight();
        if (intrinsicBefore != intrinsicAfter) {
            notifyHeightChanged(/* needsAnimation= */ true);
        } else if (notificationsRedesignTemplates()) {
            // Just request the correct layout, even if the height hasn't changed
            getShowingLayout().requestSelectLayout(/* needsAnimation= */ true);
        }
    }

+51 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.statusbar.notification.row;

import static android.app.Flags.FLAG_NOTIFICATIONS_REDESIGN_TEMPLATES;

import static com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_ALL;
import static com.android.systemui.statusbar.notification.row.NotificationTestHelper.PKG;
import static com.android.systemui.statusbar.notification.row.NotificationTestHelper.USER_HANDLE;
@@ -29,6 +31,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
@@ -189,6 +192,54 @@ public class ExpandableNotificationRowTest extends SysuiTestCase {
    }

    @Test
    @EnableFlags(FLAG_NOTIFICATIONS_REDESIGN_TEMPLATES)
    public void setSensitive_doesNothingIfCalledAgain() throws Exception {
        ExpandableNotificationRow row = mNotificationTestHelper.createRow();
        measureAndLayout(row);

        // GIVEN a mocked public layout
        NotificationContentView mockPublicLayout = mock(NotificationContentView.class);
        row.setPublicLayout(mockPublicLayout);

        // GIVEN a sensitive notification row that's currently redacted
        row.setHideSensitiveForIntrinsicHeight(true);
        row.setSensitive(true, true);
        assertThat(row.getShowingLayout()).isSameInstanceAs(row.getPublicLayout());
        verify(mockPublicLayout).requestSelectLayout(eq(true));
        clearInvocations(mockPublicLayout);

        // WHEN the row is set to the same sensitive settings
        row.setSensitive(true, true);

        // VERIFY that the layout is not updated again
        assertThat(row.getShowingLayout()).isSameInstanceAs(row.getPublicLayout());
        verify(mockPublicLayout, never()).requestSelectLayout(anyBoolean());
    }

    @Test
    @EnableFlags(FLAG_NOTIFICATIONS_REDESIGN_TEMPLATES)
    public void testSetSensitiveOnNotifRowUpdatesLayout() throws Exception {
        // GIVEN a sensitive notification row that's currently redacted
        ExpandableNotificationRow row = mNotificationTestHelper.createRow();
        measureAndLayout(row);
        row.setHideSensitiveForIntrinsicHeight(true);
        row.setSensitive(true, true);
        assertThat(row.getShowingLayout()).isSameInstanceAs(row.getPublicLayout());

        // GIVEN a mocked private layout
        NotificationContentView mockPrivateLayout = mock(NotificationContentView.class);
        row.setPrivateLayout(mockPrivateLayout);

        // WHEN the row is set to no longer be sensitive
        row.setSensitive(false, true);

        // VERIFY that the layout is updated
        assertThat(row.getShowingLayout()).isSameInstanceAs(row.getPrivateLayout());
        verify(mockPrivateLayout).requestSelectLayout(eq(true));
    }

    @Test
    @DisableFlags(FLAG_NOTIFICATIONS_REDESIGN_TEMPLATES)
    public void testSetSensitiveOnNotifRowNotifiesOfHeightChange() throws Exception {
        // GIVEN a sensitive notification row that's currently redacted
        ExpandableNotificationRow row = mNotificationTestHelper.createRow();