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

Commit 6b2852e0 authored by Adrian Roos's avatar Adrian Roos
Browse files

SysUiLeaks: Detect leaks in TunerService

Bug: 34932615
Test: manual
Change-Id: I348c18dc4e5772637828c1f53f15c84ad4c39485
parent f6d562b8
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -47,8 +47,10 @@ import com.android.systemui.SystemUIApplication;
import com.android.systemui.settings.CurrentUserTracker;
import com.android.systemui.statusbar.phone.StatusBarIconController;
import com.android.systemui.statusbar.phone.SystemUIDialog;
import com.android.systemui.util.leak.LeakDetector;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;


@@ -65,6 +67,8 @@ public class TunerService {
    private final ArrayMap<Uri, String> mListeningUris = new ArrayMap<>();
    // Map of settings keys to the listener.
    private final HashMap<String, Set<Tunable>> mTunableLookup = new HashMap<>();
    // Set of all tunables, used for leak detection.
    private final HashSet<Tunable> mTunables = LeakDetector.ENABLED ? new HashSet<>() : null;
    private final Context mContext;

    private ContentResolver mContentResolver;
@@ -149,6 +153,10 @@ public class TunerService {
            mTunableLookup.put(key, new ArraySet<Tunable>());
        }
        mTunableLookup.get(key).add(tunable);
        if (LeakDetector.ENABLED) {
            mTunables.add(tunable);
            Dependency.get(LeakDetector.class).trackCollection(mTunables, "TunerService.mTunables");
        }
        Uri uri = Settings.Secure.getUriFor(key);
        if (!mListeningUris.containsKey(uri)) {
            mListeningUris.put(uri, key);
@@ -163,6 +171,9 @@ public class TunerService {
        for (Set<Tunable> list : mTunableLookup.values()) {
            list.remove(tunable);
        }
        if (LeakDetector.ENABLED) {
            mTunables.remove(tunable);
        }
    }

    protected void reregisterAll() {
+1 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ import java.util.Collection;
 */
public class LeakDetector implements Dumpable {

    private static final boolean ENABLED = Build.IS_DEBUGGABLE;
    public static final boolean ENABLED = Build.IS_DEBUGGABLE;

    private final TrackedCollections mTrackedCollections;
    private final TrackedGarbage mTrackedGarbage;