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

Commit 9811256f authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

[AOD RONs] Use packageContext instead of SystemUI context

This fixes an issue with fetching the app icon, but also allows us to do
other things with the context (like obtaining the profile badge, see
follow-up CL).

Bug: 414830446
Bug: 402147648
Test: post RON from app only installed on work profile, verify it doesn't crash
Flag: android.app.ui_rich_ongoing
Change-Id: I4be70d14603e631ae0aba3f627b765f318027fd6
parent b3eb540d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -324,7 +324,8 @@ public interface NotificationsModule {
        if (PromotedNotificationContentModel.featureFlagEnabled()) {
            return implProvider.get();
        } else {
            return (entry, recoveredBuilder, redactionType, imageModelProvider) -> null;
            return (entry, recoveredBuilder, redactionType, imageModelProvider,
                    packageContext) -> null;
        }
    }

+14 −17
Original line number Diff line number Diff line
@@ -36,12 +36,10 @@ 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
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.shade.ShadeDisplayAware
import com.android.systemui.statusbar.NotificationLockscreenUserManager.REDACTION_TYPE_NONE
import com.android.systemui.statusbar.NotificationLockscreenUserManager.RedactionType
import com.android.systemui.statusbar.notification.collection.NotificationEntry
@@ -69,6 +67,7 @@ interface PromotedNotificationContentExtractor {
        recoveredBuilder: Notification.Builder,
        @RedactionType redactionType: Int,
        imageModelProvider: ImageModelProvider,
        packageContext: Context,
    ): PromotedNotificationContentModels?
}

@@ -76,7 +75,6 @@ interface PromotedNotificationContentExtractor {
class PromotedNotificationContentExtractorImpl
@Inject
constructor(
    @ShadeDisplayAware private val context: Context,
    private val notificationIconStyleProvider: NotificationIconStyleProvider,
    private val appIconProvider: AppIconProvider,
    private val skeletonImageTransform: SkeletonImageTransform,
@@ -88,6 +86,7 @@ constructor(
        recoveredBuilder: Notification.Builder,
        @RedactionType redactionType: Int,
        imageModelProvider: ImageModelProvider,
        packageContext: Context,
    ): PromotedNotificationContentModels? {
        if (!PromotedNotificationContentModel.featureFlagEnabled()) {
            if (LOG_NOT_EXTRACTED) {
@@ -118,6 +117,7 @@ constructor(
                recoveredBuilder = recoveredBuilder,
                lastAudiblyAlertedMs = entry.lastAudiblyAlertedMs,
                imageModelProvider = imageModelProvider,
                packageContext = packageContext,
            )
        val publicVersion =
            if (redactionType == REDACTION_TYPE_NONE) {
@@ -128,6 +128,7 @@ constructor(
                        privateModel = privateVersion,
                        publicNotification = publicNotification,
                        imageModelProvider = imageModelProvider,
                        packageContext = packageContext,
                    )
                } ?: createDefaultPublicVersion(privateModel = privateVersion)
            }
@@ -166,6 +167,7 @@ constructor(
        privateModel: PromotedNotificationContentModel,
        publicNotification: Notification,
        imageModelProvider: ImageModelProvider,
        packageContext: Context,
    ): PromotedNotificationContentModel =
        PromotedNotificationContentModel.Builder(key = privateModel.identity.key)
            .also { publicBuilder ->
@@ -198,6 +200,7 @@ constructor(
        recoveredBuilder: Notification.Builder,
        lastAudiblyAlertedMs: Long,
        imageModelProvider: ImageModelProvider,
        packageContext: Context,
    ): PromotedNotificationContentModel {
        val notification = sbn.notification

@@ -210,10 +213,11 @@ constructor(
            notification.extras.getBoolean(EXTRA_WAS_AUTOMATICALLY_PROMOTED, false)

        contentBuilder.skeletonNotifIcon =
            sbn.skeletonAppIcon() ?: notification.skeletonSmallIcon(imageModelProvider)
            sbn.skeletonAppIcon(packageContext)
                ?: notification.skeletonSmallIcon(imageModelProvider)

        contentBuilder.iconLevel = notification.iconLevel
        contentBuilder.appName = notification.loadHeaderAppName(context)
        contentBuilder.appName = notification.loadHeaderAppName(packageContext)
        contentBuilder.subText = notification.subText()
        contentBuilder.time = notification.extractWhen()
        contentBuilder.shortCriticalText = notification.shortCriticalText()
@@ -241,19 +245,12 @@ constructor(
    ): NotifIcon.SmallIcon? =
        imageModelProvider.getImageModel(smallIcon, SmallSquare)?.let { NotifIcon.SmallIcon(it) }

    private fun StatusBarNotification.skeletonAppIcon(): NotifIcon.AppIcon? {
    private fun StatusBarNotification.skeletonAppIcon(packageContext: Context): NotifIcon.AppIcon? {
        if (!android.app.Flags.notificationsRedesignAppIcons()) return null
        if (!notificationIconStyleProvider.shouldShowAppIcon(this, context)) return null
        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
        }
        if (!notificationIconStyleProvider.shouldShowAppIcon(this, packageContext)) return null
        return NotifIcon.AppIcon(
            appIconProvider.getOrFetchSkeletonAppIcon(packageName, packageContext)
        )
    }

    private fun Notification.title(): CharSequence? = getCharSequenceExtraUnlessEmpty(EXTRA_TITLE)
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.statusbar.notification.promoted.shared.model
import android.annotation.CurrentTimeMillisLong
import android.annotation.DrawableRes
import android.annotation.ElapsedRealtimeLong
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import androidx.annotation.ColorInt
import com.android.internal.widget.NotificationProgressModel
+2 −1
Original line number Diff line number Diff line
@@ -1390,7 +1390,8 @@ public class NotificationContentInflater implements NotificationRowContentBinder
                        result.mRowImageInflater.useForContentModel();
                final PromotedNotificationContentModels promotedContent =
                        mPromotedNotificationContentExtractor.extractContent(mEntry,
                                recoveredBuilder, mBindParams.redactionType, imageModelProvider);
                                recoveredBuilder, mBindParams.redactionType, imageModelProvider,
                                packageContext);
                mLogger.logAsyncTaskProgress(logKey, "extracted promoted notification content: "
                        + (promotedContent != null ? promotedContent.toRedactedString() : null));

+1 −0
Original line number Diff line number Diff line
@@ -706,6 +706,7 @@ constructor(
                            builder,
                            bindParams.redactionType,
                            imageModelProvider,
                            packageContext,
                        )
                        .also {
                            logger.logAsyncTaskProgress(
Loading