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

Commit 0afea469 authored by Riddle Hsu's avatar Riddle Hsu Committed by Automerger Merge Worker
Browse files

Merge "Drop task snapshot with invalid hw buffer" into tm-dev am: 5ff11183

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17352244

Change-Id: I6d23d4c37cd65d4168c54d8c80aeda56342f9b39
parents f569b012 5ff11183
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package android.app;
import android.app.ActivityManager.RunningTaskInfo;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ComponentName;
import android.os.Binder;
import android.os.Build;
import android.os.RemoteException;
import android.window.TaskSnapshot;
@@ -32,10 +31,18 @@ import android.window.TaskSnapshot;
 */
public abstract class TaskStackListener extends ITaskStackListener.Stub {

    /** Whether this listener and the callback dispatcher are in different processes. */
    private boolean mIsRemote = true;

    @UnsupportedAppUsage
    public TaskStackListener() {
    }

    /** Indicates that this listener lives in system server. */
    public void setIsLocal() {
        mIsRemote = false;
    }

    @Override
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    public void onTaskStackChanged() throws RemoteException {
@@ -154,8 +161,7 @@ public abstract class TaskStackListener extends ITaskStackListener.Stub {
    @Override
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    public void onTaskSnapshotChanged(int taskId, TaskSnapshot snapshot) throws RemoteException {
        if (Binder.getCallingPid() != android.os.Process.myPid()
                && snapshot != null && snapshot.getHardwareBuffer() != null) {
        if (mIsRemote && snapshot != null && snapshot.getHardwareBuffer() != null) {
            // Preemptively clear any reference to the buffer
            snapshot.getHardwareBuffer().close();
        }
+4 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.app.ITaskStackListener;
import android.app.TaskInfo;
import android.app.TaskStackListener;
import android.content.ComponentName;
import android.os.Binder;
import android.os.Handler;
@@ -286,6 +287,9 @@ class TaskChangeNotificationController {
        if (listener instanceof Binder) {
            synchronized (mLocalTaskStackListeners) {
                if (!mLocalTaskStackListeners.contains(listener)) {
                    if (listener instanceof TaskStackListener) {
                        ((TaskStackListener) listener).setIsLocal();
                    }
                    mLocalTaskStackListeners.add(listener);
                }
            }
+6 −1
Original line number Diff line number Diff line
@@ -480,12 +480,17 @@ class TaskSnapshotController {
        }
        final HardwareBuffer buffer = screenshotBuffer == null ? null
                : screenshotBuffer.getHardwareBuffer();
        if (buffer == null || buffer.getWidth() <= 1 || buffer.getHeight() <= 1) {
        if (isInvalidHardwareBuffer(buffer)) {
            return null;
        }
        return screenshotBuffer;
    }

    static boolean isInvalidHardwareBuffer(HardwareBuffer buffer) {
        return buffer == null || buffer.isClosed() // This must be checked before getting size.
                || buffer.getWidth() <= 1 || buffer.getHeight() <= 1;
    }

    @Nullable
    TaskSnapshot snapshotTask(Task task) {
        return snapshotTask(task, PixelFormat.UNKNOWN);
+4 −0
Original line number Diff line number Diff line
@@ -407,6 +407,10 @@ class TaskSnapshotPersister {
        }

        boolean writeBuffer() {
            if (TaskSnapshotController.isInvalidHardwareBuffer(mSnapshot.getHardwareBuffer())) {
                Slog.e(TAG, "Invalid task snapshot hw buffer, taskId=" + mTaskId);
                return false;
            }
            final Bitmap bitmap = Bitmap.wrapHardwareBuffer(
                    mSnapshot.getHardwareBuffer(), mSnapshot.getColorSpace());
            if (bitmap == null) {
+11 −6
Original line number Diff line number Diff line
@@ -9045,6 +9045,8 @@ public class WindowManagerService extends IWindowManager.Stub
        }

        TaskSnapshot taskSnapshot;
        final long token = Binder.clearCallingIdentity();
        try {
            synchronized (mGlobalLock) {
                Task task = mRoot.anyTaskForId(taskId, MATCH_ATTACHED_TASK_OR_RECENT_TASKS);
                if (task == null) {
@@ -9053,6 +9055,9 @@ public class WindowManagerService extends IWindowManager.Stub
                }
                taskSnapshot = mTaskSnapshotController.captureTaskSnapshot(task, false);
            }
        } finally {
            Binder.restoreCallingIdentity(token);
        }

        if (taskSnapshot == null || taskSnapshot.getHardwareBuffer() == null) {
            return null;
Loading