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

Commit 6bed9bd7 authored by Sujith Ramakrishnan's avatar Sujith Ramakrishnan
Browse files

Accessibility shortcut on Android TV.

	- Added a Long Press (HOME + DPAD_CENTER) combination
	  as the Accessibility shortcut.

Note: Accessibility Shortcut in TV Settings still needs to be put in.

Test: Manual - Pressed the key combination and watched logs.
Test: Manual - watch -n 1 'adb shell dumpsys window policy | grep mAccess'
		will show the keys pressed at any given time.

Bug: 36572948
Change-Id: I557aabad84b2c02ea195754fa2bd051934e324ee
parent 71e0fcbf
Loading
Loading
Loading
Loading
+54 −0
Original line number Diff line number Diff line
@@ -777,6 +777,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private boolean mBugreportTvKey2Pressed;
    private boolean mBugreportTvScheduled;

    private boolean mAccessibilityTvKey1Pressed;
    private boolean mAccessibilityTvKey2Pressed;
    private boolean mAccessibilityTvScheduled;

    /* The number of steps between min and max brightness */
    private static final int BRIGHTNESS_STEPS = 10;

@@ -821,6 +825,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private static final int MSG_BACK_DELAYED_PRESS = 20;
    private static final int MSG_ACCESSIBILITY_SHORTCUT = 21;
    private static final int MSG_BUGREPORT_TV = 22;
    private static final int MSG_ACCESSIBILITY_TV = 23;

    private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
    private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
@@ -902,6 +907,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                case MSG_BUGREPORT_TV:
                    takeBugreport();
                    break;
                case MSG_ACCESSIBILITY_TV:
                    if (mAccessibilityShortcutController.isAccessibilityShortcutAvailable(false)) {
                        accessibilityShortcutActivated();
                    }
                    break;
            }
        }
    }
@@ -3308,6 +3318,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            if (!down) {
                cancelPreloadRecentApps();

                if (mHasFeatureLeanback) {
                    // Clear flags
                    mAccessibilityTvKey2Pressed = down;
                }

                mHomePressed = false;
                if (mHomeConsumed) {
                    mHomeConsumed = false;
@@ -3362,6 +3377,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    preloadRecentApps();
                }
            } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
                if (mHasFeatureLeanback) {
                    mAccessibilityTvKey2Pressed = down;
                    if (interceptAccessibilityGestureTv()) {
                        return -1;
                    }
                }

                if (!keyguardOn) {
                    handleLongPressOnHome(event.getDeviceId());
                }
@@ -3521,6 +3543,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            return 0;
        } else if (mHasFeatureLeanback && interceptBugreportGestureTv(keyCode, down)) {
            return -1;
        } else if (mHasFeatureLeanback && keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
            mAccessibilityTvKey1Pressed = down;
            if (interceptAccessibilityGestureTv()) {
                return -1;
            }
        }

        // Toggle Caps Lock on META-ALT.
@@ -3739,6 +3766,25 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        return mBugreportTvScheduled;
    }

    /**
     * TV only: recognizes a remote control gesture as Accessibility shortcut.
     * Shortcut: Long press (HOME + DPAD_CENTER)
     */
    private boolean interceptAccessibilityGestureTv() {
        if (mAccessibilityTvKey1Pressed && mAccessibilityTvKey2Pressed) {
            if (!mAccessibilityTvScheduled) {
                mAccessibilityTvScheduled = true;
                Message msg = Message.obtain(mHandler, MSG_ACCESSIBILITY_TV);
                msg.setAsynchronous(true);
                mHandler.sendMessage(msg);
            }
        } else if (mAccessibilityTvScheduled) {
            mHandler.removeMessages(MSG_ACCESSIBILITY_TV);
            mAccessibilityTvScheduled = false;
        }
        return mAccessibilityTvScheduled;
    }

    private void takeBugreport() {
        if ("1".equals(SystemProperties.get("ro.debuggable"))
                || Settings.Global.getInt(mContext.getContentResolver(),
@@ -8215,6 +8261,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
                pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
        pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
        if (mHasFeatureLeanback) {
            pw.print(prefix);
            pw.print("mAccessibilityTvKey1Pressed="); pw.println(mAccessibilityTvKey1Pressed);
            pw.print(prefix);
            pw.print("mAccessibilityTvKey2Pressed="); pw.println(mAccessibilityTvKey2Pressed);
            pw.print(prefix);
            pw.print("mAccessibilityTvScheduled="); pw.println(mAccessibilityTvScheduled);
        }

        mGlobalKeyManager.dump(prefix, pw);
        mStatusBarController.dump(pw, prefix);