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

Commit c56b8800 authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

Fall back to small icon when AppIconProvider throws

The PromotedNotificationContentExtractor is passing in the SystemUI
context instead of the app context to fetch icons, which leads to
NameNotFoundException being thrown if the app is not installed in the
main profile. This is a temporary workaround to just fall back to the
small icon for AOD RONs when that happens.

Fix: 414830446
Flag: android.app.ui_rich_ongoing
Test: manual, install Notify only on work profile and post a RON; verify it doesn't crash
Change-Id: I30829c33196a807efe806f421418e654400c1e2b
parent 495128ff
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