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

Commit a572251a authored by Dhina17's avatar Dhina17
Browse files

WindowDecor: Pass correct displayId for back key event

TaskOperations object is being created with default display context
so it will provide the default display id only.
It causes that back button is not working on external displays.

Change-Id: Ia4772e898dda20fb16ae85f2b2652a17924e9a7c
parent 3e197d65
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -211,6 +211,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
        private final WindowContainerToken mTaskToken;
        private final DragPositioningCallback mDragPositioningCallback;
        private final DragDetector mDragDetector;
        private final int mDisplayId;

        private int mDragPointerId = -1;
        private boolean mIsDragging;
@@ -222,6 +223,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
            mTaskToken = taskInfo.token;
            mDragPositioningCallback = dragPositioningCallback;
            mDragDetector = new DragDetector(this);
            mDisplayId = taskInfo.displayId;
        }

        @Override
@@ -230,7 +232,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
            if (id == R.id.close_window) {
                mTaskOperations.closeTask(mTaskToken);
            } else if (id == R.id.back_button) {
                mTaskOperations.injectBackKey();
                mTaskOperations.injectBackKey(mDisplayId);
            } else if (id == R.id.minimize_window) {
                mTaskOperations.minimizeTask(mTaskToken);
            } else if (id == R.id.maximize_window) {
+3 −1
Original line number Diff line number Diff line
@@ -382,6 +382,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
        private final DragPositioningCallback mDragPositioningCallback;
        private final DragDetector mDragDetector;
        private final GestureDetector mGestureDetector;
        private final int mDisplayId;

        private boolean mIsDragging;
        private boolean mHasLongClicked;
@@ -396,6 +397,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
            mDragPositioningCallback = dragPositioningCallback;
            mDragDetector = new DragDetector(this);
            mGestureDetector = new GestureDetector(mContext, this);
            mDisplayId = taskInfo.displayId;
        }

        @Override
@@ -409,7 +411,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
                    mTaskOperations.closeTask(mTaskToken);
                }
            } else if (id == R.id.back_button) {
                mTaskOperations.injectBackKey();
                mTaskOperations.injectBackKey(mDisplayId);
            } else if (id == R.id.caption_handle || id == R.id.open_menu_button) {
                if (!decoration.isHandleMenuActive()) {
                    moveTaskToFront(mTaskOrganizer.getRunningTaskInfo(mTaskId));
+5 −5
Original line number Diff line number Diff line
@@ -52,19 +52,19 @@ class TaskOperations {
        mSyncQueue = syncQueue;
    }

    void injectBackKey() {
        sendBackEvent(KeyEvent.ACTION_DOWN);
        sendBackEvent(KeyEvent.ACTION_UP);
    void injectBackKey(int displayId) {
        sendBackEvent(KeyEvent.ACTION_DOWN, displayId);
        sendBackEvent(KeyEvent.ACTION_UP, displayId);
    }

    private void sendBackEvent(int action) {
    private void sendBackEvent(int action, int displayId) {
        final long when = SystemClock.uptimeMillis();
        final KeyEvent ev = new KeyEvent(when, when, action, KeyEvent.KEYCODE_BACK,
                0 /* repeat */, 0 /* metaState */, KeyCharacterMap.VIRTUAL_KEYBOARD,
                0 /* scancode */, KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY,
                InputDevice.SOURCE_KEYBOARD);

        ev.setDisplayId(mContext.getDisplay().getDisplayId());
        ev.setDisplayId(displayId);
        if (!mContext.getSystemService(InputManager.class)
                .injectInputEvent(ev, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC)) {
            Log.e(TAG, "Inject input event fail");