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

Commit abcca634 authored by Amin Shaikh's avatar Amin Shaikh
Browse files

Update QS tile icon and label upon service binding.

CustomTile maintains the state of each Tile provided by a 3rd party
TileService. The Tile icon was not updated after the app updates. This
resulted in systemui retrieving the previous app version's resource id
being retrieved from the new app's apk, which resulted in incorrect
icons being displayed.

The fix is to simply set the Tile's icon and label when it is first
retrieved from a 3rd party TileSerice (TileService#onBind immediately
calls IQSService#getTile).

Change-Id: I8aca7acd2377695bbc592f673e63d88988f53ef9
Fixes: 112452836
Test: Manually from steps in b/112452836#5
parent 2bbd6c34
Loading
Loading
Loading
Loading
+17 −11
Original line number Diff line number Diff line
@@ -31,15 +31,15 @@ import android.provider.Settings;
import android.service.quicksettings.IQSTileService;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.IWindowManager;
import android.view.WindowManagerGlobal;
import com.android.internal.logging.MetricsLogger;

import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.systemui.Dependency;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.plugins.qs.QSTile;
import com.android.systemui.plugins.qs.QSTile.State;
import com.android.systemui.qs.tileimpl.QSTileImpl;
import com.android.systemui.qs.external.TileLifecycleManager.TileChangeListener;
@@ -68,9 +68,9 @@ public class CustomTile extends QSTileImpl<State> implements TileChangeListener
    private final TileServiceManager mServiceManager;
    private final int mUser;
    private android.graphics.drawable.Icon mDefaultIcon;
    private CharSequence mDefaultLabel;

    private boolean mListening;
    private boolean mBound;
    private boolean mIsTokenGranted;
    private boolean mIsShowingDialog;

@@ -79,7 +79,7 @@ public class CustomTile extends QSTileImpl<State> implements TileChangeListener
        mWindowManager = WindowManagerGlobal.getWindowManagerService();
        mComponent = ComponentName.unflattenFromString(action);
        mTile = new Tile();
        setTileIcon();
        updateDefaultTileAndIcon();
        mServiceManager = host.getTileServices().getTileWrapper(this);
        mService = mServiceManager.getTileService();
        mServiceManager.setTileChangeListener(this);
@@ -91,13 +91,14 @@ public class CustomTile extends QSTileImpl<State> implements TileChangeListener
        return CUSTOM_STALE_TIMEOUT + DateUtils.MINUTE_IN_MILLIS * mHost.indexOf(getTileSpec());
    }

    private void setTileIcon() {
    private void updateDefaultTileAndIcon() {
        try {
            PackageManager pm = mContext.getPackageManager();
            int flags = PackageManager.MATCH_DIRECT_BOOT_UNAWARE | PackageManager.MATCH_DIRECT_BOOT_AWARE;
            if (isSystemApp(pm)) {
                flags |= PackageManager.MATCH_DISABLED_COMPONENTS;
            }

            ServiceInfo info = pm.getServiceInfo(mComponent, flags);
            int icon = info.icon != 0 ? info.icon
                    : info.applicationInfo.icon;
@@ -109,12 +110,16 @@ public class CustomTile extends QSTileImpl<State> implements TileChangeListener
            if (updateIcon) {
                mTile.setIcon(mDefaultIcon);
            }
            // Update the label if there is no label.
            if (mTile.getLabel() == null) {
                mTile.setLabel(info.loadLabel(pm));
            // Update the label if there is no label or it is the default label.
            boolean updateLabel = mTile.getLabel() == null
                    || TextUtils.equals(mTile.getLabel(), mDefaultLabel);
            mDefaultLabel = info.loadLabel(pm);
            if (updateLabel) {
                mTile.setLabel(mDefaultLabel);
            }
        } catch (Exception e) {
        } catch (PackageManager.NameNotFoundException e) {
            mDefaultIcon = null;
            mDefaultLabel = null;
        }
    }

@@ -148,7 +153,7 @@ public class CustomTile extends QSTileImpl<State> implements TileChangeListener

    @Override
    public void onTileChanged(ComponentName tile) {
        setTileIcon();
        updateDefaultTileAndIcon();
    }

    @Override
@@ -170,6 +175,7 @@ public class CustomTile extends QSTileImpl<State> implements TileChangeListener
    }

    public Tile getQsTile() {
        updateDefaultTileAndIcon();
        return mTile;
    }

@@ -199,7 +205,7 @@ public class CustomTile extends QSTileImpl<State> implements TileChangeListener
        mListening = listening;
        try {
            if (listening) {
                setTileIcon();
                updateDefaultTileAndIcon();
                refreshState();
                if (!mServiceManager.isActiveTile()) {
                    mServiceManager.setBindRequested(true);