From 1d35979f0ada629f192eb1078a29f6eae2c71745 Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Fri, 13 Jan 2017 14:43:43 -0800 Subject: [PATCH] Not allowing foreground services to be cleared as children forground service notifications could simply be cleared when they were sent as notification children and then the summary was cancelled. This also cleans up the logic in systemui and only removes the child if allowed. The clear all button could also show under certain conditions where it shouldn't have been shown. Change-Id: I85998b5342bd75425cc6d68e96391299c4f3d83d Test: manual Bug: 33766648 --- .../systemui/statusbar/NotificationData.java | 14 -------- .../systemui/statusbar/phone/PhoneStatusBar.java | 38 ++++++++++++++++++---- .../notification/NotificationManagerService.java | 3 +- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java index 05a9fc762595..3052bf6a0617 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java @@ -394,20 +394,6 @@ public class NotificationData { return false; } - /** - * Return whether there are any clearable notifications (that aren't errors). - */ - public boolean hasActiveClearableNotifications() { - for (Entry e : mSortedAndFiltered) { - if (e.getContentView() != null) { // the view successfully inflated - if (e.notification.isClearable()) { - return true; - } - } - } - return false; - } - // Q: What kinds of notifications should show during setup? // A: Almost none! Only things coming from the system (package is "android") that also // have special "kind" tags marking them as relevant for setup (see below). diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index 91f3cc9dbfbb..14868a5442d6 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -1196,8 +1196,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, List children = row.getNotificationChildren(); if (row.areChildrenExpanded() && children != null) { for (ExpandableNotificationRow childRow : children) { - if (childRow.getVisibility() == View.VISIBLE) { - viewsToHide.add(childRow); + if (mStackScroller.canChildBeDismissed(childRow)) { + if (childRow.getVisibility() == View.VISIBLE) { + viewsToHide.add(childRow); + } } } } @@ -1682,8 +1684,15 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, } List notificationChildren = entry.row.getNotificationChildren(); - ArrayList toRemove = new ArrayList<>(notificationChildren); - for (int i = 0; i < toRemove.size(); i++) { + ArrayList toRemove = new ArrayList<>(); + for (int i = 0; i < notificationChildren.size(); i++) { + ExpandableNotificationRow row = notificationChildren.get(i); + if ((row.getStatusBarNotification().getNotification().flags + & Notification.FLAG_FOREGROUND_SERVICE) != 0) { + // the child is a forground service notification which we can't remove! + continue; + } + toRemove.add(row); toRemove.get(i).setKeepInParent(true); // we need to set this state earlier as otherwise we might generate some weird // animations @@ -1949,10 +1958,27 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, private void updateClearAll() { boolean showDismissView = mState != StatusBarState.KEYGUARD && - mNotificationData.hasActiveClearableNotifications(); + hasActiveClearableNotifications(); mStackScroller.updateDismissView(showDismissView); } + /** + * Return whether there are any clearable notifications + */ + private boolean hasActiveClearableNotifications() { + int childCount = mStackScroller.getChildCount(); + for (int i = 0; i < childCount; i++) { + View child = mStackScroller.getChildAt(i); + if (!(child instanceof ExpandableNotificationRow)) { + continue; + } + if (((ExpandableNotificationRow) child).canViewBeDismissed()) { + return true; + } + } + return false; + } + private void updateEmptyShadeView() { boolean showEmptyShade = mState != StatusBarState.KEYGUARD && @@ -1999,7 +2025,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, if (SPEW) { final boolean clearable = hasActiveNotifications() && - mNotificationData.hasActiveClearableNotifications(); + hasActiveClearableNotifications(); Log.d(TAG, "setAreThereNotifications: N=" + mNotificationData.getActiveNotifications().size() + " any=" + hasActiveNotifications() + " clearable=" + clearable); diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index b1468f182fd3..4973e17f33bf 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -3576,7 +3576,8 @@ public class NotificationManagerService extends SystemService { NotificationRecord childR = mNotificationList.get(i); StatusBarNotification childSbn = childR.sbn; if ((childSbn.isGroup() && !childSbn.getNotification().isGroupSummary()) && - childR.getGroupKey().equals(r.getGroupKey())) { + childR.getGroupKey().equals(r.getGroupKey()) + && (childR.getFlags() & Notification.FLAG_FOREGROUND_SERVICE) == 0) { EventLogTags.writeNotificationCancel(callingUid, callingPid, pkg, childSbn.getId(), childSbn.getTag(), userId, 0, 0, reason, listenerName); mNotificationList.remove(i); -- 2.11.0