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

Commit 364a7091 authored by Valentin Iftime's avatar Valentin Iftime
Browse files

Allow TestHarness exemption from forced grouping notifications

 Forced grouping for all notifications in Test Harness can be disabled via ADB cmd:
 - adb shell cmd notification set_exempt_th_force_grouping true

 While running tests in Test Harness mode, disable forced grouping of abusive notifications:
 	- group summary notifications without children
 	- group child notifications without summary

 Autogrouping of ungrouped notifications is still enabled.

Flag: android.service.notification.notification_force_grouping
Test: atest PlatformScenarioTests:android.platform.test.scenario.notification

Bug: 359340654

Change-Id: Iaa74d9d5d3b338b68d3201f8f96854cd72f19a2c
parent 21754b02
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
@@ -2982,6 +2982,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);
            }