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

Commit b0f18015 authored by Bartosz Chomiński's avatar Bartosz Chomiński Committed by Android (Google) Code Review
Browse files

Merge "Clear Binder identity in AppTaskImpl#moveTaskTo" into main

parents 8e791bb9 bc867108
Loading
Loading
Loading
Loading
+61 −43
Original line number Diff line number Diff line
@@ -185,13 +185,16 @@ class AppTaskImpl extends IAppTask.Stub {
    @Override
    public void moveTaskTo(int displayId, Rect bounds, IRemoteCallback callback) {
        checkCallerOrSystemOrRoot();
        if (mService.checkPermission(
                REPOSITION_SELF_WINDOWS, Binder.getCallingPid(), Binder.getCallingUid())
        final int origCallingPid = Binder.getCallingPid();
        final int origCallingUid = Binder.getCallingUid();
        final long origId = Binder.clearCallingIdentity();
        if (mService.checkPermission(REPOSITION_SELF_WINDOWS, origCallingPid, origCallingUid)
                != PERMISSION_GRANTED) {
            reportTaskMoveRequestResult(
                    RESULT_FAILED_NO_PERMISSIONS, INVALID_DISPLAY, null /* bounds */, callback);
            return;
        }
        try {
            synchronized (mService.mGlobalLock) {
                final Task task = mService.mRootWindowContainer.anyTaskForId(mTaskId);
                if (task == null) {
@@ -205,9 +208,11 @@ class AppTaskImpl extends IAppTask.Stub {
                }

                adjustTaskMoveRequestBounds(displayId, bounds);
            final int result = validateTaskMoveRequest(displayId, bounds, task);
                final int result = validateTaskMoveRequest(displayId, bounds, task,
                        origCallingPid, origCallingUid);
                if (result != RESULT_APPROVED) {
                reportTaskMoveRequestResult(result, INVALID_DISPLAY, null /* bounds */, callback);
                    reportTaskMoveRequestResult(
                            result, INVALID_DISPLAY, null /* bounds */, callback);
                    return;
                }

@@ -224,10 +229,15 @@ class AppTaskImpl extends IAppTask.Stub {
                                int lateResult = validateTaskMoveRequest(
                                        transition.getRequestedLocation().getDisplayId(),
                                        transition.getRequestedLocation().getBounds(),
                                    task);
                                        task,
                                        origCallingPid,
                                        origCallingUid);
                                if (lateResult != RESULT_APPROVED) {
                                    reportTaskMoveRequestResult(
                                        lateResult, INVALID_DISPLAY, null /* bounds */, callback);
                                            lateResult,
                                            INVALID_DISPLAY,
                                            null /* bounds */,
                                            callback);
                                    transition.abort();
                                    return;
                                }
@@ -236,6 +246,9 @@ class AppTaskImpl extends IAppTask.Stub {
                            transition.setReady(task, true);
                        });
            }
        } finally {
            Binder.restoreCallingIdentity(origId);
        }
    }

    /**
@@ -266,7 +279,12 @@ class AppTaskImpl extends IAppTask.Stub {
    }

    @TaskMoveRequestHandler.RequestResult
    private int validateTaskMoveRequest(int displayId, Rect bounds, @NonNull Task task) {
    private int validateTaskMoveRequest(
            int displayId,
            Rect bounds,
            @NonNull Task task,
            int origCallingPid,
            int origCallingUid) {
        final DisplayContent targetDisplay =
                mService.mRootWindowContainer.getDisplayContent(displayId);
        if (targetDisplay == null) {
@@ -274,7 +292,7 @@ class AppTaskImpl extends IAppTask.Stub {
        }

        if (!mService.mTaskSupervisor.canPlaceEntityOnDisplay(
                displayId, Binder.getCallingPid(), Binder.getCallingUid(), task)) {
                displayId, origCallingPid, origCallingUid, task)) {
            return RESULT_FAILED_UNABLE_TO_PLACE_TASK;
        }