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

Commit 60c941a8 authored by Selim Cinek's avatar Selim Cinek
Browse files

Revert "Make mPendingNotifications truly private"

Fixes: 120942531
This reverts commit 294d0a21.

Reason for revert: <INSERT REASONING HERE>

Change-Id: I31e3fb8ee90635e14ec11104ec35d12983663ea7
parent 294d0a21
Loading
Loading
Loading
Loading
+0 −41
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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;

/**
 * Listener interface for when NotificationEntryManager needs to tell
 * NotificationGroupAlertTransferHelper things. Will eventually grow to be a general-purpose
 * listening interface for the NotificationEntryManager.
 */
public interface AlertTransferListener {
    /**
     * Called when a new notification is posted. At this point, the notification is "pending": its
     * views haven't been inflated yet and most of the system pretends like it doesn't exist yet.
     */
    void onPendingEntryAdded(NotificationData.Entry entry);

    /**
     * Called when an existing notification's views are reinflated (usually due to an update being
     * posted to that notification).
     */
    void onEntryReinflated(NotificationData.Entry entry);

    /**
     * Called when a notification has been removed (either because the user swiped it away or
     * because the developer retracted it).
     */
    void onEntryRemoved(NotificationData.Entry entry);
}
+13 −23
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ import com.android.systemui.Dependency;
import com.android.systemui.Dumpable;
import com.android.systemui.EventLogTags;
import com.android.systemui.ForegroundServiceController;
import com.android.systemui.InitController;
import com.android.systemui.R;
import com.android.systemui.UiOffloadThread;
import com.android.systemui.bubbles.BubbleController;
@@ -82,6 +83,7 @@ import com.android.systemui.statusbar.notification.row.NotificationInflater;
import com.android.systemui.statusbar.notification.row.NotificationInflater.InflationFlag;
import com.android.systemui.statusbar.notification.row.RowInflaterTask;
import com.android.systemui.statusbar.notification.stack.NotificationListContainer;
import com.android.systemui.statusbar.phone.NotificationGroupAlertTransferHelper;
import com.android.systemui.statusbar.phone.NotificationGroupManager;
import com.android.systemui.statusbar.phone.ShadeController;
import com.android.systemui.statusbar.phone.StatusBar;
@@ -115,6 +117,8 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.

    private final NotificationGroupManager mGroupManager =
            Dependency.get(NotificationGroupManager.class);
    private final NotificationGroupAlertTransferHelper mGroupAlertTransferHelper =
            Dependency.get(NotificationGroupAlertTransferHelper.class);
    private final NotificationGutsManager mGutsManager =
            Dependency.get(NotificationGutsManager.class);
    private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);
@@ -153,7 +157,6 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.
            = new ArrayList<>();
    private ExpandableNotificationRow.OnAppOpsClickListener mOnAppOpsClickListener;
    private NotificationViewHierarchyManager.StatusBarStateListener mStatusBarStateListener;
    @Nullable private AlertTransferListener mAlertTransferListener;

    private final class NotificationClicker implements View.OnClickListener {

@@ -255,10 +258,12 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.
        mMessagingUtil = new NotificationMessagingUtil(context);
        mBubbleController.setDismissListener(this /* bubbleEventListener */);
        mNotificationData = new NotificationData();
        Dependency.get(InitController.class).addPostInitTask(this::onPostInit);
    }

    public void setAlertTransferListener(AlertTransferListener listener) {
        mAlertTransferListener = listener;
    private void onPostInit() {
        mGroupAlertTransferHelper.setPendingEntries(mPendingNotifications);
        mGroupManager.addOnGroupChangeListener(mGroupAlertTransferHelper);
    }

    /**
@@ -582,9 +587,7 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.
                    mVisualStabilityManager.onLowPriorityUpdated(entry);
                    mPresenter.updateNotificationViews();
                }
                if (mAlertTransferListener != null) {
                    mAlertTransferListener.onEntryReinflated(entry);
                }
                mGroupAlertTransferHelper.onInflationFinished(entry);
            }
        }
        entry.setLowPriorityStateUpdated(false);
@@ -597,12 +600,8 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.

    private void removeNotificationInternal(String key,
            @Nullable NotificationListenerService.RankingMap ranking, boolean forceRemove) {
        final NotificationData.Entry entry = mNotificationData.get(key);

        abortExistingInflation(key);
        if (mAlertTransferListener != null) {
            mAlertTransferListener.onEntryRemoved(entry);
        }
        mGroupAlertTransferHelper.cleanUpPendingAlertInfo(key);

        // Attempt to remove notifications from their alert managers (heads up, ambient pulse).
        // Though the remove itself may fail, it lets the manager know to remove as soon as
@@ -621,6 +620,8 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.
            mAmbientPulseManager.removeNotification(key, false /* ignoreEarliestRemovalTime */);
        }

        NotificationData.Entry entry = mNotificationData.get(key);

        if (entry == null) {
            mCallback.onNotificationRemoved(key, null /* old */);
            return;
@@ -845,9 +846,7 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.
                mNotificationData.getImportance(key));

        mPendingNotifications.put(key, shadeEntry);
        if (mAlertTransferListener != null) {
            mAlertTransferListener.onPendingEntryAdded(shadeEntry);
        }
        mGroupAlertTransferHelper.onPendingEntryAdded(shadeEntry);
    }

    @VisibleForTesting
@@ -1231,15 +1230,6 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.
        }
    }

    /**
     * @return An iterator for all "pending" notifications. Pending notifications are newly-posted
     * notifications whose views have not yet been inflated. In general, the system pretends like
     * these don't exist, although there are a couple exceptions.
     */
    public Iterable<NotificationData.Entry> getPendingNotificationsIterator() {
        return mPendingNotifications.values();
    }

    /**
     * Callback for NotificationEntryManager.
     */
+90 −91
Original line number Diff line number Diff line
@@ -29,9 +29,7 @@ import com.android.systemui.statusbar.AmbientPulseManager.OnAmbientChangedListen
import com.android.systemui.statusbar.InflationTask;
import com.android.systemui.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.StatusBarStateController.StateListener;
import com.android.systemui.statusbar.notification.AlertTransferListener;
import com.android.systemui.statusbar.notification.NotificationData.Entry;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.row.NotificationInflater.AsyncInflationTask;
import com.android.systemui.statusbar.notification.row.NotificationInflater.InflationFlag;
import com.android.systemui.statusbar.phone.NotificationGroupManager.NotificationGroup;
@@ -40,6 +38,8 @@ import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Objects;

/**
@@ -47,8 +47,8 @@ import java.util.Objects;
 * {@link HeadsUpManager}, {@link AmbientPulseManager}. In particular, this class deals with keeping
 * the correct notification in a group alerting based off the group suppression.
 */
public class NotificationGroupAlertTransferHelper implements OnHeadsUpChangedListener,
        OnAmbientChangedListener, StateListener {
public class NotificationGroupAlertTransferHelper implements OnGroupChangeListener,
        OnHeadsUpChangedListener, OnAmbientChangedListener, StateListener {

    private static final long ALERT_TRANSFER_TIMEOUT = 300;

@@ -69,7 +69,15 @@ public class NotificationGroupAlertTransferHelper implements OnHeadsUpChangedLis
    private final NotificationGroupManager mGroupManager =
            Dependency.get(NotificationGroupManager.class);

    private NotificationEntryManager mEntryManager;
    // TODO(b/119637830): It would be good if GroupManager already had all pending notifications as
    // normal children (i.e. add notifications to GroupManager before inflation) so that we don't
    // have to have this dependency. We'd also have to worry less about the suppression not being up
    // to date.
    /**
     * Notifications that are currently inflating for the first time. Used to remove an incorrectly
     * alerting notification faster.
     */
    private HashMap<String, Entry> mPendingNotifications;

    private boolean mIsDozing;

@@ -77,23 +85,6 @@ public class NotificationGroupAlertTransferHelper implements OnHeadsUpChangedLis
        Dependency.get(StatusBarStateController.class).addCallback(this);
    }

    /** Causes the TransferHelper to register itself as a listener to the appropriate classes. */
    public void bind(NotificationEntryManager entryManager,
            NotificationGroupManager groupManager) {
        if (mEntryManager != null) {
            throw new IllegalStateException("Already bound.");
        }

        // TODO(b/119637830): It would be good if GroupManager already had all pending notifications
        // as normal children (i.e. add notifications to GroupManager before inflation) so that we
        // don't have to have this dependency. We'd also have to worry less about the suppression
        // not being up to date.
        mEntryManager = entryManager;

        mEntryManager.setAlertTransferListener(mAlertTransferListener);
        groupManager.addOnGroupChangeListener(mOnGroupChangeListener);
    }

    /**
     * Whether or not a notification has transferred its alert state to the notification and
     * the notification should alert after inflating.
@@ -106,10 +97,25 @@ public class NotificationGroupAlertTransferHelper implements OnHeadsUpChangedLis
        return alertInfo != null && alertInfo.isStillValid();
    }

    /**
     * Removes any alerts pending on this entry. Note that this will not stop any inflation tasks
     * started by a transfer, so this should only be used as clean-up for when inflation is stopped
     * and the pending alert no longer needs to happen.
     *
     * @param key notification key that may have info that needs to be cleaned up
     */
    public void cleanUpPendingAlertInfo(@NonNull String key) {
        mPendingAlerts.remove(key);
    }

    public void setHeadsUpManager(HeadsUpManager headsUpManager) {
        mHeadsUpManager = headsUpManager;
    }

    public void setPendingEntries(HashMap<String, Entry> pendingNotifications) {
        mPendingNotifications = pendingNotifications;
    }

    @Override
    public void onStateChanged(int newState) {}

@@ -124,7 +130,6 @@ public class NotificationGroupAlertTransferHelper implements OnHeadsUpChangedLis
        mIsDozing = isDozing;
    }

    private final OnGroupChangeListener mOnGroupChangeListener = new OnGroupChangeListener() {
    @Override
    public void onGroupCreated(NotificationGroup group, String groupKey) {
        mGroupAlertEntries.put(groupKey, new GroupAlertEntry(group));
@@ -162,7 +167,6 @@ public class NotificationGroupAlertTransferHelper implements OnHeadsUpChangedLis
            }
        }
    }
    };

    @Override
    public void onAmbientStateChanged(Entry entry, boolean isAmbient) {
@@ -181,42 +185,37 @@ public class NotificationGroupAlertTransferHelper implements OnHeadsUpChangedLis
        }
    }

    private final AlertTransferListener mAlertTransferListener = new AlertTransferListener() {
        // Called when a new notification has been posted but is not inflated yet. We use this to
        // see as early as we can if we need to abort a transfer.
        @Override
        public void onPendingEntryAdded(Entry entry) {
            String groupKey = mGroupManager.getGroupKey(entry.notification);
            GroupAlertEntry groupAlertEntry = mGroupAlertEntries.get(groupKey);
            if (groupAlertEntry != null) {
                checkShouldTransferBack(groupAlertEntry);
            }
        }

        // Called when the entry's reinflation has finished. If there is an alert pending, we
        // then show the alert.
        @Override
        public void onEntryReinflated(Entry entry) {
    /**
     * Called when the entry's reinflation has finished. If there is an alert pending, we then
     * show the alert.
     *
     * @param entry entry whose inflation has finished
     */
    public void onInflationFinished(@NonNull Entry entry) {
        PendingAlertInfo alertInfo = mPendingAlerts.remove(entry.key);
        if (alertInfo != null) {
            if (alertInfo.isStillValid()) {
                alertNotificationWhenPossible(entry, getActiveAlertManager());
            } else {
                // The transfer is no longer valid. Free the content.
                    entry.getRow().freeContentViewWhenSafe(
                            alertInfo.mAlertManager.getContentFlag());
                entry.getRow().freeContentViewWhenSafe(alertInfo.mAlertManager.getContentFlag());
            }
        }
    }

        @Override
        public void onEntryRemoved(Entry entry) {
            // Removes any alerts pending on this entry. Note that this will not stop any inflation
            // tasks started by a transfer, so this should only be used as clean-up for when
            // inflation is stopped and the pending alert no longer needs to happen.
            mPendingAlerts.remove(entry.key);
    /**
     * Called when a new notification has been posted but is not inflated yet. We use this to see
     * as early as we can if we need to abort a transfer.
     *
     * @param entry entry that has been added
     */
    public void onPendingEntryAdded(@NonNull Entry entry) {
        String groupKey = mGroupManager.getGroupKey(entry.notification);
        GroupAlertEntry groupAlertEntry = mGroupAlertEntries.get(groupKey);
        if (groupAlertEntry != null) {
            checkShouldTransferBack(groupAlertEntry);
        }
    }
    };

    /**
     * Gets the number of new notifications pending inflation that will be added to the group
@@ -226,11 +225,11 @@ public class NotificationGroupAlertTransferHelper implements OnHeadsUpChangedLis
     * @return the number of new notifications that will be added to the group
     */
    private int getPendingChildrenNotAlerting(@NonNull NotificationGroup group) {
        if (mEntryManager == null) {
        if (mPendingNotifications == null) {
            return 0;
        }
        int number = 0;
        Iterable<Entry> values = mEntryManager.getPendingNotificationsIterator();
        Collection<Entry> values = mPendingNotifications.values();
        for (Entry entry : values) {
            if (isPendingNotificationInGroup(entry, group) && onlySummaryAlerts(entry)) {
                number++;
@@ -246,10 +245,10 @@ public class NotificationGroupAlertTransferHelper implements OnHeadsUpChangedLis
     * @return true if a pending notification will add to this group
     */
    private boolean pendingInflationsWillAddChildren(@NonNull NotificationGroup group) {
        if (mEntryManager == null) {
        if (mPendingNotifications == null) {
            return false;
        }
        Iterable<Entry> values = mEntryManager.getPendingNotificationsIterator();
        Collection<Entry> values = mPendingNotifications.values();
        for (Entry entry : values) {
            if (isPendingNotificationInGroup(entry, group)) {
                return true;
+0 −2
Original line number Diff line number Diff line
@@ -628,8 +628,6 @@ public class StatusBar extends SystemUI implements DemoMode,
        mBubbleController = Dependency.get(BubbleController.class);
        mBubbleController.setExpandListener(mBubbleExpandListener);

        mGroupAlertTransferHelper.bind(mEntryManager, mGroupManager);

        mColorExtractor.addOnColorsChangedListener(this);
        mStatusBarStateController.addCallback(this, StatusBarStateController.RANK_STATUS_BAR);

+10 −21
Original line number Diff line number Diff line
@@ -32,19 +32,14 @@ import android.testing.TestableLooper;

import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.AmbientPulseManager;
import com.android.systemui.statusbar.notification.AlertTransferListener;
import com.android.systemui.statusbar.notification.NotificationData;
import com.android.systemui.statusbar.notification.NotificationData.Entry;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.policy.HeadsUpManager;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

@@ -54,15 +49,13 @@ import java.util.HashMap;
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
public class NotificationGroupAlertTransferHelperTest extends SysuiTestCase {
    @Rule public MockitoRule rule = MockitoJUnit.rule();
    @Rule
    public MockitoRule rule = MockitoJUnit.rule();

    private NotificationGroupAlertTransferHelper mGroupAlertTransferHelper;
    private NotificationGroupManager mGroupManager;
    private AmbientPulseManager mAmbientPulseManager;
    private HeadsUpManager mHeadsUpManager;
    @Mock private NotificationEntryManager mNotificationEntryManager;
    @Captor private ArgumentCaptor<AlertTransferListener> mListenerCaptor;
    private AlertTransferListener mAlertTransferListener;
    private final HashMap<String, Entry> mPendingEntries = new HashMap<>();
    private final NotificationGroupTestHelper mGroupTestHelper =
            new NotificationGroupTestHelper(mContext);
@@ -74,19 +67,15 @@ public class NotificationGroupAlertTransferHelperTest extends SysuiTestCase {
        mDependency.injectTestDependency(AmbientPulseManager.class, mAmbientPulseManager);
        mHeadsUpManager = new HeadsUpManager(mContext) {};

        when(mNotificationEntryManager.getPendingNotificationsIterator())
                .thenReturn(mPendingEntries.values());

        mGroupManager = new NotificationGroupManager();
        mDependency.injectTestDependency(NotificationGroupManager.class, mGroupManager);
        mGroupManager.setHeadsUpManager(mHeadsUpManager);

        mGroupAlertTransferHelper = new NotificationGroupAlertTransferHelper();
        mGroupAlertTransferHelper.setHeadsUpManager(mHeadsUpManager);
        mGroupAlertTransferHelper.setPendingEntries(mPendingEntries);

        mGroupAlertTransferHelper.bind(mNotificationEntryManager, mGroupManager);
        verify(mNotificationEntryManager).setAlertTransferListener(mListenerCaptor.capture());
        mAlertTransferListener = mListenerCaptor.getValue();
        mGroupManager.addOnGroupChangeListener(mGroupAlertTransferHelper);
        mHeadsUpManager.addListener(mGroupAlertTransferHelper);
        mAmbientPulseManager.addListener(mGroupAlertTransferHelper);
    }
@@ -121,7 +110,7 @@ public class NotificationGroupAlertTransferHelperTest extends SysuiTestCase {

        // Add second child notification so that summary is no longer suppressed.
        mPendingEntries.put(childEntry2.key, childEntry2);
        mAlertTransferListener.onPendingEntryAdded(childEntry2);
        mGroupAlertTransferHelper.onPendingEntryAdded(childEntry2);
        mGroupManager.onEntryAdded(childEntry2);

        // The alert state should transfer back to the summary as there is now more than one
@@ -148,7 +137,7 @@ public class NotificationGroupAlertTransferHelperTest extends SysuiTestCase {

        // Add second child notification so that summary is no longer suppressed.
        mPendingEntries.put(childEntry2.key, childEntry2);
        mAlertTransferListener.onPendingEntryAdded(childEntry2);
        mGroupAlertTransferHelper.onPendingEntryAdded(childEntry2);
        mGroupManager.onEntryAdded(childEntry2);

        // Dozing changed so no reason to re-alert summary.
@@ -186,7 +175,7 @@ public class NotificationGroupAlertTransferHelperTest extends SysuiTestCase {

        when(childEntry.getRow().isInflationFlagSet(mHeadsUpManager.getContentFlag()))
            .thenReturn(true);
        mAlertTransferListener.onEntryReinflated(childEntry);
        mGroupAlertTransferHelper.onInflationFinished(childEntry);

        // Alert is immediately removed from summary, and we show child as its content is inflated.
        assertFalse(mHeadsUpManager.isAlerting(summaryEntry.key));
@@ -210,13 +199,13 @@ public class NotificationGroupAlertTransferHelperTest extends SysuiTestCase {

        // Add second child notification so that summary is no longer suppressed.
        mPendingEntries.put(childEntry2.key, childEntry2);
        mAlertTransferListener.onPendingEntryAdded(childEntry2);
        mGroupAlertTransferHelper.onPendingEntryAdded(childEntry2);
        mGroupManager.onEntryAdded(childEntry2);

        // Child entry finishes its inflation.
        when(childEntry.getRow().isInflationFlagSet(mHeadsUpManager.getContentFlag()))
            .thenReturn(true);
        mAlertTransferListener.onEntryReinflated(childEntry);
        mGroupAlertTransferHelper.onInflationFinished(childEntry);

        verify(childEntry.getRow(), times(1)).freeContentViewWhenSafe(mHeadsUpManager
            .getContentFlag());
@@ -236,7 +225,7 @@ public class NotificationGroupAlertTransferHelperTest extends SysuiTestCase {
        mGroupManager.onEntryAdded(summaryEntry);
        mGroupManager.onEntryAdded(childEntry);

        mAlertTransferListener.onEntryRemoved(childEntry);
        mGroupAlertTransferHelper.cleanUpPendingAlertInfo(childEntry.key);

        assertFalse(mGroupAlertTransferHelper.isAlertTransferPending(childEntry));
    }