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

Unverified Commit 53ced068 authored by Danesh M's avatar Danesh M Committed by Michael Bestas
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)

Prevent power key capture when screen is off

The ability for an activity to capture the power key, which was
added to support power key as shutter in the camera, should only
allow the capture when the screen is on. Otherwise, if an activity
that captures the power key is to the front when the device turns
off, the user will be unable to turn it back on.

Change-Id: Ib119d6914ec72554b404c1cc17eef3a932d5d402
parent a7a6ca17
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -1076,6 +1076,10 @@ public abstract class Window {
    }
    }


    private void setPrivateFlags(int flags, int mask) {
    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();
        final WindowManager.LayoutParams attrs = getAttributes();
        attrs.privateFlags = (attrs.privateFlags & ~mask) | (flags & mask);
        attrs.privateFlags = (attrs.privateFlags & ~mask) | (flags & mask);
        dispatchWindowAttributesChanged(attrs);
        dispatchWindowAttributesChanged(attrs);
+6 −0
Original line number Original line Diff line number Diff line
@@ -1262,6 +1262,12 @@ public interface WindowManager extends ViewManager {
         */
         */
        public static final int PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE = 0x00040000;
        public static final int PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE = 0x00040000;


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

        /**
        /**
         * Control flags that are private to the platform.
         * Control flags that are private to the platform.
         * @hide
         * @hide
+9 −0
Original line number Original line Diff line number Diff line
@@ -1382,6 +1382,15 @@
        android:description="@string/permdesc_transmitIr"
        android:description="@string/permdesc_transmitIr"
        android:protectionLevel="normal" />
        android:protectionLevel="normal" />


    <!-- 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" />


    <!-- ==================================================== -->
    <!-- ==================================================== -->
    <!-- Permissions related to changing audio settings   -->
    <!-- Permissions related to changing audio settings   -->
    <!-- ==================================================== -->
    <!-- ==================================================== -->
+4 −0
Original line number Original line Diff line number Diff line
@@ -20,4 +20,8 @@
    <!-- Long-press back kill application -->
    <!-- Long-press back kill application -->
    <string name="app_killed_message">Application killed</string>
    <string name="app_killed_message">Application killed</string>


    <!-- [CHAR LIMIT=NONE] Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
    <string name="permlab_preventpower">override power key</string>
    <!-- [CHAR LIMIT=NONE] 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>
</resources>
+5 −0
Original line number Original line Diff line number Diff line
@@ -6429,6 +6429,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            }
            }


            case KeyEvent.KEYCODE_POWER: {
            case KeyEvent.KEYCODE_POWER: {
                if ((mTopFullscreenOpaqueWindowState.getAttrs().privateFlags
                        & WindowManager.LayoutParams.PRIVATE_FLAG_PREVENT_POWER_KEY) != 0
                        && mScreenOnFully) {
                    return result;
                }
                result &= ~ACTION_PASS_TO_USER;
                result &= ~ACTION_PASS_TO_USER;
                isWakeKey = false; // wake-up will be handled separately
                isWakeKey = false; // wake-up will be handled separately
                if (down) {
                if (down) {