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

Commit 0ec77895 authored by Danesh M's avatar Danesh M Committed by Wilhelm Fitzpatrick
Browse files

Camera : allow camera to use power key as shutter

Provides a way for an app to take control of the power key.
Used by the camera to make the power key control the shutter.

Change-Id: I85a1e1761199f4604672be42a3a5005227f5451a
(cherry picked from commit 15661444)
parent d1e40028
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -821,6 +821,10 @@ 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");
        }
        final WindowManager.LayoutParams attrs = getAttributes();
        attrs.privateFlags = (attrs.privateFlags & ~mask) | (flags & mask);
        dispatchWindowAttributesChanged(attrs);
+6 −0
Original line number Diff line number Diff line
@@ -1134,6 +1134,12 @@ public interface WindowManager extends ViewManager {
         */
        public static final int PRIVATE_FLAG_WAS_NOT_FULLSCREEN = 0x00002000;

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

        /**
         * Window flag: adding additional blur layer and set this as masking layer
         * {@hide}
+8 −0
Original line number Diff line number Diff line
@@ -999,6 +999,14 @@
        android:description="@string/permdesc_changeWifiMulticastState"
        android:label="@string/permlab_changeWifiMulticastState" />

    <!-- Allows an application to override the power key action
        @hide -->
    <permission android:name="android.permission.PREVENT_POWER_KEY"
        android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
        android:protectionLevel="signatureOrSystem"
        android:label="@string/permlab_preventpower"
        android:description="@string/permdesc_preventpower" />

    <!-- Allows access to the vibrator -->
    <permission android:name="android.permission.VIBRATE"
        android:permissionGroup="android.permission-group.AFFECTS_BATTERY"
+5 −0
Original line number Diff line number Diff line
@@ -270,4 +270,9 @@
    <string name="permlab_accessTorchService">access torch service</string>
    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
    <string name="permdesc_accessTorchService">Allows an app to access the torch service. Should never be needed for normal apps.</string>

    <string name="permlab_preventpower">override power key</string>
    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
    <string name="permdesc_preventpower">Allows an app to override the power key.</string>

</resources>
+4 −0
Original line number Diff line number Diff line
@@ -5174,6 +5174,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            }

            case KeyEvent.KEYCODE_POWER: {
                if ((mTopFullscreenOpaqueWindowState.getAttrs().privateFlags
                        & WindowManager.LayoutParams.PRIVATE_FLAG_PREVENT_POWER_KEY) != 0){
                    return result;
                }
                result &= ~ACTION_PASS_TO_USER;
                if (down) {
                    if (interactive && !mPowerKeyTriggered