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

Commit 99fd277a authored by Yuta Yamada's avatar Yuta Yamada Committed by Yoshinori Hirano
Browse files

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
parent e011bf80
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -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() {
+11 −0
Original line number Diff line number Diff line
@@ -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) {