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

Commit 96b3f1bd authored by Tony Mak's avatar Tony Mak
Browse files

Fix expansion change is not reported if the notification is updated

When the notification is updated(reinflated), we should report the
expansion is visibly expanded again even it the notification of
the same key was already reported.

Test: atest ExpansionStateLoggerTest.java
Test: Manual. Send a message to myself. Observe
onNotificationExpansionChange is called. Send another message to update
the notification and go to see the notification. Observe that
onNotificationExpansionChange is called again.

Change-Id: Ie1f245c3954eafade0d81794b4722de6dfbec9dc
parent 92fd2908
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import com.android.systemui.statusbar.StatusBarStateController.StateListener;
import com.android.systemui.statusbar.notification.NotificationEntryListener;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.stack.ExpandableViewState;
import com.android.systemui.statusbar.notification.stack.NotificationListContainer;
import com.android.systemui.statusbar.policy.HeadsUpManager;
@@ -220,6 +219,11 @@ public class NotificationLogger implements StateListener {
                mExpansionStateLogger.onEntryRemoved(entry.key);
            }

            @Override
            public void onEntryReinflated(NotificationEntry entry) {
                mExpansionStateLogger.onEntryReinflated(entry.key);
            }

            @Override
            public void onInflationError(
                    StatusBarNotification notification,
@@ -468,6 +472,13 @@ public class NotificationLogger implements StateListener {
            mLoggedExpansionState.remove(key);
        }

        @VisibleForTesting
        void onEntryReinflated(String key) {
            // When the notification is updated, we should consider the notification as not
            // yet logged.
            mLoggedExpansionState.remove(key);
        }

        private State getState(String key) {
            State state = mExpansionStates.get(key);
            if (state == null) {
+23 −1
Original line number Diff line number Diff line
@@ -15,10 +15,10 @@
 */
package com.android.systemui.statusbar.notification.logging;

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.times;
import static org.mockito.Mockito.verify;

import android.os.RemoteException;
@@ -31,6 +31,7 @@ import com.android.internal.statusbar.NotificationVisibility;
import com.android.systemui.Dependency;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.UiOffloadThread;
import com.android.systemui.statusbar.notification.stack.ExpandableViewState;

import org.junit.Before;
import org.junit.Test;
@@ -155,6 +156,27 @@ public class ExpansionStateLoggerTest extends SysuiTestCase {
                NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN.toMetricsEventEnum());
    }

    @Test
    public void testOnEntryReinflated() throws RemoteException {
        mLogger.onExpansionChanged(NOTIFICATION_KEY, true, true,
                NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN);
        mLogger.onVisibilityChanged(
                Collections.singletonList(createNotificationVisibility(NOTIFICATION_KEY, true)),
                Collections.emptyList());
        waitForUiOffloadThread();
        verify(mBarService).onNotificationExpansionChanged(
                NOTIFICATION_KEY, true, true, ExpandableViewState.LOCATION_UNKNOWN);

        mLogger.onEntryReinflated(NOTIFICATION_KEY);
        mLogger.onVisibilityChanged(
                Collections.singletonList(createNotificationVisibility(NOTIFICATION_KEY, true)),
                Collections.emptyList());
        waitForUiOffloadThread();
        // onNotificationExpansionChanged is called the second time.
        verify(mBarService, times(2)).onNotificationExpansionChanged(
                NOTIFICATION_KEY, true, true, ExpandableViewState.LOCATION_UNKNOWN);
    }

    private NotificationVisibility createNotificationVisibility(String key, boolean visibility) {
        return createNotificationVisibility(key, visibility,
                NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN);