Ensure call notifications appear in the "ForegroundService" section.
Fixes: 215584504 Test: atest AppOpsCoordinatorTest Change-Id: I53fe4e91446a6f4a8b306ecd4ed268dedac57f68
This commit is contained in:
@@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user