Merge "Update notifications on density or font size change for current user" into pi-dev

am: 1394b342e3

Change-Id: I913e56f9da1676df6ce78e18fc9a47cca101e481
This commit is contained in:
Dieter Hsu
2018-06-06 15:37:21 -07:00
committed by android-build-merger
3 changed files with 42 additions and 5 deletions

View File

@@ -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);
}

View File

@@ -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();

View File

@@ -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);