Run explicit GC to clear references to bitmaps earlier.

Bug: 38258699
Test: Open Recents, dump meminfo, close Recents, wait, dump meminfo
Change-Id: Ibdcf94aee4fac9abcde64e30ae1f13cbb551fec0
(cherry picked from commit 69a9c170b39cf26293a5b6d80e9aeed47b17b385)
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
index 7697061..ba3bcc7 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
@@ -514,6 +514,9 @@
             RecentsActivityLaunchState launchState = config.getLaunchState();
             launchState.reset();
         }
+
+        // Force a gc to attempt to clean up bitmap references more quickly (b/38258699)
+        Recents.getSystemServices().gc();
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
index cbfa0e5..1f13830 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
@@ -362,6 +362,19 @@
     }
 
     /**
+     * Requests a gc() from the background thread.
+     */
+    public void gc() {
+        BackgroundThread.getHandler().post(new Runnable() {
+            @Override
+            public void run() {
+                System.gc();
+                System.runFinalization();
+            }
+        });
+    }
+
+    /**
      * @return whether the provided {@param className} is blacklisted
      */
     public boolean isBlackListedActivity(String className) {