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

Commit 33b3d738 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Fix notification app icon badging cloned and private profiles.

Fixes: 416218108
Test: manual testing of notifications with private space
Flag: android.app.notifications_redesign_app_icons
Change-Id: I6d3a45a252735e0df07f5710ca08b6b3da9dda93
parent 5d914b59
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -699,8 +699,10 @@ public class Utils {
        return networkRegWwan.isInService();
    }

    /** Get the corresponding adaptive icon drawable. */
    public static Drawable getBadgedIcon(Context context, Drawable icon, UserHandle user) {
    /** Get the UserIconInfo required to badge an icon by looking up the UserInfo. */
    @NonNull
    public static UserIconInfo fetchUserIconInfo(@NonNull Context context,
            @NonNull UserHandle user) {
        int userType = UserIconInfo.TYPE_MAIN;
        try {
            UserInfo ui =
@@ -717,10 +719,17 @@ public class Utils {
        } catch (Exception e) {
            // Ignore
        }
        return new UserIconInfo(user, userType);
    }

    /** Get the corresponding adaptive icon drawable. */
    @NonNull
    public static Drawable getBadgedIcon(@NonNull Context context, @NonNull Drawable icon,
            @NonNull UserHandle user) {
        try (IconFactory iconFactory = IconFactory.obtain(context)) {
            return iconFactory
                    .createBadgedIconBitmap(
                            icon, new IconOptions().setUser(new UserIconInfo(user, userType)))
                            icon, new IconOptions().setUser(fetchUserIconInfo(context, user)))
                    .newIcon(context);
        }
    }
+10 −16
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.os.UserHandle
import android.os.UserManager
import android.util.Log
import com.android.internal.R
import com.android.launcher3.icons.BaseIconFactory
@@ -34,6 +33,7 @@ import com.android.launcher3.icons.BaseIconFactory.IconOptions
import com.android.launcher3.icons.BitmapInfo
import com.android.launcher3.icons.mono.MonoIconThemeController
import com.android.launcher3.util.UserIconInfo
import com.android.settingslib.Utils
import com.android.systemui.Dumpable
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dump.DumpManager
@@ -217,7 +217,7 @@ constructor(

    private fun iconOptions(userHandle: UserHandle, allowProfileBadge: Boolean): IconOptions {
        return IconOptions().apply {
            setUser(userIconInfo(userHandle, allowProfileBadge))
            setUser(userIconInfo(userHandle, allowProfileBadge = allowProfileBadge))
            setBitmapGenerationMode(BaseIconFactory.MODE_HARDWARE)
            // This color will not be used, but we're just setting it so that the icon factory
            // doesn't try to extract colors from our bitmap (since it won't work, given it's a
@@ -226,19 +226,13 @@ constructor(
        }
    }

    private fun userIconInfo(userHandle: UserHandle, allowProfileBadge: Boolean): UserIconInfo {
        // TODO(b/423033161): use the correct badge for the type of managed profile
        val withWorkProfileBadge =
    private fun userIconInfo(userHandle: UserHandle, allowProfileBadge: Boolean): UserIconInfo =
        if (allowProfileBadge) {
                val userManager = sysuiContext.getSystemService(UserManager::class.java)
                userManager?.isManagedProfile(userHandle.identifier) == true
            // Look up the user to determine if it is a profile, and if so which badge to use
            Utils.fetchUserIconInfo(sysuiContext, userHandle)
        } else {
                false
            }
        return UserIconInfo(
            userHandle,
            if (withWorkProfileBadge) UserIconInfo.TYPE_WORK else UserIconInfo.TYPE_MAIN,
        )
            // For a main user the IconFactory does not add a badge
            UserIconInfo(/* user= */ userHandle, /* type= */ UserIconInfo.TYPE_MAIN)
        }

    override fun purgeCache(wantedPackages: Collection<String>) {