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

Commit 86113371 authored by Danesh M's avatar Danesh M Committed by Steve Kondik
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 877e6616
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -843,6 +843,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
@@ -1127,6 +1127,12 @@ public interface WindowManager extends ViewManager {
         */
        public static final int PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT = 0x00001000;

        /**
         * 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.
         * @hide
+9 −0
Original line number Diff line number Diff line
@@ -1137,6 +1137,15 @@
        android:description="@string/permdesc_transmitIr"
        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   -->
    <!-- ==================================================== -->
+5 −0
Original line number Diff line number Diff line
@@ -45,4 +45,9 @@
    <string name="permlab_changePhoneBlacklist">change phone blacklist</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_changePhoneBlacklist">Allows an app to change the phone numbers that are blocked for incoming calls or messages.</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>
+5 −0
Original line number Diff line number Diff line
@@ -5438,6 +5438,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            }

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