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

Commit 122fbe47 authored by Iavor-Valentin Iftime's avatar Iavor-Valentin Iftime Committed by Android (Google) Code Review
Browse files

Merge "Allow TestHarness exemption from forced grouping notifications" into main

parents 552200a5 364a7091
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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) {
+5 −0
Original line number Diff line number Diff line
@@ -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));
    }
+8 −0
Original line number Diff line number Diff line
@@ -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);
            }