From 21582d4643e3e999b7a98e232f4a9774331a3ed8 Mon Sep 17 00:00:00 2001 From: Jason Monk Date: Thu, 21 Apr 2016 16:14:27 -0400 Subject: [PATCH] QS: Use current tile state when removing custom tiles Change-Id: If12415c051239348261386fb23e88d6725767ba0 Fixes: 27912532 --- .../qs/customize/TileQueryHelper.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/qs/customize/TileQueryHelper.java b/packages/SystemUI/src/com/android/systemui/qs/customize/TileQueryHelper.java index 9bc85c8a83951..fb76918c644de 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/customize/TileQueryHelper.java +++ b/packages/SystemUI/src/com/android/systemui/qs/customize/TileQueryHelper.java @@ -54,7 +54,7 @@ public class TileQueryHelper { // TODO: Live? } - private void addSystemTiles(QSTileHost host) { + private void addSystemTiles(final QSTileHost host) { String possible = mContext.getString(R.string.quick_settings_tiles_default) + ",hotspot,inversion,saver,work,cast,night"; String[] possibleTiles = possible.split(","); @@ -93,7 +93,7 @@ public class TileQueryHelper { mainHandler.post(new Runnable() { @Override public void run() { - new QueryTilesTask().execute(); + new QueryTilesTask().execute(host.getTiles()); } }); } @@ -133,9 +133,10 @@ public class TileQueryHelper { public boolean isSystem; } - private class QueryTilesTask extends AsyncTask> { + private class QueryTilesTask extends + AsyncTask>, Void, Collection> { @Override - protected Collection doInBackground(Void... params) { + protected Collection doInBackground(Collection>... params) { List tiles = new ArrayList<>(); PackageManager pm = mContext.getPackageManager(); List services = pm.queryIntentServicesAsUser( @@ -143,7 +144,13 @@ public class TileQueryHelper { for (ResolveInfo info : services) { String packageName = info.serviceInfo.packageName; ComponentName componentName = new ComponentName(packageName, info.serviceInfo.name); + final CharSequence appLabel = info.serviceInfo.applicationInfo.loadLabel(pm); String spec = CustomTile.toSpec(componentName); + State state = getState(params[0], spec); + if (state != null) { + addTile(spec, appLabel, state, false); + continue; + } if (info.serviceInfo.icon == 0) { continue; } @@ -157,12 +164,22 @@ public class TileQueryHelper { icon.mutate(); icon.setTint(mContext.getColor(android.R.color.white)); CharSequence label = info.serviceInfo.loadLabel(pm); - final CharSequence appLabel = info.serviceInfo.applicationInfo.loadLabel(pm); addTile(spec, icon, label != null ? label.toString() : "null", appLabel, mContext); } return tiles; } + private State getState(Collection> tiles, String spec) { + for (QSTile tile : tiles) { + if (spec.equals(tile.getTileSpec())) { + final QSTile.State state = tile.newTileState(); + tile.getState().copyTo(state); + return state; + } + } + return null; + } + @Override protected void onPostExecute(Collection result) { mTiles.addAll(result);