From f6d562b83f16fe9a90464179087110c869640cf7 Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Thu, 2 Feb 2017 16:01:51 -0800 Subject: [PATCH 1/2] SysUiLeaks: Detect leaks of NotificationData.Entry Bug: 34932615 Test: manual Change-Id: I0c33d5194fe94e99b7bebe3a04a3730e41575080 --- .../src/com/android/systemui/statusbar/phone/StatusBar.java | 4 ++++ 1 file changed, 4 insertions(+) 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 9ac6f6580ba3d..4dd5d854a0750 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -193,6 +193,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; @@ -6748,6 +6750,7 @@ public class StatusBar extends SystemUI implements DemoMode, return null; } updateNotifications(); + Dependency.get(LeakDetector.class).trackGarbage(entry); return entry.notification; } @@ -6756,6 +6759,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) { From 6b2852e03f638b8e0694a0c02544232a1ef04804 Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Thu, 2 Feb 2017 16:01:51 -0800 Subject: [PATCH 2/2] SysUiLeaks: Detect leaks in TunerService Bug: 34932615 Test: manual Change-Id: I348c18dc4e5772637828c1f53f15c84ad4c39485 --- .../src/com/android/systemui/tuner/TunerService.java | 11 +++++++++++ .../com/android/systemui/util/leak/LeakDetector.java | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java b/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java index ca582b360a489..377d31b6884cb 100644 --- a/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java +++ b/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java @@ -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 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; @@ -149,6 +153,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); @@ -163,6 +171,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;