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

Commit 9b5f4aa4 authored by Winson Chung's avatar Winson Chung
Browse files

Fix two small thumbnail leaks

- Even though the object wrapper is used within the same process, the
  call to start the fallback recents activity means that the system
  still ends up holding a reference to a copy of the intent and its
  extras, including the reference to the wrapper and the thumbnail it
  references, until the activity is destroyed (or next restarted).
  We need to clear the actual object strong ref after it's used when
  handling the new intent.
- The running task can have an associated thumbnail, so we should also
  clear the tmp running task ref when we leave overview.

Change-Id: Icdc0b1989b13927d112949797752615014856970
parent 88267345
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -89,9 +89,13 @@ public final class RecentsActivity extends BaseRecentsActivity {
            int taskID = intent.getIntExtra(EXTRA_TASK_ID, 0);
            IBinder thumbnail = intent.getExtras().getBinder(EXTRA_THUMBNAIL);
            if (taskID != 0 && thumbnail instanceof ObjectWrapper) {
                ThumbnailData thumbnailData = ((ObjectWrapper<ThumbnailData>) thumbnail).get();
                ObjectWrapper<ThumbnailData> obj = (ObjectWrapper<ThumbnailData>) thumbnail;
                ThumbnailData thumbnailData = obj.get();
                mFallbackRecentsView.showCurrentTask(taskID);
                mFallbackRecentsView.updateThumbnail(taskID, thumbnailData);
                // Clear the ref since any reference to the extras on the system side will still
                // hold a reference to the wrapper
                obj.clear();
            }
        }
        intent.removeExtra(EXTRA_TASK_ID);
+5 −0
Original line number Diff line number Diff line
@@ -485,6 +485,11 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
    public void setOverviewStateEnabled(boolean enabled) {
        mOverviewStateEnabled = enabled;
        updateTaskStackListenerState();
        if (!enabled) {
            // Reset the running task when leaving overview since it can still have a reference to
            // its thumbnail
            mTmpRunningTask = null;
        }
    }

    public void onDigitalWellbeingToastShown() {
+5 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import android.os.IBinder;
 */
public class ObjectWrapper<T> extends Binder {

    private final T mObject;
    private T mObject;

    public ObjectWrapper(T object) {
        mObject = object;
@@ -35,6 +35,10 @@ public class ObjectWrapper<T> extends Binder {
        return mObject;
    }

    public void clear() {
        mObject = null;
    }

    public static IBinder wrap(Object obj) {
        return new ObjectWrapper<>(obj);
    }