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

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

Merge "Invert adapter/entry relationship" into main

parents a0a2dca1 703c86c4
Loading
Loading
Loading
Loading
+23 −24
Original line number Diff line number Diff line
@@ -34,123 +34,122 @@ import org.junit.runner.RunWith
@SmallTest
@RunWith(AndroidJUnit4::class)
@RunWithLooper
class BundleEntryTest : SysuiTestCase() {
    private lateinit var underTest: BundleEntry
class BundleEntryAdapterTest : SysuiTestCase() {
    private lateinit var underTest: BundleEntryAdapter

    @get:Rule
    val setFlagsRule = SetFlagsRule()
    @get:Rule val setFlagsRule = SetFlagsRule()

    @Before
    fun setUp() {
        underTest = BundleEntry("key")
        underTest = BundleEntryAdapter(BundleEntry("key"))
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getParent_adapter() {
        assertThat(underTest.entryAdapter.parent).isEqualTo(GroupEntry.ROOT_ENTRY)
        assertThat(underTest.parent).isEqualTo(GroupEntry.ROOT_ENTRY)
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isTopLevelEntry_adapter() {
        assertThat(underTest.entryAdapter.isTopLevelEntry).isTrue()
        assertThat(underTest.isTopLevelEntry).isTrue()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getRow_adapter() {
        assertThat(underTest.entryAdapter.row).isNull()
        assertThat(underTest.row).isNull()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isGroupRoot_adapter() {
        assertThat(underTest.entryAdapter.isGroupRoot).isTrue()
        assertThat(underTest.isGroupRoot).isTrue()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getKey_adapter() {
        assertThat(underTest.entryAdapter.key).isEqualTo("key")
        assertThat(underTest.key).isEqualTo("key")
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isClearable_adapter() {
        assertThat(underTest.entryAdapter.isClearable).isTrue()
        assertThat(underTest.isClearable).isTrue()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getSummarization_adapter() {
        assertThat(underTest.entryAdapter.summarization).isNull()
        assertThat(underTest.summarization).isNull()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getContrastedColor_adapter() {
        assertThat(underTest.entryAdapter.getContrastedColor(context, false, Color.WHITE))
        assertThat(underTest.getContrastedColor(context, false, Color.WHITE))
            .isEqualTo(Notification.COLOR_DEFAULT)
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun canPeek_adapter() {
        assertThat(underTest.entryAdapter.canPeek()).isFalse()
        assertThat(underTest.canPeek()).isFalse()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getWhen_adapter() {
        assertThat(underTest.entryAdapter.`when`).isEqualTo(0)
        assertThat(underTest.`when`).isEqualTo(0)
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isColorized() {
        assertThat(underTest.entryAdapter.isColorized).isFalse()
        assertThat(underTest.isColorized).isFalse()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getSbn() {
        assertThat(underTest.entryAdapter.sbn).isNull()
        assertThat(underTest.sbn).isNull()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun canDragAndDrop() {
        assertThat(underTest.entryAdapter.canDragAndDrop()).isFalse()
        assertThat(underTest.canDragAndDrop()).isFalse()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isBubble() {
        assertThat(underTest.entryAdapter.isBubbleCapable).isFalse()
        assertThat(underTest.isBubbleCapable).isFalse()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getStyle() {
        assertThat(underTest.entryAdapter.style).isNull()
        assertThat(underTest.style).isNull()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getSectionBucket() {
        assertThat(underTest.entryAdapter.sectionBucket).isEqualTo(underTest.bucket)
        assertThat(underTest.sectionBucket).isEqualTo(underTest.entry.bucket)
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isAmbient() {
        assertThat(underTest.entryAdapter.isAmbient).isFalse()
        assertThat(underTest.isAmbient).isFalse()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun canShowFullScreen() {
        assertThat(underTest.entryAdapter.isFullScreenCapable()).isFalse()
        assertThat(underTest.isFullScreenCapable()).isFalse()
    }
}
+370 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.notification.collection

import android.app.ActivityManager
import android.app.Notification
import android.app.NotificationManager
import android.app.PendingIntent
import android.os.UserHandle
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.SetFlagsRule
import android.testing.TestableLooper.RunWithLooper
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.res.R
import com.android.systemui.statusbar.RankingBuilder
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.statusbar.notification.row.entryAdapterFactory
import com.android.systemui.statusbar.notification.shared.NotificationBundleUi
import com.android.systemui.statusbar.notification.stack.BUCKET_ALERTING
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito
import org.mockito.Mockito.verify

@SmallTest
@RunWith(AndroidJUnit4::class)
@RunWithLooper
class NotificationEntryAdapterTest : SysuiTestCase() {
    private val kosmos = testKosmos()

    private val factory: EntryAdapterFactory = kosmos.entryAdapterFactory
    private lateinit var underTest: NotificationEntryAdapter

    @get:Rule val setFlagsRule = SetFlagsRule()

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getParent_adapter() {
        val ge = GroupEntryBuilder().build()
        val notification: Notification =
            Notification.Builder(mContext, "").setSmallIcon(R.drawable.ic_person).build()

        val entry =
            NotificationEntryBuilder()
                .setNotification(notification)
                .setUser(UserHandle(ActivityManager.getCurrentUser()))
                .setParent(ge)
                .build()

        underTest = factory.create(entry) as NotificationEntryAdapter
        assertThat(underTest.parent).isEqualTo(entry.parent)
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isTopLevelEntry_adapter() {
        val notification: Notification =
            Notification.Builder(mContext, "").setSmallIcon(R.drawable.ic_person).build()

        val entry =
            NotificationEntryBuilder()
                .setNotification(notification)
                .setUser(UserHandle(ActivityManager.getCurrentUser()))
                .setParent(GroupEntry.ROOT_ENTRY)
                .build()

        underTest = factory.create(entry) as NotificationEntryAdapter
        assertThat(underTest.isTopLevelEntry).isTrue()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getKey_adapter() {
        val notification: Notification =
            Notification.Builder(mContext, "").setSmallIcon(R.drawable.ic_person).build()

        val entry =
            NotificationEntryBuilder()
                .setNotification(notification)
                .setUser(UserHandle(ActivityManager.getCurrentUser()))
                .build()

        underTest = factory.create(entry) as NotificationEntryAdapter
        assertThat(underTest.key).isEqualTo(entry.key)
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getRow_adapter() {
        val row = Mockito.mock(ExpandableNotificationRow::class.java)
        val notification: Notification =
            Notification.Builder(mContext, "").setSmallIcon(R.drawable.ic_person).build()

        val entry =
            NotificationEntryBuilder()
                .setNotification(notification)
                .setUser(UserHandle(ActivityManager.getCurrentUser()))
                .build()
        entry.row = row

        underTest = factory.create(entry) as NotificationEntryAdapter
        assertThat(underTest.row).isEqualTo(entry.row)
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isGroupRoot_adapter_groupSummary() {
        val row = Mockito.mock(ExpandableNotificationRow::class.java)
        val notification: Notification =
            Notification.Builder(mContext, "")
                .setSmallIcon(R.drawable.ic_person)
                .setGroupSummary(true)
                .setGroup("key")
                .build()

        val entry =
            NotificationEntryBuilder()
                .setNotification(notification)
                .setUser(UserHandle(ActivityManager.getCurrentUser()))
                .setParent(GroupEntry.ROOT_ENTRY)
                .build()
        entry.row = row

        underTest = factory.create(entry) as NotificationEntryAdapter
        assertThat(underTest.isGroupRoot).isFalse()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isGroupRoot_adapter_groupChild() {
        val notification: Notification =
            Notification.Builder(mContext, "")
                .setSmallIcon(R.drawable.ic_person)
                .setGroupSummary(true)
                .setGroup("key")
                .build()

        val parent = NotificationEntryBuilder().setParent(GroupEntry.ROOT_ENTRY).build()
        val groupEntry = GroupEntryBuilder().setSummary(parent)

        val entry =
            NotificationEntryBuilder()
                .setNotification(notification)
                .setUser(UserHandle(ActivityManager.getCurrentUser()))
                .setParent(groupEntry.build())
                .build()

        underTest = factory.create(entry) as NotificationEntryAdapter
        assertThat(underTest.isGroupRoot).isFalse()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isClearable_adapter() {
        val row = Mockito.mock(ExpandableNotificationRow::class.java)
        val notification: Notification =
            Notification.Builder(mContext, "").setSmallIcon(R.drawable.ic_person).build()

        val entry =
            NotificationEntryBuilder()
                .setNotification(notification)
                .setUser(UserHandle(ActivityManager.getCurrentUser()))
                .build()
        entry.row = row

        underTest = factory.create(entry) as NotificationEntryAdapter
        assertThat(underTest.isClearable).isEqualTo(entry.isClearable)
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getSummarization_adapter() {
        val row = Mockito.mock(ExpandableNotificationRow::class.java)
        val notification: Notification =
            Notification.Builder(mContext, "").setSmallIcon(R.drawable.ic_person).build()

        val entry =
            NotificationEntryBuilder()
                .setNotification(notification)
                .setUser(UserHandle(ActivityManager.getCurrentUser()))
                .build()
        val ranking = RankingBuilder(entry.ranking).setSummarization("hello").build()
        entry.setRanking(ranking)
        entry.row = row

        underTest = factory.create(entry) as NotificationEntryAdapter
        assertThat(underTest.summarization).isEqualTo("hello")
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getIcons_adapter() {
        val row = Mockito.mock(ExpandableNotificationRow::class.java)
        val notification: Notification =
            Notification.Builder(mContext, "").setSmallIcon(R.drawable.ic_person).build()

        val entry =
            NotificationEntryBuilder()
                .setNotification(notification)
                .setUser(UserHandle(ActivityManager.getCurrentUser()))
                .build()
        entry.row = row

        underTest = factory.create(entry) as NotificationEntryAdapter
        assertThat(underTest.icons).isEqualTo(entry.icons)
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isColorized() {
        val notification: Notification =
            Notification.Builder(mContext, "")
                .setSmallIcon(R.drawable.ic_person)
                .setColorized(true)
                .build()

        val entry = NotificationEntryBuilder().setNotification(notification).build()

        underTest = factory.create(entry) as NotificationEntryAdapter
        assertThat(underTest.isColorized).isEqualTo(entry.sbn.notification.isColorized)
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getSbn() {
        val notification: Notification =
            Notification.Builder(mContext, "").setSmallIcon(R.drawable.ic_person).build()

        val entry = NotificationEntryBuilder().setNotification(notification).build()

        underTest = factory.create(entry) as NotificationEntryAdapter
        assertThat(underTest.sbn).isEqualTo(entry.sbn)
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun canDragAndDrop() {
        val pi = Mockito.mock(PendingIntent::class.java)
        Mockito.`when`(pi.isActivity).thenReturn(true)
        val notification: Notification =
            Notification.Builder(mContext, "")
                .setSmallIcon(R.drawable.ic_person)
                .setContentIntent(pi)
                .build()

        val entry = NotificationEntryBuilder().setNotification(notification).build()

        underTest = factory.create(entry) as NotificationEntryAdapter
        assertThat(underTest.canDragAndDrop()).isTrue()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isBubble() {
        val notification: Notification =
            Notification.Builder(mContext, "")
                .setSmallIcon(R.drawable.ic_person)
                .setFlag(Notification.FLAG_BUBBLE, true)
                .build()

        val entry = NotificationEntryBuilder().setNotification(notification).build()

        underTest = factory.create(entry) as NotificationEntryAdapter
        assertThat(underTest.isBubbleCapable).isEqualTo(entry.isBubble)
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getStyle() {
        val notification: Notification =
            Notification.Builder(mContext, "")
                .setSmallIcon(R.drawable.ic_person)
                .setStyle(Notification.BigTextStyle())
                .build()

        val entry = NotificationEntryBuilder().setNotification(notification).build()

        underTest = factory.create(entry) as NotificationEntryAdapter
        assertThat(underTest.style).isEqualTo(entry.notificationStyle)
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getSectionBucket() {
        val notification: Notification =
            Notification.Builder(mContext, "")
                .setSmallIcon(R.drawable.ic_person)
                .setStyle(Notification.BigTextStyle())
                .build()

        val entry = NotificationEntryBuilder().setNotification(notification).build()
        entry.bucket = BUCKET_ALERTING

        underTest = factory.create(entry) as NotificationEntryAdapter
        assertThat(underTest.sectionBucket).isEqualTo(BUCKET_ALERTING)
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isAmbient() {
        val notification: Notification =
            Notification.Builder(mContext, "").setSmallIcon(R.drawable.ic_person).build()

        val entry =
            NotificationEntryBuilder()
                .setNotification(notification)
                .setImportance(NotificationManager.IMPORTANCE_MIN)
                .build()

        underTest = factory.create(entry) as NotificationEntryAdapter
        assertThat(underTest.isAmbient).isTrue()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun canShowFullScreen() {
        val notification: Notification =
            Notification.Builder(mContext, "")
                .setSmallIcon(R.drawable.ic_person)
                .setFullScreenIntent(Mockito.mock(PendingIntent::class.java), true)
                .build()

        val entry =
            NotificationEntryBuilder()
                .setNotification(notification)
                .setImportance(NotificationManager.IMPORTANCE_MIN)
                .build()

        underTest = factory.create(entry) as NotificationEntryAdapter
        assertThat(underTest.isFullScreenCapable).isTrue()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun onNotificationBubbleIconClicked() {
        val notification: Notification =
            Notification.Builder(mContext, "").setSmallIcon(R.drawable.ic_person).build()

        val entry =
            NotificationEntryBuilder()
                .setNotification(notification)
                .setImportance(NotificationManager.IMPORTANCE_MIN)
                .build()

        underTest = factory.create(entry) as NotificationEntryAdapter

        underTest.onNotificationBubbleIconClicked()
        verify((factory as? EntryAdapterFactoryImpl)?.getNotificationActivityStarter())
            ?.onNotificationBubbleIconClicked(entry)
    }
}
+0 −339

File changed.

Preview size limit exceeded, changes collapsed.

+34 −27

File changed.

Preview size limit exceeded, changes collapsed.

+14 −9
Original line number Diff line number Diff line
@@ -22,10 +22,13 @@ import android.platform.test.flag.junit.SetFlagsRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.statusbar.notification.collection.EntryAdapterFactoryImpl
import com.android.systemui.statusbar.notification.collection.GroupEntry
import com.android.systemui.statusbar.notification.collection.GroupEntryBuilder
import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder
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.Rule
import org.junit.Test
@@ -35,8 +38,10 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class GroupMembershipManagerTest : SysuiTestCase() {

    @get:Rule
    val setFlagsRule = SetFlagsRule()
    @get:Rule val setFlagsRule = SetFlagsRule()

    private val kosmos = testKosmos()
    private val factory: EntryAdapterFactoryImpl = kosmos.entryAdapterFactory

    private var underTest = GroupMembershipManagerImpl()

@@ -144,14 +149,14 @@ class GroupMembershipManagerTest : SysuiTestCase() {
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isChildEntryAdapterInGroup_topLevel() {
        val topLevelEntry = NotificationEntryBuilder().setParent(GroupEntry.ROOT_ENTRY).build()
        assertThat(underTest.isChildInGroup(topLevelEntry.entryAdapter)).isFalse()
        assertThat(underTest.isChildInGroup(factory.create(topLevelEntry))).isFalse()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isChildEntryAdapterInGroup_noParent() {
        val noParentEntry = NotificationEntryBuilder().setParent(null).build()
        assertThat(underTest.isChildInGroup(noParentEntry.entryAdapter)).isFalse()
        assertThat(underTest.isChildInGroup(factory.create(noParentEntry))).isFalse()
    }

    @Test
@@ -165,7 +170,7 @@ class GroupMembershipManagerTest : SysuiTestCase() {
                .build()
        GroupEntryBuilder().setKey(groupKey).setSummary(summary).build()

        assertThat(underTest.isChildInGroup(summary.entryAdapter)).isFalse()
        assertThat(underTest.isChildInGroup(factory.create(summary))).isFalse()
    }

    @Test
@@ -180,14 +185,14 @@ class GroupMembershipManagerTest : SysuiTestCase() {
        val entry = NotificationEntryBuilder().setGroup(mContext, groupKey).build()
        GroupEntryBuilder().setKey(groupKey).setSummary(summary).addChild(entry).build()

        assertThat(underTest.isChildInGroup(entry.entryAdapter)).isTrue()
        assertThat(underTest.isChildInGroup(factory.create(entry))).isTrue()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isGroupRoot_topLevelEntry() {
        val entry = NotificationEntryBuilder().setParent(GroupEntry.ROOT_ENTRY).build()
        assertThat(underTest.isGroupRoot(entry.entryAdapter)).isFalse()
        assertThat(underTest.isGroupRoot(factory.create(entry))).isFalse()
    }

    @Test
@@ -201,7 +206,7 @@ class GroupMembershipManagerTest : SysuiTestCase() {
                .build()
        GroupEntryBuilder().setKey(groupKey).setSummary(summary).build()

        assertThat(underTest.isGroupRoot(summary.entryAdapter)).isTrue()
        assertThat(underTest.isGroupRoot(factory.create(summary))).isTrue()
    }

    @Test
@@ -216,6 +221,6 @@ class GroupMembershipManagerTest : SysuiTestCase() {
        val entry = NotificationEntryBuilder().setGroup(mContext, groupKey).build()
        GroupEntryBuilder().setKey(groupKey).setSummary(summary).addChild(entry).build()

        assertThat(underTest.isGroupRoot(entry.entryAdapter)).isFalse()
        assertThat(underTest.isGroupRoot(factory.create(entry))).isFalse()
    }
}
Loading