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

Commit be459eaf authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Fix badged apps in Privacy dialog

Badged icons are retrieved for managed profiles

Test: created a managed profile and launched Work camera
Fixes: 122918402
Change-Id: I089a465038b85f761a1b74adeaed684b8214ceff
parent 8e95f0bf
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ import android.content.Context
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import android.os.UserHandle
import android.util.IconDrawableFactory
import com.android.systemui.R

typealias Privacy = PrivacyType
@@ -46,14 +48,21 @@ data class PrivacyApplication(val packageName: String, val uid: Int, val context

    private val applicationInfo: ApplicationInfo? by lazy {
        try {
            context.packageManager.getApplicationInfo(packageName, 0)
            val userHandle = UserHandle.getUserHandleForUid(uid)
            context.createPackageContextAsUser(packageName, 0, userHandle).getPackageManager()
                    .getApplicationInfo(packageName, 0)
        } catch (_: PackageManager.NameNotFoundException) {
            null
        }
    }
    val icon: Drawable by lazy {
        applicationInfo?.let {
            context.packageManager.getApplicationIcon(it)
            try {
                val iconFactory = IconDrawableFactory.newInstance(context, true)
                iconFactory.getBadgedIcon(it, UserHandle.getUserId(uid))
            } catch (_: Exception) {
                null
            }
        } ?: context.getDrawable(android.R.drawable.sym_def_app_icon)
    }