Combines NotificationEntryManager listener interfaces (part 5).

This change combines the onEntryRemoved() and
onPerformRemoveNotification() methods on NotificationEntryListener to a
single method.  The latter method was called after the former method in
all cases where the removal of the notification was precipitated by user
action (swipe, bubble swipe, launching content intent), so it's replaced
by a boolean parameter to the former method indicating whether a user
action caused the removal.

Test: atest SystemUITests, manual
Change-Id: I448fdd68984e3c2489259940c4d3432ac5bfe320
This commit is contained in:
Gus Prevas
2018-12-21 11:25:10 -05:00
parent f37435a69b
commit dca2be5f93
7 changed files with 32 additions and 36 deletions

View File

@@ -81,7 +81,8 @@ public class NotificationAlertingManager {
@Override
public void onEntryRemoved(
String key, StatusBarNotification old, boolean lifetimeExtended) {
String key, StatusBarNotification old, boolean lifetimeExtended,
boolean removedByUser) {
stopAlerting(key);
}
});

View File

@@ -59,21 +59,15 @@ public interface NotificationEntryListener {
/**
* Called when a notification has been removed (either because the user swiped it away or
* because the developer retracted it).
*
* @param key key of notification that was removed
* @param key key of notification that was removed
* @param old StatusBarNotification of the notification before it was removed
* @param lifetimeExtended true if something is artificially extending how long the notification
* stays visible after it's removed
* @param removedByUser true if the notification was removed by a user action
*/
default void onEntryRemoved(
String key, StatusBarNotification old, boolean lifetimeExtended) {
}
/**
* Removes a notification immediately.
*
* TODO: combine this with onEntryRemoved().
*/
default void onPerformRemoveNotification(StatusBarNotification statusBarNotification) {
String key,
StatusBarNotification old,
boolean lifetimeExtended,
boolean removedByUser) {
}
}

View File

@@ -246,15 +246,11 @@ public class NotificationEntryManager implements
int dismissalSentiment = NotificationStats.DISMISS_SENTIMENT_NEUTRAL;
mBarService.onNotificationClear(pkg, tag, id, userId, n.getKey(), dismissalSurface,
dismissalSentiment, nv);
removeNotification(n.getKey(), null);
removeNotificationInternal(
n.getKey(), null, false /* forceRemove */, true /* removedByUser */);
} catch (RemoteException ex) {
// system process is dead if we're here.
}
for (NotificationEntryListener listener : mNotificationEntryListeners) {
listener.onPerformRemoveNotification(n);
}
}
@Override
@@ -294,7 +290,8 @@ public class NotificationEntryManager implements
*/
@Override
public void handleInflationException(StatusBarNotification n, Exception e) {
removeNotificationInternal(n.getKey(), null, true /* forceRemove */);
removeNotificationInternal(
n.getKey(), null, true /* forceRemove */, false /* removedByUser */);
try {
mBarService.onNotificationError(n.getPackageName(), n.getTag(), n.getId(), n.getUid(),
n.getInitialPid(), e.getMessage(), n.getUserId());
@@ -355,11 +352,15 @@ public class NotificationEntryManager implements
@Override
public void removeNotification(String key, NotificationListenerService.RankingMap ranking) {
removeNotificationInternal(key, ranking, false /* forceRemove */);
removeNotificationInternal(
key, ranking, false /* forceRemove */, false /* removedByUser */);
}
private void removeNotificationInternal(String key,
@Nullable NotificationListenerService.RankingMap ranking, boolean forceRemove) {
private void removeNotificationInternal(
String key,
@Nullable NotificationListenerService.RankingMap ranking,
boolean forceRemove,
boolean removedByUser) {
final NotificationData.Entry entry = mNotificationData.get(key);
abortExistingInflation(key);
@@ -405,7 +406,7 @@ public class NotificationEntryManager implements
}
for (NotificationEntryListener listener : mNotificationEntryListeners) {
listener.onEntryRemoved(key, old, lifetimeExtended);
listener.onEntryRemoved(key, old, lifetimeExtended, removedByUser);
}
}

View File

@@ -217,7 +217,8 @@ public class NotificationGroupAlertTransferHelper implements OnHeadsUpChangedLis
@Override
public void onEntryRemoved(
String key, StatusBarNotification old, boolean lifetimeExtended) {
String key, StatusBarNotification old, boolean lifetimeExtended,
boolean removedByUser) {
// 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.

View File

@@ -189,16 +189,13 @@ public class StatusBarNotificationPresenter implements NotificationPresenter,
@Override
public void onEntryRemoved(String key, StatusBarNotification old,
boolean lifetimeExtended) {
boolean lifetimeExtended, boolean removedByUser) {
if (!lifetimeExtended) {
StatusBarNotificationPresenter.this.onNotificationRemoved(key, old);
}
}
@Override
public void onPerformRemoveNotification(
StatusBarNotification statusBarNotification) {
StatusBarNotificationPresenter.this.onPerformRemoveNotification();
if (removedByUser) {
maybeEndAmbientPulse();
}
}
};
@@ -260,7 +257,7 @@ public class StatusBarNotificationPresenter implements NotificationPresenter,
|| mActivityLaunchAnimator.isAnimationRunning();
}
private void onPerformRemoveNotification() {
private void maybeEndAmbientPulse() {
if (mNotificationPanel.hasPulsingNotifications() &&
!mAmbientPulseManager.hasNotifications()) {
// We were showing a pulse for a notification, but no notifications are pulsing anymore.

View File

@@ -323,7 +323,8 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
verify(mForegroundServiceController).removeNotification(mSbn);
verify(mListContainer).cleanUpViewStateForEntry(mEntry);
verify(mPresenter).updateNotificationViews();
verify(mEntryListener).onEntryRemoved(mSbn.getKey(), mSbn, false /* lifetimeExtended */);
verify(mEntryListener).onEntryRemoved(mSbn.getKey(), mSbn, false /* lifetimeExtended */,
false /* removedByUser */);
verify(mRow).setRemoved();
assertNull(mEntryManager.getNotificationData().get(mSbn.getKey()));
@@ -347,7 +348,8 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
assertNotNull(mEntryManager.getNotificationData().get(mSbn.getKey()));
verify(extender).setShouldManageLifetime(mEntry, true /* shouldManage */);
verify(mEntryListener).onEntryRemoved(mSbn.getKey(), null, true /* lifetimeExtended */);
verify(mEntryListener).onEntryRemoved(mSbn.getKey(), null, true /* lifetimeExtended */,
false /* removedByUser */);
}
@Test

View File

@@ -237,7 +237,7 @@ public class NotificationGroupAlertTransferHelperTest extends SysuiTestCase {
mGroupManager.onEntryAdded(summaryEntry);
mGroupManager.onEntryAdded(childEntry);
mNotificationEntryListener.onEntryRemoved(childEntry.key, null, false);
mNotificationEntryListener.onEntryRemoved(childEntry.key, null, false, false);
assertFalse(mGroupAlertTransferHelper.isAlertTransferPending(childEntry));
}