Merge "Preemptively clear buffer reference if snapshot is unused" into qt-dev

This commit is contained in:
Winson Chung
2019-05-02 23:01:42 +00:00
committed by Android (Google) Code Review
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