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

Commit 2d50a68e authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

[AOD RONs] Show profile badge

Fix: 402147648
Test: manual, post a RON from work profile app
Flag: android.app.ui_rich_ongoing
Change-Id: I3ba415f9910674d9a8c79d6039ee5157f6987ef9
parent 9811256f
Loading
Loading
Loading
Loading
+47 −41
Original line number Diff line number Diff line
@@ -3248,6 +3248,52 @@ public class Notification implements Parcelable
        }
    }
    /**
     * Get profile badge to be shown in the header (e.g. the briefcase icon for work profile).
     *
     * @param context the package context used to obtain the badge
     * @hide
     */
    public static Bitmap getProfileBadge(Context context) {
        Drawable badge = getProfileBadgeDrawable(context);
        if (badge == null) {
            return null;
        }
        final int size = context.getResources().getDimensionPixelSize(
                Flags.notificationsRedesignTemplates()
                        ? R.dimen.notification_2025_badge_size
                        : R.dimen.notification_badge_size);
        Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        badge.setBounds(0, 0, size, size);
        badge.draw(canvas);
        return bitmap;
    }
    private static Drawable getProfileBadgeDrawable(Context context) {
        if (context.getUserId() == UserHandle.USER_SYSTEM) {
            // This user can never be a badged profile,
            // and also includes USER_ALL system notifications.
            return null;
        }
        // Note: This assumes that the current user can read the profile badge of the
        // originating user.
        DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
        return dpm.getResources().getDrawable(
                getUpdatableProfileBadgeId(context), SOLID_COLORED, NOTIFICATION,
                () -> getDefaultProfileBadgeDrawable(context));
    }
    private static String getUpdatableProfileBadgeId(Context context) {
        return context.getSystemService(UserManager.class).isManagedProfile()
                ? WORK_PROFILE_ICON : UNDEFINED;
    }
    private static Drawable getDefaultProfileBadgeDrawable(Context context) {
        return context.getPackageManager().getUserBadgeForDensityNoBackground(
                new UserHandle(context.getUserId()), 0);
    }
    /**
     * @hide
     */
@@ -5954,48 +6000,8 @@ public class Notification implements Parcelable
                    PorterDuff.Mode.SRC_ATOP);
        }
        private Drawable getProfileBadgeDrawable() {
            if (mContext.getUserId() == UserHandle.USER_SYSTEM) {
                // This user can never be a badged profile,
                // and also includes USER_ALL system notifications.
                return null;
            }
            // Note: This assumes that the current user can read the profile badge of the
            // originating user.
            DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
            return dpm.getResources().getDrawable(
                    getUpdatableProfileBadgeId(), SOLID_COLORED, NOTIFICATION,
                    this::getDefaultProfileBadgeDrawable);
        }
        private String getUpdatableProfileBadgeId() {
            return mContext.getSystemService(UserManager.class).isManagedProfile()
                    ? WORK_PROFILE_ICON : UNDEFINED;
        }
        private Drawable getDefaultProfileBadgeDrawable() {
            return mContext.getPackageManager().getUserBadgeForDensityNoBackground(
                    new UserHandle(mContext.getUserId()), 0);
        }
        private Bitmap getProfileBadge() {
            Drawable badge = getProfileBadgeDrawable();
            if (badge == null) {
                return null;
            }
            final int size = mContext.getResources().getDimensionPixelSize(
                    Flags.notificationsRedesignTemplates()
                            ? R.dimen.notification_2025_badge_size
                            : R.dimen.notification_badge_size);
            Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            badge.setBounds(0, 0, size, size);
            badge.draw(canvas);
            return bitmap;
        }
        private void bindProfileBadge(RemoteViews contentView, StandardTemplateParams p) {
            Bitmap profileBadge = getProfileBadge();
            Bitmap profileBadge = Notification.getProfileBadge(mContext);
            if (profileBadge != null) {
                contentView.setImageViewBitmap(R.id.profile_badge, profileBadge);
+7 −1
Original line number Diff line number Diff line
@@ -648,7 +648,13 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {
        redactionType: Int = REDACTION_TYPE_PUBLIC,
    ): PromotedNotificationContentModels? {
        val recoveredBuilder = Notification.Builder(context, entry.sbn.notification)
        return underTest.extractContent(entry, recoveredBuilder, redactionType, imageModelProvider)
        return underTest.extractContent(
            entry,
            recoveredBuilder,
            redactionType,
            imageModelProvider,
            context,
        )
    }

    private fun Kosmos.createEntry(
+10 −0
Original line number Diff line number Diff line
@@ -460,6 +460,7 @@ private class AODPromotedNotificationViewUpdater(root: View) {
        updateTextView(headerTextSecondary, content.subText)
        updateTitle(titleView, content)
        updateTimeAndChronometer(content)
        updateProfileBadge(content)

        updateHeaderDividers(content, hideTitle = !hasTitle, hideAppName = hideAppName)

@@ -495,6 +496,7 @@ private class AODPromotedNotificationViewUpdater(root: View) {
    ) {
        updateAppName(content, forceHide = collapsed)
        updateTimeAndChronometer(content)
        updateProfileBadge(content)

        updateImageView(verificationIcon, content.verificationIcon)
        updateTextView(verificationText, content.verificationText)
@@ -571,6 +573,14 @@ private class AODPromotedNotificationViewUpdater(root: View) {
        chronometer?.isVisible = (content.time is When.Chronometer)
    }

    private fun updateProfileBadge(content: PromotedNotificationContentModel) {
        if (content.profileBadgeBitmap != null) {
            profileBadge?.setImageBitmap(content.profileBadgeBitmap)
            profileBadge?.visibility = VISIBLE
            profileBadge?.setColorFilter(PrimaryText.colorInt, PorterDuff.Mode.SRC_IN)
        }
    }

    private fun updateNotifIcon(
        smallIconView: CachingIconView?,
        notifIcon: PromotedNotificationContentModel.NotifIcon?,
+2 −2
Original line number Diff line number Diff line
@@ -148,7 +148,7 @@ constructor(
        publicBuilder.appName = privateModel.appName
        publicBuilder.time = privateModel.time
        publicBuilder.lastAudiblyAlertedMs = privateModel.lastAudiblyAlertedMs
        publicBuilder.profileBadgeResId = privateModel.profileBadgeResId
        publicBuilder.profileBadgeBitmap = privateModel.profileBadgeBitmap
        publicBuilder.colors = privateModel.colors
    }

@@ -222,7 +222,7 @@ constructor(
        contentBuilder.time = notification.extractWhen()
        contentBuilder.shortCriticalText = notification.shortCriticalText()
        contentBuilder.lastAudiblyAlertedMs = lastAudiblyAlertedMs
        contentBuilder.profileBadgeResId = null // TODO
        contentBuilder.profileBadgeBitmap = Notification.getProfileBadge(packageContext)
        contentBuilder.title = notification.title(recoveredBuilder.style?.javaClass)
        contentBuilder.text = notification.text(recoveredBuilder.style?.javaClass)
        contentBuilder.skeletonLargeIcon = notification.skeletonLargeIcon(imageModelProvider)
+4 −5
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
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
@@ -76,7 +75,7 @@ data class PromotedNotificationContentModel(
     */
    val time: When?,
    val lastAudiblyAlertedMs: Long,
    @DrawableRes val profileBadgeResId: Int?,
    val profileBadgeBitmap: Bitmap?,
    val title: CharSequence?,
    val text: CharSequence?,
    val skeletonLargeIcon: ImageModel?,
@@ -100,7 +99,7 @@ data class PromotedNotificationContentModel(
        var time: When? = null
        var shortCriticalText: String? = null
        var lastAudiblyAlertedMs: Long = 0L
        @DrawableRes var profileBadgeResId: Int? = null
        var profileBadgeBitmap: Bitmap? = null
        var title: CharSequence? = null
        var text: CharSequence? = null
        var skeletonLargeIcon: ImageModel? = null
@@ -126,7 +125,7 @@ data class PromotedNotificationContentModel(
                shortCriticalText = shortCriticalText,
                time = time,
                lastAudiblyAlertedMs = lastAudiblyAlertedMs,
                profileBadgeResId = profileBadgeResId,
                profileBadgeBitmap = profileBadgeBitmap,
                title = title,
                text = text,
                skeletonLargeIcon = skeletonLargeIcon,
@@ -190,7 +189,7 @@ data class PromotedNotificationContentModel(
            "shortCriticalText=$shortCriticalText, " +
            "time=$time, " +
            "lastAudiblyAlertedMs=$lastAudiblyAlertedMs, " +
            "profileBadgeResId=$profileBadgeResId, " +
            "profileBadgeBitmap=$profileBadgeBitmap, " +
            "title=${title?.toRedactedString()}, " +
            "text=${text?.toRedactedString()}, " +
            "skeletonLargeIcon=${skeletonLargeIcon?.toRedactedString()}, " +