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

Commit 071c35d4 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Migrate NotificationGroupingUtil to EntryAdapter" into main

parents 99624a74 67053093
Loading
Loading
Loading
Loading
+63 −1
Original line number Diff line number Diff line
@@ -16,24 +16,35 @@

package com.android.systemui.statusbar

import android.app.Notification
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.FlagsParameterization
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.res.R
import com.android.systemui.statusbar.notification.collection.BundleEntry
import com.android.systemui.statusbar.notification.collection.EntryAdapterFactory
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.statusbar.notification.row.NotificationTestHelper
import com.android.systemui.statusbar.notification.row.entryAdapterFactory
import com.android.systemui.statusbar.notification.shared.NotificationBundleUi
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.mock
import org.mockito.Mockito.`when`
import platform.test.runner.parameterized.ParameterizedAndroidJunit4
import platform.test.runner.parameterized.Parameters

@SmallTest
@RunWith(ParameterizedAndroidJunit4::class)
class NotificationGroupingUtilTest(flags: FlagsParameterization) : SysuiTestCase() {

    private val kosmos = testKosmos()
    private lateinit var underTest: NotificationGroupingUtil

    private val factory: EntryAdapterFactory = kosmos.entryAdapterFactory
    private lateinit var testHelper: NotificationTestHelper

    companion object {
@@ -60,4 +71,55 @@ class NotificationGroupingUtilTest(flags: FlagsParameterization) : SysuiTestCase
        underTest = NotificationGroupingUtil(row)
        assertThat(underTest.showsTime(row)).isTrue()
    }

    @Test
    fun iconExtractor_extractsSbn_notification() {
        val row = testHelper.createRow()

        underTest = NotificationGroupingUtil(row)

        assertThat(NotificationGroupingUtil.ICON_EXTRACTOR.extractData(row)).isInstanceOf(
            Notification::class.java)
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun iconExtractor_noException_bundle() {
        val row = mock(ExpandableNotificationRow::class.java)
        val be = BundleEntry("promotions")
        `when`(row.entryAdapter).thenReturn(factory.create(be))

        underTest = NotificationGroupingUtil(row)

        assertThat(NotificationGroupingUtil.ICON_EXTRACTOR.extractData(row)).isNull()
    }

    @Test
    fun iconComparator_sameNotificationIcon() {
        val n1 = NotificationGroupingUtil.ICON_EXTRACTOR.extractData(testHelper.createRow())
        val n2 = NotificationGroupingUtil.ICON_EXTRACTOR.extractData(testHelper.createRow())

        assertThat(NotificationGroupingUtil.IconComparator().hasSameIcon(n1, n2)).isTrue()
    }

    @Test
    fun iconComparator_differentNotificationIcon() {
        val notif = Notification.Builder(mContext, "").setSmallIcon(R.drawable.ic_menu).build()
        val n1 = NotificationGroupingUtil.ICON_EXTRACTOR.extractData(testHelper.createRow(notif))
        val n2 = NotificationGroupingUtil.ICON_EXTRACTOR.extractData(testHelper.createRow())

        assertThat(NotificationGroupingUtil.IconComparator().hasSameIcon(n1, n2)).isFalse()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun iconComparator_bundleNotification() {
        assertThat(NotificationGroupingUtil.IconComparator().hasSameIcon(null,
            NotificationGroupingUtil.ICON_EXTRACTOR.extractData(testHelper.createRow()))).isFalse()
    }

    @Test
    fun iconComparator_twoBundles() {
        assertThat(NotificationGroupingUtil.IconComparator().hasSameIcon(null, null)).isFalse()
    }
}
 No newline at end of file
+24 −5
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import com.android.internal.R;
import com.android.internal.widget.CachingIconView;
import com.android.internal.widget.ConversationLayout;
import com.android.internal.widget.ImageFloatingTextView;
import com.android.systemui.statusbar.notification.icon.IconPack;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.row.NotificationContentView;
import com.android.systemui.statusbar.notification.row.shared.AsyncGroupHeaderViewInflation;
@@ -61,11 +62,20 @@ public class NotificationGroupingUtil {
    private static final VisibilityApplicator VISIBILITY_APPLICATOR = new VisibilityApplicator();
    private static final VisibilityApplicator APP_NAME_APPLICATOR = new AppNameApplicator();
    private static final ResultApplicator LEFT_ICON_APPLICATOR = new LeftIconApplicator();
    private static final DataExtractor ICON_EXTRACTOR = new DataExtractor() {

    @VisibleForTesting
    static final DataExtractor ICON_EXTRACTOR = new DataExtractor() {
        @Override
        public Object extractData(ExpandableNotificationRow row) {
            if (NotificationBundleUi.isEnabled()) {
                if (row.getEntryAdapter().getSbn() != null) {
                    return row.getEntryAdapter().getSbn().getNotification();
                }
                return null;
            } else {
                return row.getEntry().getSbn().getNotification();
            }
        }
    };

    private final ExpandableNotificationRow mRow;
@@ -253,7 +263,7 @@ public class NotificationGroupingUtil {
        if (NotificationBundleUi.isEnabled()) {
            sbn = row.getEntryAdapter() != null ? row.getEntryAdapter().getSbn() : null;
        } else {
            sbn = row.getEntry().getSbn();
            sbn = row.getEntryLegacy().getSbn();
        }
        return (sbn != null && sbn.getNotification().showsTime());
    }
@@ -357,7 +367,8 @@ public class NotificationGroupingUtil {
        boolean isEmpty(View view);
    }

    private interface DataExtractor {
    @VisibleForTesting
    interface DataExtractor {
        Object extractData(ExpandableNotificationRow row);
    }

@@ -395,13 +406,17 @@ public class NotificationGroupingUtil {
        }
    }

    private abstract static class IconComparator implements ViewComparator {
    @VisibleForTesting
    static class IconComparator implements ViewComparator {
        @Override
        public boolean compare(View parent, View child, Object parentData, Object childData) {
            return false;
        }

        protected boolean hasSameIcon(Object parentData, Object childData) {
            if (parentData == null || childData == null) {
                return false;
            }
            Icon parentIcon = ((Notification) parentData).getSmallIcon();
            Icon childIcon = ((Notification) childData).getSmallIcon();
            return parentIcon.sameAs(childIcon);
@@ -411,6 +426,10 @@ public class NotificationGroupingUtil {
         * @return whether two ImageViews have the same colorFilterSet or none at all
         */
        protected boolean hasSameColor(Object parentData, Object childData) {
            if ((parentData == null && childData != null)
                    || (parentData != null && childData == null)) {
                return false;
            }
            int parentColor = ((Notification) parentData).color;
            int childColor = ((Notification) childData).color;
            return parentColor == childColor;
+1 −1
Original line number Diff line number Diff line
@@ -976,7 +976,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        return mEntry;
    }

    @Nullable
    @NonNull
    public EntryAdapter getEntryAdapter() {
        NotificationBundleUi.unsafeAssertInNewMode();
        return mEntryAdapter;