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

Commit 936f7e26 authored by Adnan Begovic's avatar Adnan Begovic Committed by Gerrit Code Review
Browse files

fw: Repurpose PREVENT_POWER_KEY for preventing multiple system keys.

  Allows applications like camera, and various testing applications,
  to intercept certain system keys to verify behavior or leverage it
  in creative ways.

  Limited to signature/privileged.

Change-Id: Iacd8735af2aabafbf1fc062d8c565b7102dc6865
TICKET: FEIJ-522
parent 4018231a
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -869,9 +869,9 @@ public abstract class Window {
    }

    private void setPrivateFlags(int flags, int mask) {
        if ((flags & mask & WindowManager.LayoutParams.PRIVATE_FLAG_PREVENT_POWER_KEY) != 0){
            mContext.enforceCallingOrSelfPermission("android.permission.PREVENT_POWER_KEY",
                    "No permission to prevent power key");
        if ((flags & mask & WindowManager.LayoutParams.PRIVATE_FLAG_PREVENT_SYSTEM_KEYS) != 0){
            mContext.enforceCallingOrSelfPermission("android.permission.PREVENT_SYSTEM_KEYS",
                    "No permission to prevent system key");
        }
        final WindowManager.LayoutParams attrs = getAttributes();
        attrs.privateFlags = (attrs.privateFlags & ~mask) | (flags & mask);
+2 −2
Original line number Diff line number Diff line
@@ -1154,10 +1154,10 @@ public interface WindowManager extends ViewManager {
        public static final int PRIVATE_FLAG_WAS_NOT_FULLSCREEN = 0x02000000;

        /**
         * Window flag: Overrides default power key behavior
         * Window flag: Overrides default system key behavior.
         * {@hide}
         */
        public static final int PRIVATE_FLAG_PREVENT_POWER_KEY = 0x20000000;
        public static final int PRIVATE_FLAG_PREVENT_SYSTEM_KEYS = 0x20000000;

        /**
         * Window flag: adding additional blur layer and set this as masking layer
+2 −2
Original line number Diff line number Diff line
@@ -1239,10 +1239,10 @@
    <permission android:name="android.permission.NOTIFY_PENDING_SYSTEM_UPDATE"
        android:protectionLevel="signature|privileged" />

    <!-- Allows an application to override the power key action
    <!-- Allows an application to override the system key actions
         @hide <p>Not for use by third-party applications.
    -->
    <permission android:name="android.permission.PREVENT_POWER_KEY"
    <permission android:name="android.permission.PREVENT_SYSTEM_KEYS"
        android:protectionLevel="signature|privileged" />

    <!-- =========================================== -->
+22 −1
Original line number Diff line number Diff line
@@ -3257,6 +3257,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                return 0;
            }

            if (mTopFullscreenOpaqueWindowState != null &&
                    (mTopFullscreenOpaqueWindowState.getAttrs().privateFlags
                            & WindowManager.LayoutParams.PRIVATE_FLAG_PREVENT_SYSTEM_KEYS) != 0
                    && mScreenOnFully) {
                return 0;
            }

            if (down) {
                if (mPressOnMenuBehavior == KEY_ACTION_APP_SWITCH
                        || mLongPressOnMenuBehavior == KEY_ACTION_APP_SWITCH) {
@@ -3322,6 +3329,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            }
            return 0;
        } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
            if (mTopFullscreenOpaqueWindowState != null &&
                    (mTopFullscreenOpaqueWindowState.getAttrs().privateFlags
                            & WindowManager.LayoutParams.PRIVATE_FLAG_PREVENT_SYSTEM_KEYS) != 0
                    && mScreenOnFully) {
                return 0;
            }

            if (!keyguardOn) {
                if (down) {
                    if (mPressOnAppSwitchBehavior == KEY_ACTION_APP_SWITCH
@@ -5753,6 +5767,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            }

            case KeyEvent.KEYCODE_HOME:
                if (mTopFullscreenOpaqueWindowState != null &&
                        (mTopFullscreenOpaqueWindowState.getAttrs().privateFlags
                                & WindowManager.LayoutParams.PRIVATE_FLAG_PREVENT_SYSTEM_KEYS) != 0
                        && mScreenOnFully) {
                    return result;
                }

                if (down && !interactive && mHomeWakeScreen) {
                    isWakeKey = true;
                }
@@ -5834,7 +5855,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            case KeyEvent.KEYCODE_POWER: {
                if (mTopFullscreenOpaqueWindowState != null &&
                        (mTopFullscreenOpaqueWindowState.getAttrs().privateFlags
                        & WindowManager.LayoutParams.PRIVATE_FLAG_PREVENT_POWER_KEY) != 0
                        & WindowManager.LayoutParams.PRIVATE_FLAG_PREVENT_SYSTEM_KEYS) != 0
                        && mScreenOnFully) {
                    return result;
                }