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

Commit e7e4b3d8 authored by Jason Monk's avatar Jason Monk Committed by Android (Google) Code Review
Browse files

Merge "Don't cache QS custom tiles across users" into nyc-dev

parents 95e412b4 1ffa11b9
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -58,6 +58,7 @@ public class CustomTile extends QSTile<QSTile.State> {
    private final IBinder mToken = new Binder();
    private final IBinder mToken = new Binder();
    private final IQSTileService mService;
    private final IQSTileService mService;
    private final TileServiceManager mServiceManager;
    private final TileServiceManager mServiceManager;
    private final int mUser;


    private boolean mListening;
    private boolean mListening;
    private boolean mBound;
    private boolean mBound;
@@ -71,6 +72,7 @@ public class CustomTile extends QSTile<QSTile.State> {
        mServiceManager = host.getTileServices().getTileWrapper(this);
        mServiceManager = host.getTileServices().getTileWrapper(this);
        mService = mServiceManager.getTileService();
        mService = mServiceManager.getTileService();
        mTile = new Tile(mComponent);
        mTile = new Tile(mComponent);
        mUser = ActivityManager.getCurrentUser();
        try {
        try {
            PackageManager pm = mContext.getPackageManager();
            PackageManager pm = mContext.getPackageManager();
            ServiceInfo info = pm.getServiceInfo(mComponent, 0);
            ServiceInfo info = pm.getServiceInfo(mComponent, 0);
@@ -86,6 +88,10 @@ public class CustomTile extends QSTile<QSTile.State> {
        }
        }
    }
    }


    public int getUser() {
        return mUser;
    }

    public ComponentName getComponent() {
    public ComponentName getComponent() {
        return mComponent;
        return mComponent;
    }
    }
+4 −3
Original line number Original line Diff line number Diff line
@@ -85,6 +85,7 @@ public class TileLifecycleManager extends BroadcastReceiver implements
        mHandler = handler;
        mHandler = handler;
        mIntent = intent;
        mIntent = intent;
        mUser = user;
        mUser = user;
        if (DEBUG) Log.d(TAG, "Creating " + mIntent + " " + mUser);
    }
    }


    public ComponentName getComponent() {
    public ComponentName getComponent() {
@@ -116,13 +117,13 @@ public class TileLifecycleManager extends BroadcastReceiver implements
            if (!checkComponentState()) {
            if (!checkComponentState()) {
                return;
                return;
            }
            }
            if (DEBUG) Log.d(TAG, "Binding service " + mIntent);
            if (DEBUG) Log.d(TAG, "Binding service " + mIntent + " " + mUser);
            mBindTryCount++;
            mBindTryCount++;
            mContext.bindServiceAsUser(mIntent, this,
            mContext.bindServiceAsUser(mIntent, this,
                    Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE,
                    Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE,
                    mUser);
                    mUser);
        } else {
        } else {
            if (DEBUG) Log.d(TAG, "Unbinding service " + mIntent);
            if (DEBUG) Log.d(TAG, "Unbinding service " + mIntent + " " + mUser);
            // Give it another chance next time it needs to be bound, out of kindness.
            // Give it another chance next time it needs to be bound, out of kindness.
            mBindTryCount = 0;
            mBindTryCount = 0;
            mWrapper = null;
            mWrapper = null;
@@ -350,7 +351,7 @@ public class TileLifecycleManager extends BroadcastReceiver implements


    @Override
    @Override
    public void onClick(IBinder iBinder) {
    public void onClick(IBinder iBinder) {
        if (DEBUG) Log.d(TAG, "onClick " + iBinder);
        if (DEBUG) Log.d(TAG, "onClick " + iBinder + " " + mUser);
        if (mWrapper == null || !mWrapper.onClick(iBinder)) {
        if (mWrapper == null || !mWrapper.onClick(iBinder)) {
            mClickBinder = iBinder;
            mClickBinder = iBinder;
            queueMessage(MSG_ON_CLICK);
            queueMessage(MSG_ON_CLICK);
+8 −4
Original line number Original line Diff line number Diff line
@@ -114,6 +114,7 @@ public final class QSTileHost implements QSTile.Host, Tunable {
    private final ManagedProfileController mProfileController;
    private final ManagedProfileController mProfileController;
    private final NextAlarmController mNextAlarmController;
    private final NextAlarmController mNextAlarmController;
    private View mHeader;
    private View mHeader;
    private int mCurrentUser;


    public QSTileHost(Context context, PhoneStatusBar statusBar,
    public QSTileHost(Context context, PhoneStatusBar statusBar,
            BluetoothController bluetooth, LocationController location,
            BluetoothController bluetooth, LocationController location,
@@ -320,7 +321,8 @@ public final class QSTileHost implements QSTile.Host, Tunable {
        }
        }
        if (DEBUG) Log.d(TAG, "Recreating tiles");
        if (DEBUG) Log.d(TAG, "Recreating tiles");
        final List<String> tileSpecs = loadTileSpecs(mContext, newValue);
        final List<String> tileSpecs = loadTileSpecs(mContext, newValue);
        if (tileSpecs.equals(mTileSpecs)) return;
        int currentUser = ActivityManager.getCurrentUser();
        if (tileSpecs.equals(mTileSpecs) && currentUser == mCurrentUser) return;
        for (Map.Entry<String, QSTile<?>> tile : mTiles.entrySet()) {
        for (Map.Entry<String, QSTile<?>> tile : mTiles.entrySet()) {
            if (!tileSpecs.contains(tile.getKey())) {
            if (!tileSpecs.contains(tile.getKey())) {
                if (DEBUG) Log.d(TAG, "Destroying tile: " + tile.getKey());
                if (DEBUG) Log.d(TAG, "Destroying tile: " + tile.getKey());
@@ -329,15 +331,16 @@ public final class QSTileHost implements QSTile.Host, Tunable {
        }
        }
        final LinkedHashMap<String, QSTile<?>> newTiles = new LinkedHashMap<>();
        final LinkedHashMap<String, QSTile<?>> newTiles = new LinkedHashMap<>();
        for (String tileSpec : tileSpecs) {
        for (String tileSpec : tileSpecs) {
            if (mTiles.containsKey(tileSpec)) {
            QSTile<?> tile = mTiles.get(tileSpec);
            QSTile<?> tile = mTiles.get(tileSpec);
            if (tile != null && (!(tile instanceof CustomTile)
                    || ((CustomTile) tile).getUser() == currentUser)) {
                if (DEBUG) Log.d(TAG, "Adding " + tile);
                if (DEBUG) Log.d(TAG, "Adding " + tile);
                tile.removeCallbacks();
                tile.removeCallbacks();
                newTiles.put(tileSpec, tile);
                newTiles.put(tileSpec, tile);
            } else {
            } else {
                if (DEBUG) Log.d(TAG, "Creating tile: " + tileSpec);
                if (DEBUG) Log.d(TAG, "Creating tile: " + tileSpec);
                try {
                try {
                    QSTile<?> tile = createTile(tileSpec);
                    tile = createTile(tileSpec);
                    if (tile != null && tile.isAvailable()) {
                    if (tile != null && tile.isAvailable()) {
                        tile.setTileSpec(tileSpec);
                        tile.setTileSpec(tileSpec);
                        newTiles.put(tileSpec, tile);
                        newTiles.put(tileSpec, tile);
@@ -347,6 +350,7 @@ public final class QSTileHost implements QSTile.Host, Tunable {
                }
                }
            }
            }
        }
        }
        mCurrentUser = currentUser;
        mTileSpecs.clear();
        mTileSpecs.clear();
        mTileSpecs.addAll(tileSpecs);
        mTileSpecs.addAll(tileSpecs);
        mTiles.clear();
        mTiles.clear();