Merge "Ensure call notifications appear in the "ForegroundService" section."

This commit is contained in:
TreeHugger Robot
2022-01-21 04:52:07 +00:00
committed by Android (Google) Code Review
2 changed files with 50 additions and 5 deletions

View File

@@ -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 notification.isForegroundService()
&& notification.isColorized()
&& entry.getRepresentativeEntry().getImportance() > IMPORTANCE_MIN;
return isColorizedForegroundService(notificationEntry) || isCall(notificationEntry);
}
return false;
}
private boolean isColorizedForegroundService(NotificationEntry entry) {
Notification notification = entry.getSbn().getNotification();
return notification.isForegroundService()
&& notification.isColorized()
&& entry.getImportance() > IMPORTANCE_MIN;
}
private boolean isCall(NotificationEntry entry) {
Notification notification = entry.getSbn().getNotification();
return entry.getImportance() > IMPORTANCE_MIN
&& notification.isStyle(Notification.CallStyle.class);
}
};
}

View File

@@ -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);
}
}