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

Commit 4e6f1a41 authored by Vladimir Komsiyski's avatar Vladimir Komsiyski
Browse files

API for moving all tasks from the virtual display to the default one

Bug: 440005498
Flag: android.companion.virtualdevice.flags.computer_control_access
Test: manual
Change-Id: Ief41137dbbf1a714c98e4237e53e7e35db5b22af
parent 924ff30a
Loading
Loading
Loading
Loading
+25 −9
Original line number Diff line number Diff line
@@ -118,15 +118,6 @@ public final class ComputerControlSession implements AutoCloseable {
    @Nullable
    private ImageReader mImageReader;

    /** Perform provided action on the trusted virtual display. */
    public void performAction(@Action int actionCode) {
        try {
            mSession.performAction(actionCode);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** @hide */
    public ComputerControlSession(int displayId, @NonNull IVirtualDisplayCallback displayToken,
            @NonNull IComputerControlSession session) {
@@ -170,6 +161,22 @@ public final class ComputerControlSession implements AutoCloseable {
        }
    }

    /**
     * Hand over full control of the automation session to the user.
     *
     * <p>All of the applications currently automated in the session are moved from the session's
     * display to the user's default display. No further automation is possible on these tasks,
     * although the session remains active and new applications may be launched via
     * {@link #launchApplication(String)}</p>
     */
    public void handOverApplications() {
        try {
            mSession.handOverApplications();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Screenshot the current display content.
     *
@@ -287,6 +294,15 @@ public final class ComputerControlSession implements AutoCloseable {
        }
    }

    /** Perform provided action on the trusted virtual display. */
    public void performAction(@Action int actionCode) {
        try {
            mSession.performAction(actionCode);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** Injects a touch event into the trusted virtual display. */
    public void sendTouchEvent(@NonNull VirtualTouchEvent event) {
        try {
+3 −0
Original line number Diff line number Diff line
@@ -32,6 +32,9 @@ interface IComputerControlSession {
    /** Launches an application on the trusted virtual display. */
    void launchApplication(in String packageName);

    /** Hand over full control of the automation session to the user. */
    void handOverApplications();

    /* Injects a tap event into the trusted virtual display. */
    void tap(int x, int y);

+12 −0
Original line number Diff line number Diff line
@@ -114,6 +114,18 @@ public final class ComputerControlSession implements AutoCloseable {
        mAccessibilityProxy.resetStabilityState();
    }

    /**
     * Hand over full control of the automation session to the user.
     *
     * <p>All of the applications currently automated in the session are moved from the session's
     * display to the user's default display. No further automation is possible on these tasks,
     * although the session remains active and new applications may be launched via
     * {@link #launchApplication(String)}</p>
     */
    public void handOverApplications() {
        mSession.handOverApplications();
    }

    /**
     * Screenshot the current display content.
     *
+14 −0
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ import com.android.internal.inputmethod.InputConnectionCommandHeader;
import com.android.server.LocalServices;
import com.android.server.inputmethod.InputMethodManagerInternal;
import com.android.server.pm.UserManagerInternal;
import com.android.server.wm.ActivityTaskManagerInternal;
import com.android.server.wm.WindowManagerInternal;

import java.util.ArrayList;
@@ -337,6 +338,12 @@ final class ComputerControlSessionImpl extends IComputerControlSession.Stub
        notifyApplicationLaunchToStabilityCalculator();
    }

    @Override
    public void handOverApplications() {
        Binder.withCleanCallingIdentity(
                () -> mInjector.moveAllTasks(mVirtualDisplayId, mMainDisplayId));
    }

    @Override
    public void tap(@IntRange(from = 0) int x, @IntRange(from = 0) int y) throws RemoteException {
        cancelOngoingTouchGestures();
@@ -696,6 +703,7 @@ final class ComputerControlSessionImpl extends IComputerControlSession.Stub
        private final WindowManagerInternal mWindowManagerInternal;
        private final InputMethodManagerInternal mInputMethodManagerInternal;
        private final UserManagerInternal mUserManagerInternal;
        private final ActivityTaskManagerInternal mActivityTaskManagerInternal;

        Injector(Context context) {
            mContext = context;
@@ -704,6 +712,8 @@ final class ComputerControlSessionImpl extends IComputerControlSession.Stub
            mInputMethodManagerInternal = LocalServices.getService(
                    InputMethodManagerInternal.class);
            mUserManagerInternal = LocalServices.getService(UserManagerInternal.class);
            mActivityTaskManagerInternal = LocalServices.getService(
                    ActivityTaskManagerInternal.class);
        }

        public String getPermissionControllerPackageName() {
@@ -758,5 +768,9 @@ final class ComputerControlSessionImpl extends IComputerControlSession.Stub
            return mInputMethodManagerInternal.getComputerControlInputConnection(
                    mUserManagerInternal.getUserAssignedToDisplay(displayId), displayId);
        }

        public void moveAllTasks(int fromDisplayId, int toDisplayId) {
            mActivityTaskManagerInternal.moveAllTasks(fromDisplayId, toDisplayId);
        }
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -844,4 +844,7 @@ public abstract class ActivityTaskManagerInternal implements ActiveUids.Observer
    /** Unregisters a listener for handoff enablement changes. */
    public abstract void unregisterHandoffEnablementListener(
        @NonNull HandoffEnablementListener listener);

    /** Moves all tasks from the source display to the destination display. */
    public abstract void moveAllTasks(int fromDisplayId, int toDisplayId);
}
Loading