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

Commit b8e3b939 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[RONs] Add ranking changes for promoted notifications" into main

parents 91242589 42ed6239
Loading
Loading
Loading
Loading
+64 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.notification.collection.coordinator;

import static android.app.Notification.FLAG_FOREGROUND_SERVICE;
import static android.app.Notification.FLAG_PROMOTED_ONGOING;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_MIN;
@@ -24,12 +25,18 @@ import static android.app.NotificationManager.IMPORTANCE_MIN;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

import android.app.Notification;
import android.app.PendingIntent;
import android.app.Person;
import android.content.Intent;
import android.graphics.Color;
import android.os.UserHandle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.testing.TestableLooper;

import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -38,11 +45,14 @@ import androidx.test.filters.SmallTest;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.notification.collection.NotifPipeline;
import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder;
import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifPromoter;
import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifSectioner;
import com.android.systemui.statusbar.notification.promoted.PromotedNotificationUi;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

@@ -136,6 +146,60 @@ public class ColorizedFgsCoordinatorTest extends SysuiTestCase {
        assertFalse(mFgsSection.isInSection(mEntryBuilder.build()));
    }

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME)
    public void testIncludePromotedOngoingInSection_flagEnabled() {
        // GIVEN the notification has FLAG_PROMOTED_ONGOING
        mEntryBuilder.setFlag(mContext, FLAG_PROMOTED_ONGOING, true);

        // THEN the entry is in the fgs section
        assertTrue(mFgsSection.isInSection(mEntryBuilder.build()));
    }

    @Test
    @DisableFlags(PromotedNotificationUi.FLAG_NAME)
    public void testDiscludePromotedOngoingInSection_flagDisabled() {
        // GIVEN the notification has FLAG_PROMOTED_ONGOING
        mEntryBuilder.setFlag(mContext, FLAG_PROMOTED_ONGOING, true);

        // THEN the entry is NOT in the fgs section
        assertFalse(mFgsSection.isInSection(mEntryBuilder.build()));
    }

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME)
    public void promoterSelectsPromotedOngoing_flagEnabled() {
        ArgumentCaptor<NotifPromoter> captor = ArgumentCaptor.forClass(NotifPromoter.class);
        verify(mNotifPipeline).addPromoter(captor.capture());
        NotifPromoter promoter = captor.getValue();

        // GIVEN the notification has FLAG_PROMOTED_ONGOING
        mEntryBuilder.setFlag(mContext, FLAG_PROMOTED_ONGOING, true);

        // THEN the entry is promoted to top level
        assertTrue(promoter.shouldPromoteToTopLevel(mEntryBuilder.build()));
    }

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME)
    public void promoterIgnoresNonPromotedOngoing_flagEnabled() {
        ArgumentCaptor<NotifPromoter> captor = ArgumentCaptor.forClass(NotifPromoter.class);
        verify(mNotifPipeline).addPromoter(captor.capture());
        NotifPromoter promoter = captor.getValue();

        // GIVEN the notification does not have FLAG_PROMOTED_ONGOING
        mEntryBuilder.setFlag(mContext, FLAG_PROMOTED_ONGOING, false);

        // THEN the entry is NOT promoted to top level
        assertFalse(promoter.shouldPromoteToTopLevel(mEntryBuilder.build()));
    }

    @Test
    @DisableFlags(PromotedNotificationUi.FLAG_NAME)
    public void noPromoterAdded_flagDisabled() {
        verify(mNotifPipeline, never()).addPromoter(any());
    }

    private Notification.CallStyle makeCallStyle() {
        final PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0,
                new Intent("action"), PendingIntent.FLAG_IMMUTABLE);
+42 −1
Original line number Diff line number Diff line
@@ -20,13 +20,21 @@ import static android.app.NotificationManager.IMPORTANCE_MIN;

import android.app.Notification;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.systemui.statusbar.notification.collection.ListEntry;
import com.android.systemui.statusbar.notification.collection.NotifPipeline;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.coordinator.dagger.CoordinatorScope;
import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifComparator;
import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifPromoter;
import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifSectioner;
import com.android.systemui.statusbar.notification.promoted.PromotedNotificationUi;
import com.android.systemui.statusbar.notification.stack.NotificationPriorityBucketKt;

import com.google.common.primitives.Booleans;

import javax.inject.Inject;

/**
@@ -44,12 +52,21 @@ public class ColorizedFgsCoordinator implements Coordinator {

    @Override
    public void attach(NotifPipeline pipeline) {
        if (PromotedNotificationUi.isEnabled()) {
            pipeline.addPromoter(mPromotedOngoingPromoter);
        }
    }

    public NotifSectioner getSectioner() {
        return mNotifSectioner;
    }

    private final NotifPromoter mPromotedOngoingPromoter = new NotifPromoter("PromotedOngoing") {
        @Override
        public boolean shouldPromoteToTopLevel(NotificationEntry child) {
            return isPromotedOngoing(child);
        }
    };

    /**
     * Puts colorized foreground service and call notifications into its own section.
@@ -64,11 +81,30 @@ public class ColorizedFgsCoordinator implements Coordinator {
            }
            return false;
        }

        private NotifComparator mPreferPromoted = new NotifComparator("PreferPromoted") {
            @Override
            public int compare(@NonNull ListEntry o1, @NonNull ListEntry o2) {
                return -1 * Booleans.compare(
                        isPromotedOngoing(o1.getRepresentativeEntry()),
                        isPromotedOngoing(o2.getRepresentativeEntry()));
            }
        };

        @Nullable
        @Override
        public NotifComparator getComparator() {
            if (PromotedNotificationUi.isEnabled()) {
                return mPreferPromoted;
            } else {
                return null;
            }
        }
    };

    /** Determines if the given notification is a colorized or call notification */
    public static boolean isRichOngoing(NotificationEntry entry) {
        return isColorizedForegroundService(entry) || isCall(entry);
        return isPromotedOngoing(entry) || isColorizedForegroundService(entry) || isCall(entry);
    }

    private static boolean isColorizedForegroundService(NotificationEntry entry) {
@@ -78,6 +114,11 @@ public class ColorizedFgsCoordinator implements Coordinator {
                && entry.getImportance() > IMPORTANCE_MIN;
    }

    private static boolean isPromotedOngoing(NotificationEntry entry) {
        // NOTE: isPromotedOngoing already checks the android.app.ui_rich_ongoing flag.
        return entry != null && entry.getSbn().getNotification().isPromotedOngoing();
    }

    private static boolean isCall(NotificationEntry entry) {
        Notification notification = entry.getSbn().getNotification();
        return entry.getImportance() > IMPORTANCE_MIN