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

Commit c109b730 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Ensure call notifications appear in the "ForegroundService" section.

Fixes: 215584504
Test: atest AppOpsCoordinatorTest
Change-Id: I53fe4e91446a6f4a8b306ecd4ed268dedac57f68
parent feb567fa
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ public class AppOpsCoordinator implements Coordinator {
    };

    /**
     * Puts foreground service notifications into its own section.
     * Puts colorized foreground service and call notifications into its own section.
     */
    private final NotifSectioner mNotifSectioner = new NotifSectioner("ForegroundService",
            NotificationPriorityBucketKt.BUCKET_FOREGROUND_SERVICE) {
@@ -109,12 +109,22 @@ public class AppOpsCoordinator implements Coordinator {
        public boolean isInSection(ListEntry entry) {
            NotificationEntry notificationEntry = entry.getRepresentativeEntry();
            if (notificationEntry != null) {
                Notification notification = notificationEntry.getSbn().getNotification();
                return isColorizedForegroundService(notificationEntry) || isCall(notificationEntry);
            }
            return false;
        }

        private boolean isColorizedForegroundService(NotificationEntry entry) {
            Notification notification = entry.getSbn().getNotification();
            return notification.isForegroundService()
                    && notification.isColorized()
                        && entry.getRepresentativeEntry().getImportance() > IMPORTANCE_MIN;
                    && entry.getImportance() > IMPORTANCE_MIN;
        }
            return false;

        private boolean isCall(NotificationEntry entry) {
            Notification notification = entry.getSbn().getNotification();
            return entry.getImportance() > IMPORTANCE_MIN
                    && notification.isStyle(Notification.CallStyle.class);
        }
    };
}
+35 −0
Original line number Diff line number Diff line
@@ -28,6 +28,10 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

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.service.notification.StatusBarNotification;
@@ -151,4 +155,35 @@ public class AppOpsCoordinatorTest extends SysuiTestCase {
        // THEN the entry is NOT in the fgs section
        assertFalse(mFgsSection.isInSection(mEntryBuilder.build()));
    }

    @Test
    public void testIncludeCallInSection_importanceDefault() {
        // GIVEN the notification represents a call with > min importance
        mEntryBuilder
                .setImportance(IMPORTANCE_DEFAULT)
                .modifyNotification(mContext)
                .setStyle(makeCallStyle());

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

    @Test
    public void testDiscludeCallInSection_importanceMin() {
        // GIVEN the notification represents a call with min importance
        mEntryBuilder
                .setImportance(IMPORTANCE_MIN)
                .modifyNotification(mContext)
                .setStyle(makeCallStyle());

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

    private Notification.CallStyle makeCallStyle() {
        final PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0,
                new Intent("action"), PendingIntent.FLAG_IMMUTABLE);
        final Person person = new Person.Builder().setName("person").build();
        return Notification.CallStyle.forIncomingCall(person, pendingIntent, pendingIntent);
    }
}