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

Commit 052e4b00 authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

Prototype replacing small icons with app icons.

This would replace the small icon in the notification shelf, AOD and
status bar, as well as the notification itself.

As this is just a simple prototype, it's not particularly optimal since
we just want to see what this will look like before investing time in a
proper solution.

Bug: 335211019
Test: manual; no automated tests yet as this is just a prototype
Flag: ACONFIG android.app.notifications_use_app_icon DEVELOPMENT
Change-Id: I0ae3070339efa4558cf97fad3a20b9fe69641cd8
parent fc05d49c
Loading
Loading
Loading
Loading
+32 −3
Original line number Diff line number Diff line
@@ -3077,6 +3077,25 @@ public class Notification implements Parcelable
        }
    }
    /**
     * @hide
     */
    public int loadHeaderAppIconRes(Context context) {
        ApplicationInfo info = null;
        if (extras.containsKey(EXTRA_BUILDER_APPLICATION_INFO)) {
            info = extras.getParcelable(
                    EXTRA_BUILDER_APPLICATION_INFO,
                    ApplicationInfo.class);
        }
        if (info == null) {
            info = context.getApplicationInfo();
        }
        if (info != null) {
            return info.icon;
        }
        return 0;
    }
    /**
     * Removes heavyweight parts of the Notification object for archival or for sending to
     * listeners when the full contents are not necessary.
@@ -5891,13 +5910,22 @@ public class Notification implements Parcelable
        }
        private void bindSmallIcon(RemoteViews contentView, StandardTemplateParams p) {
            if (mN.mSmallIcon == null && mN.icon != 0) {
            if (Flags.notificationsUseAppIcon()) {
                // Override small icon with app icon
                mN.mSmallIcon = Icon.createWithResource(mContext,
                        mN.loadHeaderAppIconRes(mContext));
            } else if (mN.mSmallIcon == null && mN.icon != 0) {
                mN.mSmallIcon = Icon.createWithResource(mContext, mN.icon);
            }
            contentView.setImageViewIcon(R.id.icon, mN.mSmallIcon);
            contentView.setInt(R.id.icon, "setImageLevel", mN.iconLevel);
            // Don't change color if we're using the app icon.
            if (!Flags.notificationsUseAppIcon()) {
                processSmallIconColor(mN.mSmallIcon, contentView, p);
            }
        }
        /**
         * @return true if the built notification will show the time or the chronometer; false
@@ -6696,7 +6724,8 @@ public class Notification implements Parcelable
         */
        private void processSmallIconColor(Icon smallIcon, RemoteViews contentView,
                StandardTemplateParams p) {
            boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon);
            boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext,
                    smallIcon);
            int color = getSmallIconColor(p);
            contentView.setInt(R.id.icon, "setBackgroundColor",
                    getBackgroundColor(p));
+11 −0
Original line number Diff line number Diff line
package: "android.app"
container: "system"

# Note: When adding a new flag here, consider including the word "notification(s)" in the flag name
# when appropriate, as it's not currently part of the namespace so it may not be obvious what the
# flag relates to.

flag {
  name: "modes_api"
  is_exported: true
@@ -41,6 +45,13 @@ flag {
  bug: "281044385"
}

flag {
  name: "notifications_use_app_icon"
  namespace: "systemui"
  description: "Experiment to replace the small icon in a notification with the app icon."
  bug: "335211019"
}

flag {
  name: "keyguard_private_notifications"
  namespace: "systemui"
+5 −5
Original line number Diff line number Diff line
@@ -39,13 +39,13 @@ import com.android.systemui.statusbar.notification.InflationException
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection
import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener
import java.util.concurrent.ConcurrentHashMap
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.concurrent.ConcurrentHashMap
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext

/**
 * Inflates and updates icons associated with notifications
@@ -239,8 +239,8 @@ constructor(

        val sbi = icon.toStatusBarIcon(entry)

        // Cache if important conversation.
        if (isImportantConversation(entry)) {
        // Cache if important conversation or app icon.
        if (isImportantConversation(entry) || android.app.Flags.notificationsUseAppIcon()) {
            if (showPeopleAvatar) {
                entry.icons.peopleAvatarDescriptor = sbi
            } else {
+16 −9
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.graphics.Rect
import android.view.View
import com.android.app.tracing.traceSection
import com.android.internal.util.ContrastColorUtil
import com.android.systemui.Flags
import com.android.systemui.res.R
import com.android.systemui.statusbar.StatusBarIconView
import com.android.systemui.statusbar.StatusBarIconView.NO_COLOR
@@ -34,11 +35,14 @@ object StatusBarIconViewBinder {
    //  view-model (which, at the time of this writing, does not yet exist).

    suspend fun bindColor(view: StatusBarIconView, color: Flow<Int>) {
        // Don't change the icon color if an app icon experiment is enabled.
        if (!android.app.Flags.notificationsUseAppIcon()) {
            color.collectTracingEach("SBIV#bindColor") { color ->
                view.staticDrawableColor = color
                view.setDecorColor(color)
            }
        }
    }

    suspend fun bindTintAlpha(view: StatusBarIconView, tintAlpha: Flow<Float>) {
        tintAlpha.collectTracingEach("SBIV#bindTintAlpha") { amt -> view.setTintAlpha(amt) }
@@ -53,6 +57,8 @@ object StatusBarIconViewBinder {
        iconColors: Flow<NotificationIconColors>,
        contrastColorUtil: ContrastColorUtil,
    ) {
        // Don't change the icon color if an app icon experiment is enabled.
        if (!android.app.Flags.notificationsUseAppIcon()) {
            iconColors.collectTracingEach("SBIV#bindIconColors") { colors ->
                val isPreL = java.lang.Boolean.TRUE == view.getTag(R.id.icon_is_pre_L)
                val isColorized = !isPreL || NotificationUtils.isGrayscale(view, contrastColorUtil)
@@ -62,6 +68,7 @@ object StatusBarIconViewBinder {
            }
        }
    }
}

private val View.viewBounds: Rect
    get() {