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

Commit 38030949 authored by Ioana Alexandru's avatar Ioana Alexandru Committed by Android (Google) Code Review
Browse files

Merge changes Id3eb0aa9,Ie82cd6e7 into main

* changes:
  Load monochrome app icon in SBIV
  Introduce StatusBarIcon.Type
parents 140691e2 fc14a2cc
Loading
Loading
Loading
Loading
+24 −4
Original line number Diff line number Diff line
@@ -22,7 +22,21 @@ import android.os.Parcelable;
import android.os.UserHandle;
import android.text.TextUtils;

import androidx.annotation.NonNull;

public class StatusBarIcon implements Parcelable {
    public enum Type {
        // Notification: the sender avatar for important conversations
        PeopleAvatar,
        // Notification: the monochrome version of the app icon if available; otherwise fall back to
        // the small icon
        MaybeMonochromeAppIcon,
        // Notification: the small icon from the notification
        NotifSmallIcon,
        // The wi-fi, cellular or battery icon.
        SystemIcon
    }

    public UserHandle user;
    public String pkg;
    public Icon icon;
@@ -30,9 +44,10 @@ public class StatusBarIcon implements Parcelable {
    public boolean visible = true;
    public int number;
    public CharSequence contentDescription;
    public Type type;

    public StatusBarIcon(UserHandle user, String resPackage, Icon icon, int iconLevel, int number,
            CharSequence contentDescription) {
            CharSequence contentDescription, Type type) {
        if (icon.getType() == Icon.TYPE_RESOURCE
                && TextUtils.isEmpty(icon.getResPackage())) {
            // This is an odd situation where someone's managed to hand us an icon without a
@@ -46,15 +61,17 @@ public class StatusBarIcon implements Parcelable {
        this.iconLevel = iconLevel;
        this.number = number;
        this.contentDescription = contentDescription;
        this.type = type;
    }

    public StatusBarIcon(String iconPackage, UserHandle user,
            int iconId, int iconLevel, int number,
            CharSequence contentDescription) {
            CharSequence contentDescription, Type type) {
        this(user, iconPackage, Icon.createWithResource(iconPackage, iconId),
                iconLevel, number, contentDescription);
                iconLevel, number, contentDescription, type);
    }

    @NonNull
    @Override
    public String toString() {
        return "StatusBarIcon(icon=" + icon
@@ -65,10 +82,11 @@ public class StatusBarIcon implements Parcelable {
                + " )";
    }

    @NonNull
    @Override
    public StatusBarIcon clone() {
        StatusBarIcon that = new StatusBarIcon(this.user, this.pkg, this.icon,
                this.iconLevel, this.number, this.contentDescription);
                this.iconLevel, this.number, this.contentDescription, this.type);
        that.visible = this.visible;
        return that;
    }
@@ -88,6 +106,7 @@ public class StatusBarIcon implements Parcelable {
        this.visible = in.readInt() != 0;
        this.number = in.readInt();
        this.contentDescription = in.readCharSequence();
        this.type = Type.valueOf(in.readString());
    }

    public void writeToParcel(Parcel out, int flags) {
@@ -98,6 +117,7 @@ public class StatusBarIcon implements Parcelable {
        out.writeInt(this.visible ? 1 : 0);
        out.writeInt(this.number);
        out.writeCharSequence(this.contentDescription);
        out.writeString(this.type.name());
    }

    public int describeContents() {
+2 −1
Original line number Diff line number Diff line
@@ -48,7 +48,8 @@ public class RegisterStatusBarResultTest {
        final String dumyIconKey = "dummyIcon1";
        final ArrayMap<String, StatusBarIcon> iconMap = new ArrayMap<>();
        iconMap.put(dumyIconKey, new StatusBarIcon("com.android.internal.statusbar.test",
                UserHandle.of(100), 123, 1, 2, "dummyIconDescription"));
                UserHandle.of(100), 123, 1, 2, "dummyIconDescription",
                StatusBarIcon.Type.SystemIcon));
        final LetterboxDetails letterboxDetails = new LetterboxDetails(
                /* letterboxInnerBounds= */ new Rect(1, 2, 3, 4),
                /* letterboxFullBounds= */ new Rect(5, 6, 7, 8),
+2 −1
Original line number Diff line number Diff line
@@ -44,7 +44,8 @@ public class StatusBarIconTest {
        final int dummyIconNumber = 2;
        final CharSequence dummyIconContentDescription = "dummyIcon";
        final StatusBarIcon original = new StatusBarIcon(dummyIconPackageName, dummyUserHandle,
                dummyIconId, dummyIconLevel, dummyIconNumber, dummyIconContentDescription);
                dummyIconId, dummyIconLevel, dummyIconNumber, dummyIconContentDescription,
                StatusBarIcon.Type.SystemIcon);

        final StatusBarIcon copy = clone(original);

+1 −1
Original line number Diff line number Diff line
@@ -332,7 +332,7 @@ public class TileServices extends IQSService.Stub {
                if (info.applicationInfo.isSystemApp()) {
                    final StatusBarIcon statusIcon = icon != null
                            ? new StatusBarIcon(userHandle, packageName, icon, 0, 0,
                            contentDescription)
                            contentDescription, StatusBarIcon.Type.SystemIcon)
                            : null;
                    final String slot = getStatusBarIconSlotName(componentName);
                    mMainHandler.post(new Runnable() {
+30 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.app.ActivityManager;
import android.app.Notification;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
@@ -35,6 +36,7 @@ import android.graphics.Color;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.os.Trace;
@@ -94,6 +96,8 @@ public class StatusBarIconView extends AnimatedImageView implements StatusIconDi
    public static final int STATE_DOT = 1;
    public static final int STATE_HIDDEN = 2;

    public static final float APP_ICON_SCALE = .75f;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({STATE_ICON, STATE_DOT, STATE_HIDDEN})
    public @interface VisibleState { }
@@ -499,7 +503,12 @@ public class StatusBarIconView extends AnimatedImageView implements StatusIconDi
            userId = UserHandle.USER_SYSTEM;
        }

        Drawable icon = statusBarIcon.icon.loadDrawableAsUser(context, userId);
        // Try to load the monochrome app icon if applicable
        Drawable icon = maybeGetMonochromeAppIcon(context, statusBarIcon);
        // Otherwise, just use the icon normally
        if (icon == null) {
            icon = statusBarIcon.icon.loadDrawableAsUser(context, userId);
        }

        TypedValue typedValue = new TypedValue();
        sysuiContext.getResources().getValue(R.dimen.status_bar_icon_scale_factor,
@@ -526,6 +535,26 @@ public class StatusBarIconView extends AnimatedImageView implements StatusIconDi
        return new ScalingDrawableWrapper(icon, scaleFactor);
    }

    @Nullable
    private Drawable maybeGetMonochromeAppIcon(Context context,
            StatusBarIcon statusBarIcon) {
        if (android.app.Flags.notificationsUseMonochromeAppIcon()
                && statusBarIcon.type == StatusBarIcon.Type.MaybeMonochromeAppIcon) {
            // Check if we have a monochrome app icon
            PackageManager pm = context.getPackageManager();
            Drawable appIcon = context.getApplicationInfo().loadIcon(pm);
            if (appIcon instanceof AdaptiveIconDrawable) {
                Drawable monochrome = ((AdaptiveIconDrawable) appIcon).getMonochrome();
                if (monochrome != null) {
                    setCropToPadding(true);
                    setScaleType(ScaleType.CENTER);
                    return new ScalingDrawableWrapper(monochrome, APP_ICON_SCALE);
                }
            }
        }
        return null;
    }

    public StatusBarIcon getStatusBarIcon() {
        return mIcon;
    }
Loading