Fix memory leak of Dnd tile

The instance of Dnd tile leaks when user taps the edit button
of Quick Settings. To fix this issue, QSTile#destroy should be
called when the tile is no longer needed.

Bug: 32103239
Test: manual - go to Quick Settings -> Edit repeatedly

Change-Id: I9bc9ee836be5c8e46eb1ccd202bd5cc50070ef47
This commit is contained in:
Yuta Yamada
2016-10-06 17:40:19 +09:00
committed by Yoshinori Hirano
parent e011bf80c5
commit 99fd277a47
2 changed files with 16 additions and 1 deletions

View File

@@ -65,7 +65,10 @@ public class TileQueryHelper {
for (int i = 0; i < possibleTiles.length; i++) {
final String spec = possibleTiles[i];
final QSTile<?> tile = host.createTile(spec);
if (tile == null || !tile.isAvailable()) {
if (tile == null) {
continue;
} else if (!tile.isAvailable()) {
tile.destroy();
continue;
}
tile.setListening(this, true);
@@ -79,6 +82,7 @@ public class TileQueryHelper {
tile.getState().copyTo(state);
// Ignore the current state and get the generic label instead.
state.label = tile.getTileLabel();
tile.destroy();
mainHandler.post(new Runnable() {
@Override
public void run() {

View File

@@ -68,12 +68,23 @@ public class DndTile extends QSTile<QSTile.BooleanState> {
private boolean mListening;
private boolean mShowingDetail;
private boolean mReceiverRegistered;
public DndTile(Host host) {
super(host);
mController = host.getZenModeController();
mDetailAdapter = new DndDetailAdapter();
mContext.registerReceiver(mReceiver, new IntentFilter(ACTION_SET_VISIBLE));
mReceiverRegistered = true;
}
@Override
protected void handleDestroy() {
super.handleDestroy();
if (mReceiverRegistered) {
mContext.unregisterReceiver(mReceiver);
mReceiverRegistered = false;
}
}
public static void setVisible(Context context, boolean visible) {