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

Commit d5306f77 authored by Ioana Alexandru's avatar Ioana Alexandru Committed by Android (Google) Code Review
Browse files

Merge "Fall back to small icon when AppIconProvider throws" into main

parents b929149e c56b8800
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.app.Notification.InboxStyle
import android.app.Notification.ProgressStyle
import android.app.Person
import android.content.Context
import android.content.pm.PackageManager.NameNotFoundException
import android.graphics.drawable.Icon
import android.service.notification.StatusBarNotification
import com.android.systemui.Flags
@@ -243,7 +244,16 @@ constructor(
    private fun StatusBarNotification.skeletonAppIcon(): NotifIcon.AppIcon? {
        if (!android.app.Flags.notificationsRedesignAppIcons()) return null
        if (!notificationIconStyleProvider.shouldShowAppIcon(this, context)) return null
        return NotifIcon.AppIcon(appIconProvider.getOrFetchSkeletonAppIcon(packageName, context))
        return try {
            NotifIcon.AppIcon(appIconProvider.getOrFetchSkeletonAppIcon(packageName, context))
        } catch (e: NameNotFoundException) {
            // TODO: b/416215382 - Because we're passing the SystemUI context to AppIconProvider
            //  instead of the app's context, the fetch method can throw a NameNotFoundException
            //  if the app is not installed on the main profile. When this happens, we fall back to
            //  the small icon here as a temporary workaround, but this will be removed when the
            //  AppIconProvided is updated to receive a userId instead of a context.
            null
        }
    }

    private fun Notification.title(): CharSequence? = getCharSequenceExtraUnlessEmpty(EXTRA_TITLE)
+7 −0
Original line number Diff line number Diff line
@@ -64,6 +64,13 @@ interface AppIconProvider {
    /**
     * Loads the skeleton (black and white)-themed icon corresponding to [packageName] into cache,
     * or fetches it from there if already present. This should only be called from the background.
     *
     * @param packageName the name of the app's package
     * @param context the app's context (NOT SystemUI)
     *
     * TODO: b/416215382 - if we get the SystemUI context here instead of the app's, and the package
     *   is not installed on the main profile, this will throw a [NameNotFoundException]. We should
     *   update the API to take a userId directly to avoid such issues.
     */
    @Throws(NameNotFoundException::class)
    @WorkerThread