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

Commit d2274f84 authored by Jason Monk's avatar Jason Monk
Browse files

Fix animations for app QS tiles.

Use correct context for third party tile drawable creation, also
fix comparison so that AVDs don't animate multiple times.

Change-Id: Ifcf7b818304d6677eacf080ed8c22893c91fdf73
Fixes: 32779384
Test: Install app with animated app QS tile.
parent 1e40ddc4
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -486,10 +486,19 @@ public abstract class QSTile<TState extends State> {
        public Drawable getDrawable(Context context) {
            return mDrawable;
        }
    }

    public static class DrawableIconWithRes extends DrawableIcon {
        private final int mId;

        public DrawableIconWithRes(Drawable drawable, int id) {
            super(drawable);
            mId = id;
        }

        @Override
        public Drawable getInvisibleDrawable(Context context) {
            return mDrawable;
        public boolean equals(Object o) {
            return o instanceof DrawableIconWithRes && ((DrawableIconWithRes) o).mId == mId;
        }
    }

+15 −3
Original line number Diff line number Diff line
@@ -17,11 +17,14 @@ package com.android.systemui.qs.external;

import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.os.Binder;
import android.os.IBinder;
@@ -60,6 +63,7 @@ public class CustomTile extends QSTile<QSTile.State> implements TileChangeListen
    private final IQSTileService mService;
    private final TileServiceManager mServiceManager;
    private final int mUser;
    private Context mAppContext;
    private android.graphics.drawable.Icon mDefaultIcon;

    private boolean mListening;
@@ -77,6 +81,10 @@ public class CustomTile extends QSTile<QSTile.State> implements TileChangeListen
        mService = mServiceManager.getTileService();
        mServiceManager.setTileChangeListener(this);
        mUser = ActivityManager.getCurrentUser();
        try {
            mAppContext = mContext.createPackageContext(mComponent.getPackageName(), 0);
        } catch (NameNotFoundException e) {
        }
    }

    private void setTileIcon() {
@@ -278,16 +286,20 @@ public class CustomTile extends QSTile<QSTile.State> implements TileChangeListen
            tileState = Tile.STATE_UNAVAILABLE;
        }
        Drawable drawable;
        boolean mHasRes = false;
        android.graphics.drawable.Icon icon = mTile.getIcon();
        try {
            drawable = mTile.getIcon().loadDrawable(mContext);
            drawable = icon.loadDrawable(mAppContext);
            mHasRes = icon.getType() == android.graphics.drawable.Icon.TYPE_RESOURCE;
        } catch (Exception e) {
            Log.w(TAG, "Invalid icon, forcing into unavailable state");
            tileState = Tile.STATE_UNAVAILABLE;
            drawable = mDefaultIcon.loadDrawable(mContext);
            drawable = mDefaultIcon.loadDrawable(mAppContext);
        }
        int color = mContext.getColor(getColor(tileState));
        drawable.setTint(color);
        state.icon = new DrawableIcon(drawable);
        state.icon = mHasRes ? new DrawableIconWithRes(drawable, icon.getResId())
                : new DrawableIcon(drawable);
        state.label = mTile.getLabel();
        if (tileState == Tile.STATE_UNAVAILABLE) {
            state.label = new SpannableStringBuilder().append(state.label,