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

Commit f698bf36 authored by Arthur Hung's avatar Arthur Hung
Browse files

Let KEYCODE_SYSRQ could be consumed in app

Some app that may create its own virtual display and use KEYCODE_SYSRQ
to take the screenshot, we have to handle the device screenshot after
the focused app ignored it.

Bug: 180455325
Test: atest CtsInputTestCases
Change-Id: I4e342f5f1aa94a90b591d69ff814fbd676a6ec4f
parent 0f78ba1e
Loading
Loading
Loading
Loading
+21 −35
Original line number Diff line number Diff line
@@ -632,6 +632,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private static final int MSG_HIDE_BOOT_MESSAGE = 11;
    private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
    private static final int MSG_SHOW_PICTURE_IN_PICTURE_MENU = 15;
    private static final int MSG_SCREENSHOT_CHORD = 16;
    private static final int MSG_ACCESSIBILITY_SHORTCUT = 17;
    private static final int MSG_BUGREPORT_TV = 18;
    private static final int MSG_ACCESSIBILITY_TV = 19;
@@ -707,6 +708,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                case MSG_RINGER_TOGGLE_CHORD:
                    handleRingerChordGesture();
                    break;
                case MSG_SCREENSHOT_CHORD:
                    handleScreenShot(msg.arg1, msg.arg2);
                    break;
            }
        }
    }
@@ -1452,11 +1456,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                || mShortPressOnStemPrimaryBehavior != SHORT_PRESS_PRIMARY_NOTHING;
    }

    private void interceptScreenshotChord() {
        mHandler.removeCallbacks(mScreenshotRunnable);
        mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
        mScreenshotRunnable.setScreenshotSource(SCREENSHOT_KEY_CHORD);
        mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
    private void interceptScreenshotChord(int type, int source, long pressDelay) {
        mHandler.removeMessages(MSG_SCREENSHOT_CHORD);
        mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_SCREENSHOT_CHORD, type, source),
                pressDelay);
    }

    private void interceptAccessibilityShortcutChord() {
@@ -1496,7 +1499,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    }

    private void cancelPendingScreenshotChordAction() {
        mHandler.removeCallbacks(mScreenshotRunnable);
        mHandler.removeMessages(MSG_SCREENSHOT_CHORD);
    }

    private void cancelPendingAccessibilityShortcutAction() {
@@ -1517,26 +1520,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    };

    private class ScreenshotRunnable implements Runnable {
        private int mScreenshotType = TAKE_SCREENSHOT_FULLSCREEN;
        private int mScreenshotSource = SCREENSHOT_KEY_OTHER;

        public void setScreenshotType(int screenshotType) {
            mScreenshotType = screenshotType;
        }

        public void setScreenshotSource(int screenshotSource) {
            mScreenshotSource = screenshotSource;
        }

        @Override
        public void run() {
            mDefaultDisplayPolicy.takeScreenshot(mScreenshotType, mScreenshotSource);
        }
    private void handleScreenShot(@WindowManager.ScreenshotType int type,
            @WindowManager.ScreenshotSource int source) {
        mDefaultDisplayPolicy.takeScreenshot(type, source);
    }

    private final ScreenshotRunnable mScreenshotRunnable = new ScreenshotRunnable();

    @Override
    public void showGlobalActions() {
        mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
@@ -2111,7 +2099,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                        @Override
                        void execute() {
                            mPowerKeyHandled = true;
                            interceptScreenshotChord();
                            interceptScreenshotChord(TAKE_SCREENSHOT_FULLSCREEN,
                                    SCREENSHOT_KEY_CHORD, getScreenshotChordLongPressDelay());
                        }
                        @Override
                        void cancel() {
@@ -2785,9 +2774,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                if (down && event.isMetaPressed() && event.isCtrlPressed() && repeatCount == 0) {
                    int type = event.isShiftPressed() ? TAKE_SCREENSHOT_SELECTED_REGION
                            : TAKE_SCREENSHOT_FULLSCREEN;
                    mScreenshotRunnable.setScreenshotType(type);
                    mScreenshotRunnable.setScreenshotSource(SCREENSHOT_KEY_OTHER);
                    mHandler.post(mScreenshotRunnable);
                    interceptScreenshotChord(type, SCREENSHOT_KEY_OTHER, 0 /*pressDelay*/);
                    return key_consumed;
                }
                break;
@@ -2822,13 +2809,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            case KeyEvent.KEYCODE_DEMO_APP_4:
                Slog.wtf(TAG, "KEYCODE_APP_X should be handled in interceptKeyBeforeQueueing");
                return key_consumed;
            case KeyEvent.KEYCODE_SYSRQ:
                if (down && repeatCount == 0) {
                    mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
                    mScreenshotRunnable.setScreenshotSource(SCREENSHOT_KEY_OTHER);
                    mHandler.post(mScreenshotRunnable);
                }
                return key_consumed;
            case KeyEvent.KEYCODE_BRIGHTNESS_UP:
            case KeyEvent.KEYCODE_BRIGHTNESS_DOWN:
                if (down) {
@@ -3145,6 +3125,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    }
                }
                break;
            case KeyEvent.KEYCODE_SYSRQ:
                if (down && repeatCount == 0) {
                    interceptScreenshotChord(
                            TAKE_SCREENSHOT_FULLSCREEN, SCREENSHOT_KEY_OTHER, 0 /*pressDelay*/);
                }
                return true;
        }

        return false;