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
This commit is contained in:
Winson Chung
2019-05-02 11:09:48 -07:00
parent 2f1382eaf2
commit 67b090243d
2 changed files with 15 additions and 0 deletions

View File

@@ -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

View File

@@ -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