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

Commit 36e1ebca authored by Dieter Hsu's avatar Dieter Hsu Committed by Selim Cinek
Browse files

Update notifications on density or font size change for current user

For created notifications, entry manager is not going to update entries
after changing the font scale and/or display density when shade is
disabled or other reasons.
To reinflate notifications for current user even filtered.

Fixes: 77728867
Test: manually restore backup with lots of apps and change font scale and/or display density
Test: atest SystemUITests:NotificationDataTest
Change-Id: I37fa38e73af1ebb672abd06282d10d7d928cc3a9
parent bfa0ee12
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -345,6 +345,7 @@ public class NotificationData {

    private final ArrayMap<String, Entry> mEntries = new ArrayMap<>();
    private final ArrayList<Entry> mSortedAndFiltered = new ArrayList<>();
    private final ArrayList<Entry> mFilteredForUser = new ArrayList<>();

    private NotificationGroupManager mGroupManager;

@@ -429,6 +430,23 @@ public class NotificationData {
        return mSortedAndFiltered;
    }

    public ArrayList<Entry> getNotificationsForCurrentUser() {
        mFilteredForUser.clear();

        synchronized (mEntries) {
            final int N = mEntries.size();
            for (int i = 0; i < N; i++) {
                Entry entry = mEntries.valueAt(i);
                final StatusBarNotification sbn = entry.notification;
                if (!mEnvironment.isNotificationForCurrentProfiles(sbn)) {
                    continue;
                }
                mFilteredForUser.add(entry);
            }
        }
        return mFilteredForUser;
    }

    public Entry get(String key) {
        return mEntries.get(key);
    }
+4 −4
Original line number Diff line number Diff line
@@ -681,10 +681,10 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.
    }

    public void updateNotificationsOnDensityOrFontScaleChanged() {
        ArrayList<NotificationData.Entry> activeNotifications =
                mNotificationData.getActiveNotifications();
        for (int i = 0; i < activeNotifications.size(); i++) {
            NotificationData.Entry entry = activeNotifications.get(i);
        ArrayList<NotificationData.Entry> userNotifications =
                mNotificationData.getNotificationsForCurrentUser();
        for (int i = 0; i < userNotifications.size(); i++) {
            NotificationData.Entry entry = userNotifications.get(i);
            boolean exposedGuts = mGutsManager.getExposedGuts() != null
                    && entry.row.getGuts() == mGutsManager.getExposedGuts();
            entry.row.onDensityOrFontScaleChanged();
+20 −1
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.support.test.annotation.UiThreadTest;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper.RunWithLooper;
import android.util.ArraySet;
@@ -62,6 +61,8 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.ArrayList;

@SmallTest
@RunWith(AndroidTestingRunner.class)
@RunWithLooper(setAsMainLooper = true)
@@ -279,6 +280,24 @@ public class NotificationDataTest extends SysuiTestCase {
        assertFalse(mNotificationData.shouldFilterOut(entry));
    }

    @Test
    public void testGetNotificationsForCurrentUser_shouldFilterNonCurrentUserNotifications()
            throws Exception {
        mNotificationData.add(mRow.getEntry());
        ExpandableNotificationRow row2 = new NotificationTestHelper(getContext()).createRow();
        mNotificationData.add(row2.getEntry());

        when(mEnvironment.isNotificationForCurrentProfiles(
                mRow.getEntry().notification)).thenReturn(false);
        when(mEnvironment.isNotificationForCurrentProfiles(
                row2.getEntry().notification)).thenReturn(true);
        ArrayList<NotificationData.Entry> reuslt =
                mNotificationData.getNotificationsForCurrentUser();

        assertEquals(reuslt.size(), 1);
        assertEquals(reuslt.get(0), row2.getEntry());
    }

    @Test
    public void testIsExemptFromDndVisualSuppression_foreground() {
        initStatusBarNotification(false);