diff options
3 files changed, 24 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/notification/GroupHelper.java b/services/core/java/com/android/server/notification/GroupHelper.java index 9b9be4cd8f3f..6681e36e00ee 100644 --- a/services/core/java/com/android/server/notification/GroupHelper.java +++ b/services/core/java/com/android/server/notification/GroupHelper.java @@ -29,6 +29,7 @@ import static android.service.notification.Flags.notificationForceGrouping; import android.annotation.FlaggedApi; import android.annotation.NonNull; import android.annotation.Nullable; +import android.app.ActivityManager; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; @@ -88,6 +89,7 @@ public class GroupHelper { private final int mAutogroupSparseGroupsAtCount; private final Context mContext; private final PackageManager mPackageManager; + private boolean mIsTestHarnessExempted; // Only contains notifications that are not explicitly grouped by the app (aka no group or // sort key). @@ -174,6 +176,11 @@ public class GroupHelper { NOTIFICATION_SHADE_SECTIONS = getNotificationShadeSections(); } + void setTestHarnessExempted(boolean isExempted) { + // Allow E2E tests to post ungrouped notifications + mIsTestHarnessExempted = ActivityManager.isRunningInUserTestHarness() && isExempted; + } + private String generatePackageKey(int userId, String pkg) { return userId + "|" + pkg; } @@ -696,6 +703,10 @@ public class GroupHelper { return; } + if (mIsTestHarnessExempted) { + return; + } + final NotificationSectioner sectioner = getSection(record); if (sectioner == null) { if (DEBUG) { diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 62d762244617..e48c8ee718e3 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -2984,6 +2984,11 @@ public class NotificationManagerService extends SystemService { }); } + //Enables tests running in TH mode to be exempted from forced grouping of notifications + void setTestHarnessExempted(boolean isExempted) { + mGroupHelper.setTestHarnessExempted(isExempted); + } + private void sendRegisteredOnlyBroadcast(String action) { sendRegisteredOnlyBroadcast(new Intent(action)); } diff --git a/services/core/java/com/android/server/notification/NotificationShellCmd.java b/services/core/java/com/android/server/notification/NotificationShellCmd.java index 10169d544b73..c305d66c24c1 100644 --- a/services/core/java/com/android/server/notification/NotificationShellCmd.java +++ b/services/core/java/com/android/server/notification/NotificationShellCmd.java @@ -80,6 +80,7 @@ public class NotificationShellCmd extends ShellCommand { + " get <notification-key>\n" + " snooze --for <msec> <notification-key>\n" + " unsnooze <notification-key>\n" + + " set_exempt_th_force_grouping [true|false]\n" ; private static final String NOTIFY_USAGE = @@ -428,6 +429,13 @@ public class NotificationShellCmd extends ShellCommand { } break; } + case "set_exempt_th_force_grouping": { + String arg = getNextArgRequired(); + final boolean exemptTestHarnessFromForceGrouping = + "true".equals(arg) || "1".equals(arg); + mDirectService.setTestHarnessExempted(exemptTestHarnessFromForceGrouping); + break; + } default: return handleDefaultCommands(cmd); } |