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

Commit 9e923e1c authored by Mady Mellor's avatar Mady Mellor
Browse files

NoMan bubbles policy: remove non-communication bubbles when app is foreground

We're no longer allowing any notification to be a bubble if the app is
foreground when the notif was sent; it must always fulfill the communication
policy.

- removed check & FLAG_BUBBLE when app is foreground
- removed the tests for FLAG_BUBBLE on foreground produced bubbles
- added a test to ensure that FLAG_BUBBLE doesn't happen just because the
  app is foreground
- attempted to clean up some of the bubble helper methods

- no foreground service bubbles unless its a phone call (test for this
  in CTS CL)

Test: atest NotificationManagerServiceTest
Test: atest NotificationManagerTest (needs CTS CL)
Bug: 138116133
Bug: 144352570
Change-Id: Idba370c23a3ccaa6479f61a94632f29d623a1e76
parent d9b1ac97
Loading
Loading
Loading
Loading
+11 −19
Original line number Diff line number Diff line
@@ -236,7 +236,6 @@ import com.android.internal.util.ArrayUtils;
import com.android.internal.util.CollectionUtils;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.FastXmlSerializer;
import com.android.internal.util.Preconditions;
import com.android.internal.util.XmlUtils;
import com.android.internal.util.function.TriPredicate;
import com.android.server.DeviceIdleInternal;
@@ -1182,21 +1181,14 @@ public class NotificationManagerService extends SystemService {

        @Override
        public void onNotificationBubbleChanged(String key, boolean isBubble) {
            String pkg;
            synchronized (mNotificationLock) {
                NotificationRecord r = mNotificationsByKey.get(key);
                pkg = r != null && r.sbn != null ? r.sbn.getPackageName() : null;
            }
            boolean isAppForeground = pkg != null
                    && mActivityManager.getPackageImportance(pkg) == IMPORTANCE_FOREGROUND;
            synchronized (mNotificationLock) {
                NotificationRecord r = mNotificationsByKey.get(key);
                if (r != null) {
                    final StatusBarNotification n = r.sbn;
                    final int callingUid = n.getUid();
                    pkg = n.getPackageName();
                    final String pkg = n.getPackageName();
                    if (isBubble && isNotificationAppropriateToBubble(r, pkg, callingUid,
                            null /* oldEntry */, isAppForeground)) {
                            null /* oldEntry */)) {
                        r.getNotification().flags |= FLAG_BUBBLE;
                    } else {
                        r.getNotification().flags &= ~FLAG_BUBBLE;
@@ -5386,7 +5378,7 @@ public class NotificationManagerService extends SystemService {
    private void flagNotificationForBubbles(NotificationRecord r, String pkg, int userId,
            NotificationRecord oldRecord, boolean isAppForeground) {
        Notification notification = r.getNotification();
        if (isNotificationAppropriateToBubble(r, pkg, userId, oldRecord, isAppForeground)) {
        if (isNotificationAppropriateToBubble(r, pkg, userId, oldRecord)) {
            notification.flags |= FLAG_BUBBLE;
        } else {
            notification.flags &= ~FLAG_BUBBLE;
@@ -5406,7 +5398,7 @@ public class NotificationManagerService extends SystemService {
     * accounting for user choice & policy.
     */
    private boolean isNotificationAppropriateToBubble(NotificationRecord r, String pkg, int userId,
            NotificationRecord oldRecord, boolean isAppForeground) {
            NotificationRecord oldRecord) {
        Notification notification = r.getNotification();
        if (!canBubble(r, pkg, userId)) {
            // no log: canBubble has its own
@@ -5418,11 +5410,6 @@ public class NotificationManagerService extends SystemService {
            return false;
        }

        if (isAppForeground) {
            // If the app is foreground it always gets to bubble
            return true;
        }

        if (oldRecord != null && (oldRecord.getNotification().flags & FLAG_BUBBLE) != 0) {
            // This is an update to an active bubble
            return true;
@@ -5438,7 +5425,7 @@ public class NotificationManagerService extends SystemService {
        boolean isMessageStyle = Notification.MessagingStyle.class.equals(
                notification.getNotificationStyle());
        if (!isMessageStyle && (peopleList == null || peopleList.isEmpty())) {
            logBubbleError(r.getKey(), "if not foreground, must have a person and be "
            logBubbleError(r.getKey(), "Must have a person and be "
                    + "Notification.MessageStyle or Notification.CATEGORY_CALL");
            return false;
        }
@@ -5446,6 +5433,11 @@ public class NotificationManagerService extends SystemService {
        // Communication is a message or a call
        boolean isCall = CATEGORY_CALL.equals(notification.category);
        boolean hasForegroundService = (notification.flags & FLAG_FOREGROUND_SERVICE) != 0;
        if (hasForegroundService && !isCall) {
            logBubbleError(r.getKey(),
                    "foreground services must be Notification.CATEGORY_CALL to bubble");
            return false;
        }
        if (isMessageStyle) {
            if (hasValidRemoteInput(notification)) {
                return true;
@@ -5459,7 +5451,7 @@ public class NotificationManagerService extends SystemService {
            logBubbleError(r.getKey(), "calls require foreground service");
            return false;
        }
        logBubbleError(r.getKey(), "if not foreground, must be "
        logBubbleError(r.getKey(), "Must be "
                + "Notification.MessageStyle or Notification.CATEGORY_CALL");
        return false;
    }
+144 −353

File changed.

Preview size limit exceeded, changes collapsed.