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

Commit b702fbea authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Pull AUTOGROUP_AT_COUNT into an XML config."

parents b599d73b 48dd614a
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -3374,6 +3374,9 @@
    <!-- URI for in call notification sound -->
    <string translatable="false" name="config_inCallNotificationSound">/system/media/audio/ui/InCallNotification.ogg</string>

    <!-- Default number of notifications from the same app before they are automatically grouped by the OS -->
    <integer translatable="false" name="config_autoGroupAtCount">4</integer>

    <!-- The OEM specified sensor type for the lift trigger to launch the camera app. -->
    <integer name="config_cameraLiftTriggerSensorType">-1</integer>
    <!-- The OEM specified sensor string type for the gesture to launch camera app, this value
+1 −0
Original line number Diff line number Diff line
@@ -3266,6 +3266,7 @@
  <java-symbol type="bool" name="config_handleVolumeKeysInWindowManager" />
  <java-symbol type="dimen" name="config_inCallNotificationVolume" />
  <java-symbol type="string" name="config_inCallNotificationSound" />
  <java-symbol type="integer" name="config_autoGroupAtCount" />
  <java-symbol type="bool" name="config_dozeAlwaysOnDisplayAvailable" />
  <java-symbol type="bool" name="config_dozeAlwaysOnEnabled" />
  <java-symbol type="bool" name="config_displayBlanksAfterDoze" />
+4 −3
Original line number Diff line number Diff line
@@ -32,16 +32,17 @@ public class GroupHelper {
    private static final String TAG = "GroupHelper";
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);

    protected static final int AUTOGROUP_AT_COUNT = 4;
    protected static final String AUTOGROUP_KEY = "ranker_group";

    private final Callback mCallback;
    private final int mAutoGroupAtCount;

    // Map of user : <Map of package : notification keys>. Only contains notifications that are not
    // grouped by the app (aka no group or sort key).
    Map<Integer, Map<String, LinkedHashSet<String>>> mUngroupedNotifications = new HashMap<>();

    public GroupHelper(Callback callback) {;
    public GroupHelper(int autoGroupAtCount, Callback callback) {
        mAutoGroupAtCount = autoGroupAtCount;
        mCallback = callback;
    }

@@ -68,7 +69,7 @@ public class GroupHelper {
                    notificationsForPackage.add(sbn.getKey());
                    ungroupedNotificationsByUser.put(sbn.getPackageName(), notificationsForPackage);

                    if (notificationsForPackage.size() >= AUTOGROUP_AT_COUNT
                    if (notificationsForPackage.size() >= mAutoGroupAtCount
                            || autogroupSummaryExists) {
                        notificationsToGroup.addAll(notificationsForPackage);
                    }
+4 −1
Original line number Diff line number Diff line
@@ -400,6 +400,7 @@ public class NotificationManagerService extends SystemService {

    private SnoozeHelper mSnoozeHelper;
    private GroupHelper mGroupHelper;
    private int mAutoGroupAtCount;
    private boolean mIsTelevision;

    private MetricsLogger mMetricsLogger;
@@ -1565,7 +1566,9 @@ public class NotificationManagerService extends SystemService {
    }

    private GroupHelper getGroupHelper() {
        return new GroupHelper(new GroupHelper.Callback() {
        mAutoGroupAtCount =
                getContext().getResources().getInteger(R.integer.config_autoGroupAtCount);
        return new GroupHelper(mAutoGroupAtCount, new GroupHelper.Callback() {
            @Override
            public void addAutoGroup(String key) {
                synchronized (mNotificationLock) {
+21 −22
Original line number Diff line number Diff line
@@ -50,13 +50,14 @@ import java.util.Map;
public class GroupHelperTest extends UiServiceTestCase {
    private @Mock GroupHelper.Callback mCallback;

    private final static int AUTOGROUP_AT_COUNT = 4;
    private GroupHelper mGroupHelper;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);

        mGroupHelper = new GroupHelper(mCallback);
        mGroupHelper = new GroupHelper(AUTOGROUP_AT_COUNT, mCallback);
    }

    private StatusBarNotification getSbn(String pkg, int id, String tag,
@@ -79,7 +80,7 @@ public class GroupHelperTest extends UiServiceTestCase {
    @Test
    public void testNoGroup_postingUnderLimit() throws Exception {
        final String pkg = "package";
        for (int i = 0; i < GroupHelper.AUTOGROUP_AT_COUNT - 1; i++) {
        for (int i = 0; i < AUTOGROUP_AT_COUNT - 1; i++) {
            mGroupHelper.onNotificationPosted(getSbn(pkg, i, String.valueOf(i), UserHandle.SYSTEM),
                    false);
        }
@@ -94,12 +95,12 @@ public class GroupHelperTest extends UiServiceTestCase {
    public void testNoGroup_multiPackage() throws Exception {
        final String pkg = "package";
        final String pkg2 = "package2";
        for (int i = 0; i < GroupHelper.AUTOGROUP_AT_COUNT - 1; i++) {
        for (int i = 0; i < AUTOGROUP_AT_COUNT - 1; i++) {
            mGroupHelper.onNotificationPosted(getSbn(pkg, i, String.valueOf(i), UserHandle.SYSTEM),
                    false);
        }
        mGroupHelper.onNotificationPosted(
                getSbn(pkg2, GroupHelper.AUTOGROUP_AT_COUNT, "four", UserHandle.SYSTEM), false);
                getSbn(pkg2, AUTOGROUP_AT_COUNT, "four", UserHandle.SYSTEM), false);
        verify(mCallback, never()).addAutoGroupSummary(
                eq(UserHandle.USER_SYSTEM), eq(pkg), anyString());
        verify(mCallback, never()).addAutoGroup(anyString());
@@ -110,13 +111,12 @@ public class GroupHelperTest extends UiServiceTestCase {
    @Test
    public void testNoGroup_multiUser() throws Exception {
        final String pkg = "package";
        for (int i = 0; i < GroupHelper.AUTOGROUP_AT_COUNT - 1; i++) {
        for (int i = 0; i < AUTOGROUP_AT_COUNT - 1; i++) {
            mGroupHelper.onNotificationPosted(getSbn(pkg, i, String.valueOf(i), UserHandle.SYSTEM),
                    false);
        }
        mGroupHelper.onNotificationPosted(
                getSbn(pkg, GroupHelper.AUTOGROUP_AT_COUNT, "four", UserHandle.ALL),
                false);
                getSbn(pkg, AUTOGROUP_AT_COUNT, "four", UserHandle.ALL), false);
        verify(mCallback, never()).addAutoGroupSummary(anyInt(), eq(pkg), anyString());
        verify(mCallback, never()).addAutoGroup(anyString());
        verify(mCallback, never()).removeAutoGroup(anyString());
@@ -126,13 +126,12 @@ public class GroupHelperTest extends UiServiceTestCase {
    @Test
    public void testNoGroup_someAreGrouped() throws Exception {
        final String pkg = "package";
        for (int i = 0; i < GroupHelper.AUTOGROUP_AT_COUNT - 1; i++) {
        for (int i = 0; i < AUTOGROUP_AT_COUNT - 1; i++) {
            mGroupHelper.onNotificationPosted(
                    getSbn(pkg, i, String.valueOf(i), UserHandle.SYSTEM), false);
        }
        mGroupHelper.onNotificationPosted(
                getSbn(pkg, GroupHelper.AUTOGROUP_AT_COUNT, "four", UserHandle.SYSTEM, "a"),
                false);
                getSbn(pkg, AUTOGROUP_AT_COUNT, "four", UserHandle.SYSTEM, "a"), false);
        verify(mCallback, never()).addAutoGroupSummary(
                eq(UserHandle.USER_SYSTEM), eq(pkg), anyString());
        verify(mCallback, never()).addAutoGroup(anyString());
@@ -144,12 +143,12 @@ public class GroupHelperTest extends UiServiceTestCase {
    @Test
    public void testPostingOverLimit() throws Exception {
        final String pkg = "package";
        for (int i = 0; i < GroupHelper.AUTOGROUP_AT_COUNT; i++) {
        for (int i = 0; i < AUTOGROUP_AT_COUNT; i++) {
            mGroupHelper.onNotificationPosted(
                    getSbn(pkg, i, String.valueOf(i), UserHandle.SYSTEM), false);
        }
        verify(mCallback, times(1)).addAutoGroupSummary(anyInt(), eq(pkg), anyString());
        verify(mCallback, times(GroupHelper.AUTOGROUP_AT_COUNT)).addAutoGroup(anyString());
        verify(mCallback, times(AUTOGROUP_AT_COUNT)).addAutoGroup(anyString());
        verify(mCallback, never()).removeAutoGroup(anyString());
        verify(mCallback, never()).removeAutoGroupSummary(anyInt(), anyString());
    }
@@ -158,18 +157,18 @@ public class GroupHelperTest extends UiServiceTestCase {
    public void testDropToZeroRemoveGroup() throws Exception {
        final String pkg = "package";
        List<StatusBarNotification> posted = new ArrayList<>();
        for (int i = 0; i < GroupHelper.AUTOGROUP_AT_COUNT; i++) {
        for (int i = 0; i < AUTOGROUP_AT_COUNT; i++) {
            final StatusBarNotification sbn = getSbn(pkg, i, String.valueOf(i), UserHandle.SYSTEM);
            posted.add(sbn);
            mGroupHelper.onNotificationPosted(sbn, false);
        }
        verify(mCallback, times(1)).addAutoGroupSummary(anyInt(), eq(pkg), anyString());
        verify(mCallback, times(GroupHelper.AUTOGROUP_AT_COUNT)).addAutoGroup(anyString());
        verify(mCallback, times(AUTOGROUP_AT_COUNT)).addAutoGroup(anyString());
        verify(mCallback, never()).removeAutoGroup(anyString());
        verify(mCallback, never()).removeAutoGroupSummary(anyInt(), anyString());
        Mockito.reset(mCallback);

        for (int i = 0; i < GroupHelper.AUTOGROUP_AT_COUNT - 1; i++) {
        for (int i = 0; i < AUTOGROUP_AT_COUNT - 1; i++) {
            mGroupHelper.onNotificationRemoved(posted.remove(0));
        }
        verify(mCallback, never()).removeAutoGroup(anyString());
@@ -185,28 +184,28 @@ public class GroupHelperTest extends UiServiceTestCase {
    public void testAppStartsGrouping() throws Exception {
        final String pkg = "package";
        List<StatusBarNotification> posted = new ArrayList<>();
        for (int i = 0; i < GroupHelper.AUTOGROUP_AT_COUNT; i++) {
        for (int i = 0; i < AUTOGROUP_AT_COUNT; i++) {
            final StatusBarNotification sbn = getSbn(pkg, i, String.valueOf(i), UserHandle.SYSTEM);
            posted.add(sbn);
            mGroupHelper.onNotificationPosted(sbn, false);
        }
        verify(mCallback, times(1)).addAutoGroupSummary(anyInt(), eq(pkg), anyString());
        verify(mCallback, times(GroupHelper.AUTOGROUP_AT_COUNT)).addAutoGroup(anyString());
        verify(mCallback, times(AUTOGROUP_AT_COUNT)).addAutoGroup(anyString());
        verify(mCallback, never()).removeAutoGroup(anyString());
        verify(mCallback, never()).removeAutoGroupSummary(anyInt(), anyString());
        Mockito.reset(mCallback);

        int i = 0;
        for (i = 0; i < GroupHelper.AUTOGROUP_AT_COUNT - 2; i++) {
        for (i = 0; i < AUTOGROUP_AT_COUNT - 2; i++) {
            final StatusBarNotification sbn =
                    getSbn(pkg, i, String.valueOf(i), UserHandle.SYSTEM, "app group");
            mGroupHelper.onNotificationPosted(sbn, false);
        }
        verify(mCallback, times(GroupHelper.AUTOGROUP_AT_COUNT - 2)).removeAutoGroup(anyString());
        verify(mCallback, times(AUTOGROUP_AT_COUNT - 2)).removeAutoGroup(anyString());
        verify(mCallback, never()).removeAutoGroupSummary(anyInt(), anyString());
        Mockito.reset(mCallback);

        for (; i < GroupHelper.AUTOGROUP_AT_COUNT; i++) {
        for (; i < AUTOGROUP_AT_COUNT; i++) {
            final StatusBarNotification sbn =
                    getSbn(pkg, i, String.valueOf(i), UserHandle.SYSTEM, "app group");
            mGroupHelper.onNotificationPosted(sbn, false);
@@ -220,13 +219,13 @@ public class GroupHelperTest extends UiServiceTestCase {
            throws Exception {
        final String pkg = "package";
        List<StatusBarNotification> posted = new ArrayList<>();
        for (int i = 0; i < GroupHelper.AUTOGROUP_AT_COUNT; i++) {
        for (int i = 0; i < AUTOGROUP_AT_COUNT; i++) {
            final StatusBarNotification sbn = getSbn(pkg, i, String.valueOf(i), UserHandle.SYSTEM);
            posted.add(sbn);
            mGroupHelper.onNotificationPosted(sbn, false);
        }
        verify(mCallback, times(1)).addAutoGroupSummary(anyInt(), eq(pkg), anyString());
        verify(mCallback, times(GroupHelper.AUTOGROUP_AT_COUNT)).addAutoGroup(anyString());
        verify(mCallback, times(AUTOGROUP_AT_COUNT)).addAutoGroup(anyString());
        verify(mCallback, never()).removeAutoGroup(anyString());
        verify(mCallback, never()).removeAutoGroupSummary(anyInt(), anyString());
        Mockito.reset(mCallback);