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

Commit 9d953996 authored by Pawan Wagh's avatar Pawan Wagh
Browse files

Revert "Refactor AppIconProvider to fix bugs"

Revert submission 33939960-AppIconProvider_refactor

Reason for revert: Test b/423778160

Reverted changes: /q/submissionid:33939960-AppIconProvider_refactor

Change-Id: Idad8236ef295f97bc2a49156bc06b497e9d92a50
parent ec3df532
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -125,7 +125,10 @@ class NotificationInfoTest : SysuiTestCase() {

        // Inflate the layout
        val inflater = LayoutInflater.from(mContext)
        underTest = inflater.inflate(R.layout.notification_info, null) as NotificationInfo
        val layoutId =
            if (Flags.notificationsRedesignTemplates()) R.layout.notification_2025_info
            else R.layout.notification_info
        underTest = inflater.inflate(layoutId, null) as NotificationInfo

        underTest.setGutsParent(mock<NotificationGuts>())

@@ -228,7 +231,16 @@ class NotificationInfoTest : SysuiTestCase() {
    @EnableFlags(Flags.FLAG_NOTIFICATIONS_REDESIGN_TEMPLATES)
    fun testBindNotification_SetsPackageIcon_flagOn() {
        val iconDrawable = mock<Drawable>()
        whenever(mockAppIconProvider.getOrFetchAppIcon(anyOrNull(), anyOrNull(), anyOrNull()))
        whenever(mockIconStyleProvider.shouldShowWorkProfileBadge(anyOrNull(), anyOrNull()))
            .thenReturn(false)
        whenever(
                mockAppIconProvider.getOrFetchAppIcon(
                    anyOrNull(),
                    anyOrNull(),
                    anyBoolean(),
                    anyBoolean(),
                )
            )
            .thenReturn(iconDrawable)
        bindNotification()
        val iconView = underTest.findViewById<ImageView>(R.id.pkg_icon)
+26 −16
Original line number Diff line number Diff line
@@ -18,10 +18,10 @@

package com.android.systemui.statusbar.notification.row.domain.interactor

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.os.UserHandle
import android.platform.test.annotations.EnableFlags
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.MotionScheme
@@ -55,6 +55,7 @@ import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import org.mockito.junit.MockitoJUnit
import org.mockito.junit.MockitoRule
import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever
import platform.test.motion.compose.runMonotonicClockTest
@@ -100,8 +101,9 @@ class BundleInteractorTest : SysuiTestCase() {
            whenever(
                    kosmos.mockAppIconProvider.getOrFetchAppIcon(
                        any<String>(),
                        any<UserHandle>(),
                        any<String>(),
                        any<Context>(),
                        eq(false),
                        eq(false),
                    )
                )
                .thenReturn(drawable1)
@@ -117,7 +119,7 @@ class BundleInteractorTest : SysuiTestCase() {

            // Assert
            verify(kosmos.mockAppIconProvider, times(4))
                .getOrFetchAppIcon(any<String>(), any<UserHandle>(), any<String>())
                .getOrFetchAppIcon(any<String>(), any<Context>(), eq(false), eq(false))

            assertThat(result).hasSize(3)
            assertThat(result).containsExactly(drawable1, drawable2, drawable3).inOrder()
@@ -142,16 +144,18 @@ class BundleInteractorTest : SysuiTestCase() {
            whenever(
                    kosmos.mockAppIconProvider.getOrFetchAppIcon(
                        eq("app1"),
                        any<UserHandle>(),
                        any<String>(),
                        anyOrNull<Context>(),
                        eq(false),
                        eq(false),
                    )
                )
                .thenReturn(drawable1)
            whenever(
                    kosmos.mockAppIconProvider.getOrFetchAppIcon(
                        eq("app2"),
                        any<UserHandle>(),
                        any<String>(),
                        anyOrNull<Context>(),
                        eq(false),
                        eq(false),
                    )
                )
                .thenReturn(drawable2)
@@ -166,9 +170,9 @@ class BundleInteractorTest : SysuiTestCase() {
            // Assert
            assertThat(result).containsExactly(drawable1, drawable2).inOrder()
            verify(kosmos.mockAppIconProvider)
                .getOrFetchAppIcon(eq("app1"), any<UserHandle>(), any<String>())
                .getOrFetchAppIcon(eq("app1"), anyOrNull<Context>(), eq(false), eq(false))
            verify(kosmos.mockAppIconProvider)
                .getOrFetchAppIcon(eq("app2"), any<UserHandle>(), any<String>())
                .getOrFetchAppIcon(eq("app2"), anyOrNull<Context>(), eq(false), eq(false))
        }

    @Test
@@ -197,8 +201,9 @@ class BundleInteractorTest : SysuiTestCase() {
            whenever(
                    kosmos.mockAppIconProvider.getOrFetchAppIcon(
                        eq("new_app"),
                        any<UserHandle>(),
                        any<String>(),
                        anyOrNull<Context>(),
                        eq(false),
                        eq(false),
                    )
                )
                .thenReturn(drawable3)
@@ -213,11 +218,16 @@ class BundleInteractorTest : SysuiTestCase() {
            // Assert
            assertThat(result).containsExactly(drawable3)
            verify(kosmos.mockAppIconProvider, times(0))
                .getOrFetchAppIcon(eq("old_app"), any<UserHandle>(), any<String>())
                .getOrFetchAppIcon(eq("old_app"), anyOrNull<Context>(), eq(false), eq(false))
            verify(kosmos.mockAppIconProvider, times(0))
                .getOrFetchAppIcon(eq("at_collapse_app"), any<UserHandle>(), any<String>())
                .getOrFetchAppIcon(
                    eq("at_collapse_app"),
                    anyOrNull<Context>(),
                    eq(false),
                    eq(false),
                )
            verify(kosmos.mockAppIconProvider)
                .getOrFetchAppIcon(eq("new_app"), any<UserHandle>(), any<String>())
                .getOrFetchAppIcon(eq("new_app"), anyOrNull<Context>(), eq(false), eq(false))
        }

    @Test
@@ -243,7 +253,7 @@ class BundleInteractorTest : SysuiTestCase() {
            // Assert
            assertThat(result).isEmpty()
            verify(kosmos.mockAppIconProvider, times(0))
                .getOrFetchAppIcon(anyString(), any<UserHandle>(), any<String>())
                .getOrFetchAppIcon(anyString(), anyOrNull<Context>(), eq(false), eq(false))
        }

    @Test
+2 −31
Original line number Diff line number Diff line
@@ -157,38 +157,9 @@ class NotifCollectionCache<V>(
     * purge((c));    // deletes a from the cache and marks b for deletion, etc.
     * ```
     */
    fun purge(wantedKeys: Collection<String>) = purgeUnless { it in wantedKeys }

    /**
     * Clear entries whose keys do NOT match [predicate]. This can be called from any thread.
     *
     * If a key matches the [predicate], it will be preserved, otherwise it may be purged depending
     * on internal retainCount.
     *
     * If retainCount > 0, a given key will need to match [predicate] in ([retainCount] + 1)
     * consecutive [purge] calls made more than [purgeTimeoutMillis] apart in order to be cleared.
     * This count will be reset for any given key 1) if [getOrFetch] is called for the key or 2) if
     * the key matches [predicate] in a subsequent [purge] call. We prioritize keeping the entry if
     * possible, so if [purge] is called simultaneously with [getOrFetch] on different threads for
     * example, we will try to keep it in the cache, although it is not guaranteed. If avoiding
     * cache misses is a concern, consider increasing the [retainCount] or [purgeTimeoutMillis].
     *
     * For example, say [retainCount] = 1 and [purgeTimeoutMillis] = 1000 and we start with entries
     * (a, b, c) in the cache:
     * ```kotlin
     * purgeUnless { it in (a, c) } // marks b for deletion
     * Thread.sleep(500)
     * purgeUnless { it in (a, c) } // does nothing as it was called earlier than the min 1s
     * Thread.sleep(500)
     * purgeUnless { it in (b, c) } // b is no longer marked for deletion, but now a is
     * Thread.sleep(1000);
     * purgeUnless { it == c }      // deletes a from the cache and marks b for deletion, etc.
     * ```
     */
    fun purgeUnless(predicate: (String) -> Boolean) {
    fun purge(wantedKeys: Collection<String>) {
        for ((key, entry) in cache) {
            val keep = predicate(key)
            if (keep) {
            if (key in wantedKeys) {
                entry.resetLives()
            } else if (entry.tryPurge()) {
                cache.remove(key)
+3 −1
Original line number Diff line number Diff line
@@ -324,7 +324,9 @@ constructor(
    private fun StatusBarNotification.skeletonAppIcon(packageContext: Context): NotifIcon.AppIcon? {
        if (!android.app.Flags.notificationsRedesignAppIcons()) return null
        if (!notificationIconStyleProvider.shouldShowAppIcon(this, packageContext)) return null
        return NotifIcon.AppIcon(appIconProvider.getOrFetchSkeletonAppIcon(packageName, user))
        return NotifIcon.AppIcon(
            appIconProvider.getOrFetchSkeletonAppIcon(packageName, packageContext)
        )
    }

    private fun Notification.title(): CharSequence? = getCharSequenceExtraUnlessEmpty(EXTRA_TITLE)
+6 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.notification.row;

import static android.app.Flags.notificationsRedesignTemplates;
import static android.app.Flags.notificationsRedesignThemedAppIcons;
import static android.app.Notification.EXTRA_BUILDER_APPLICATION_INFO;
import static android.app.NotificationChannel.SYSTEM_RESERVED_IDS;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
@@ -339,8 +340,11 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
                try {
                    mAppName = String.valueOf(mPm.getApplicationLabel(info));
                    // The app icon is likely already in the cache, so let's use it
                    mPkgIcon = mAppIconProvider.getOrFetchAppIcon(info.packageName,
                            mSbn.getUser(), /* instanceKey= */ "LEGACY");
                    boolean withWorkProfileBadge =
                            mIconStyleProvider.shouldShowWorkProfileBadge(mSbn, getContext());
                    mPkgIcon = mAppIconProvider.getOrFetchAppIcon(info.packageName, getContext(),
                            withWorkProfileBadge,
                            /* themed = */ notificationsRedesignThemedAppIcons());
                } catch (Exception ignored) {
                }
            }
Loading