diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 433dc3f92e5a1..365d991651214 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -196,6 +196,8 @@ import com.android.systemui.statusbar.policy.UserSwitcherController; import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; import com.android.systemui.statusbar.stack.NotificationStackScrollLayout.OnChildLocationsChangedListener; + +import com.android.systemui.util.leak.LeakDetector; import com.android.systemui.volume.VolumeComponent; import java.io.FileDescriptor; @@ -6596,6 +6598,7 @@ public class StatusBar extends SystemUI implements DemoMode, return null; } updateNotifications(); + Dependency.get(LeakDetector.class).trackGarbage(entry); return entry.notification; } @@ -6604,6 +6607,7 @@ public class StatusBar extends SystemUI implements DemoMode, Log.d(TAG, "createNotificationViews(notification=" + sbn); } NotificationData.Entry entry = new NotificationData.Entry(sbn); + Dependency.get(LeakDetector.class).trackInstance(entry); try { entry.createIcons(mContext, sbn); } catch (NotificationData.IconException exception) { diff --git a/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java b/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java index 0edff86a624bb..85be4d79d64f7 100644 --- a/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java +++ b/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java @@ -48,8 +48,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; @@ -66,6 +68,8 @@ public class TunerService { private final ArrayMap mListeningUris = new ArrayMap<>(); // Map of settings keys to the listener. private final HashMap> mTunableLookup = new HashMap<>(); + // Set of all tunables, used for leak detection. + private final HashSet mTunables = LeakDetector.ENABLED ? new HashSet<>() : null; private final Context mContext; private ContentResolver mContentResolver; @@ -150,6 +154,10 @@ public class TunerService { mTunableLookup.put(key, new ArraySet()); } 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); @@ -164,6 +172,9 @@ public class TunerService { for (Set list : mTunableLookup.values()) { list.remove(tunable); } + if (LeakDetector.ENABLED) { + mTunables.remove(tunable); + } } protected void reregisterAll() { diff --git a/packages/SystemUI/src/com/android/systemui/util/leak/LeakDetector.java b/packages/SystemUI/src/com/android/systemui/util/leak/LeakDetector.java index 2124f903bfc80..a0f8659ab5d07 100644 --- a/packages/SystemUI/src/com/android/systemui/util/leak/LeakDetector.java +++ b/packages/SystemUI/src/com/android/systemui/util/leak/LeakDetector.java @@ -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;