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

Commit 889280c4 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Only foreground notis should be sorted higher

Having the ongoing flag is not enough.

Test: runtest systemui-notification
Change-Id: I8a6c15af819f2bb4ad3937ae45d33361663fbe13
parent 3a543a1b
Loading
Loading
Loading
Loading
+7 −14
Original line number Diff line number Diff line
@@ -21,15 +21,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.os.UserHandle;
import android.provider.Settings;
import android.telecom.TelecomManager;
import android.text.TextUtils;
import android.util.ArrayMap;

import com.android.internal.util.NotificationMessagingUtil;

@@ -56,8 +48,8 @@ public class NotificationComparator
    @Override
    public int compare(NotificationRecord left, NotificationRecord right) {
        // first all colorized notifications
        boolean leftImportantColorized = isImportantColorized(left);
        boolean rightImportantColorized = isImportantColorized(right);
        boolean leftImportantColorized = isImportantOngoingColorized(left);
        boolean rightImportantColorized = isImportantOngoingColorized(right);

        if (leftImportantColorized != rightImportantColorized) {
            return -1 * Boolean.compare(leftImportantColorized, rightImportantColorized);
@@ -118,7 +110,10 @@ public class NotificationComparator
        return -1 * Long.compare(left.getRankingTimeMs(), right.getRankingTimeMs());
    }

    private boolean isImportantColorized(NotificationRecord record) {
    private boolean isImportantOngoingColorized(NotificationRecord record) {
        if (!isOngoing(record)) {
            return false;
        }
        if (record.getImportance() < NotificationManager.IMPORTANCE_LOW) {
            return false;
        }
@@ -133,7 +128,6 @@ public class NotificationComparator
        if (record.getImportance() < NotificationManager.IMPORTANCE_LOW) {
            return false;
        }
        // TODO: add whitelist

        return isCall(record) || isMediaNotification(record);
    }
@@ -153,8 +147,7 @@ public class NotificationComparator
    }

    private boolean isOngoing(NotificationRecord record) {
        final int ongoingFlags =
                Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_ONGOING_EVENT;
        final int ongoingFlags = Notification.FLAG_FOREGROUND_SERVICE;
        return (record.getNotification().flags & ongoingFlags) != 0;
    }

+12 −0
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ public class NotificationComparatorTest {
    private NotificationRecord mRecordContact;
    private NotificationRecord mRecordUrgent;
    private NotificationRecord mRecordCheater;
    private NotificationRecord mRecordCheaterColorized;


    @Before
@@ -174,6 +175,7 @@ public class NotificationComparatorTest {
                pkg2, 1, "cheater", uid2, uid2, n9, new UserHandle(userId),
                "", 9258), getDefaultChannel());
        mRecordCheater.setUserImportance(NotificationManager.IMPORTANCE_LOW);
        mRecordCheater.setPackagePriority(Notification.PRIORITY_MAX);

        Notification n10 = new Notification.Builder(mContext, TEST_CHANNEL_ID)
                .setStyle(new Notification.InboxStyle().setSummaryText("message!")).build();
@@ -181,6 +183,15 @@ public class NotificationComparatorTest {
                pkg2, 1, "email", uid2, uid2, n10, new UserHandle(userId),
                "", 1599), getDefaultChannel());
        mRecordEmail.setUserImportance(NotificationManager.IMPORTANCE_HIGH);

        Notification n11 = new Notification.Builder(mContext, TEST_CHANNEL_ID)
                .setCategory(Notification.CATEGORY_MESSAGE)
                .setColorized(true)
                .build();
        mRecordCheaterColorized = new NotificationRecord(mContext, new StatusBarNotification(pkg2,
                pkg2, 1, "cheater", uid2, uid2, n11, new UserHandle(userId),
                "", 9258), getDefaultChannel());
        mRecordCheaterColorized.setUserImportance(NotificationManager.IMPORTANCE_LOW);
    }

    @Test
@@ -195,6 +206,7 @@ public class NotificationComparatorTest {
        expected.add(mRecordEmail);
        expected.add(mRecordUrgent);
        expected.add(mRecordCheater);
        expected.add(mRecordCheaterColorized);
        expected.add(mRecordMinCall);

        List<NotificationRecord> actual = new ArrayList<>();