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

Commit 67b09024 authored by Winson Chung's avatar Winson Chung
Browse files

Preemptively clear buffer reference if snapshot is unused

- Normally this will be picked up in the next GC, but there is no reason
  to wait

Bug: 129295298
Test: Manual
Change-Id: I945336e86d0980f926586cfba6327c8c6c142ce8
parent 2f1382ea
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.app;
import android.annotation.UnsupportedAppUsage;
import android.app.ActivityManager.TaskSnapshot;
import android.content.ComponentName;
import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;

@@ -155,6 +156,11 @@ public abstract class TaskStackListener extends ITaskStackListener.Stub {
    @Override
    @UnsupportedAppUsage
    public void onTaskSnapshotChanged(int taskId, TaskSnapshot snapshot) throws RemoteException {
        if (Binder.getCallingPid() != android.os.Process.myPid()
                && snapshot != null && snapshot.getSnapshot() != null) {
            // Preemptively clear any reference to the buffer
            snapshot.getSnapshot().destroy();
        }
    }

    @Override
+9 −0
Original line number Diff line number Diff line
@@ -70,6 +70,15 @@ public class TaskStackChangeListeners extends TaskStackListener {

    public void removeListener(TaskStackChangeListener listener) {
        mTaskStackListeners.remove(listener);
        if (mTaskStackListeners.isEmpty() && mRegistered) {
            // Unregister mTaskStackListener once we have no more listeners
            try {
                ActivityTaskManager.getService().unregisterTaskStackListener(this);
                mRegistered = false;
            } catch (Exception e) {
                Log.w(TAG, "Failed to call unregisterTaskStackListener", e);
            }
        }
    }

    @Override