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

Commit 121fb1ed authored by HazouPH's avatar HazouPH Committed by Gerrit Code Review
Browse files

[1/2] Camera button support

Add support for camera button

Based on commit http://review.cyanogenmod.org/#/c/51487/

This patch adds:
- Use camera button as wake key
- Use focus button as peek and wake key
- Use camera button to launch (secure) camera

Depends on:
[2/2] Camera button support in packages/apps/Settings

Change-Id: Ia515c04cca098bf0d20b077ebffc079ee4008f21
parent 1b34a5a6
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -3338,6 +3338,24 @@ public final class Settings {
         */
        public static final String APP_SWITCH_WAKE_SCREEN = "app_switch_wake_screen";

        /**
         * Whether to wake the screen with the camera key half-press.
         * @hide
         */
        public static final String CAMERA_WAKE_SCREEN = "camera_wake_screen";

        /**
         * Whether or not to send device back to sleep if Camera button is released ("Peek")
         * @hide
         */
        public static final String CAMERA_SLEEP_ON_RELEASE = "camera_sleep_on_release";

        /**
         * Whether to launch secure camera app when key is longpressed
         * @hide
         */
        public static final String CAMERA_LAUNCH = "camera_launch";

        /**
         * Whether to wake the screen with the volume keys, the value is boolean.
         * @hide
+2 −0
Original line number Diff line number Diff line
@@ -1812,6 +1812,8 @@ public class KeyEvent extends InputEvent implements Parcelable {
            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_VOLUME_DOWN:
            case KeyEvent.KEYCODE_VOLUME_MUTE:
            case KeyEvent.KEYCODE_CAMERA:
            case KeyEvent.KEYCODE_FOCUS:
                return true;
        }
        return false;
+1 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@

    <java-symbol type="integer" name="config_deviceHardwareKeys" />
    <java-symbol type="integer" name="config_deviceHardwareWakeKeys" />
    <java-symbol type="bool" name="config_singleStageCameraKey" />
    <java-symbol type="integer" name="config_longPressOnMenuBehavior" />

    <java-symbol type="string" name="global_action_reboot" />
+4 −0
Original line number Diff line number Diff line
@@ -910,6 +910,10 @@
         config to 7. -->
    <integer name="config_deviceHardwareWakeKeys">79</integer>

    <!-- Indicates that the device has Single-stage Camera key
         (without "Focus" state) instead of Dual-stage. -->
    <bool name="config_singleStageCameraKey">false</bool>

    <!-- Minimum screen brightness setting allowed by the power manager.
         The user is forbidden from setting the brightness below this level. -->
    <integer name="config_screenBrightnessSettingMinimum">10</integer>
+77 −4
Original line number Diff line number Diff line
@@ -449,8 +449,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    boolean mMenuWakeScreen;
    boolean mAssistWakeScreen;
    boolean mAppSwitchWakeScreen;
    boolean mCameraWakeScreen;
    boolean mVolumeWakeScreen;

    // Camera button control flags and actions
    boolean mCameraSleepOnRelease;
    boolean mIsFocusPressed;
    boolean mCameraLaunch;

    // During wakeup by volume keys, we still need to capture subsequent events
    // until the key is released. This is required since the beep sound is produced
    // post keypressed.
@@ -700,6 +706,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private static final int MSG_POWER_DELAYED_PRESS = 13;
    private static final int MSG_POWER_LONG_PRESS = 14;
    private static final int MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK = 15;
    private static final int MSG_CAMERA_LONG_PRESS = 16;
    private boolean mHasPermanentMenuKey;
    private boolean mClearedBecauseOfForceShow;
    private boolean mTopWindowIsKeyguard;
@@ -759,6 +766,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                            KeyEvent.changeAction(event, KeyEvent.ACTION_UP));
                    break;
                }
                case MSG_CAMERA_LONG_PRESS: {
                    KeyEvent event = (KeyEvent) msg.obj;
                    mIsLongPress = true;
                    break;
                }
            }
        }
    }
@@ -856,6 +868,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.APP_SWITCH_WAKE_SCREEN), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.CAMERA_WAKE_SCREEN), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.CAMERA_SLEEP_ON_RELEASE), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.CAMERA_LAUNCH), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.VOLUME_WAKE_SCREEN), false, this,
                    UserHandle.USER_ALL);
@@ -1972,6 +1993,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            mAppSwitchWakeScreen = (Settings.System.getIntForUser(resolver,
                    Settings.System.APP_SWITCH_WAKE_SCREEN, 0, UserHandle.USER_CURRENT) == 1) &&
                    ((mDeviceHardwareWakeKeys & KEY_MASK_APP_SWITCH) != 0);
            mCameraWakeScreen = (Settings.System.getIntForUser(resolver,
                    Settings.System.CAMERA_WAKE_SCREEN, 0, UserHandle.USER_CURRENT) == 1) &&
                    ((mDeviceHardwareWakeKeys & KEY_MASK_CAMERA) != 0);
            mCameraSleepOnRelease = (Settings.System.getIntForUser(resolver,
                    Settings.System.CAMERA_SLEEP_ON_RELEASE, 0, UserHandle.USER_CURRENT) == 1);
            mCameraLaunch = (Settings.System.getIntForUser(resolver,
                    Settings.System.CAMERA_LAUNCH, 0, UserHandle.USER_CURRENT) == 1);
            mVolumeWakeScreen = (Settings.System.getIntForUser(resolver,
                    Settings.System.VOLUME_WAKE_SCREEN, 0, UserHandle.USER_CURRENT) == 1) &&
                    ((mDeviceHardwareWakeKeys & KEY_MASK_VOLUME) != 0);
@@ -5514,6 +5542,42 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                }
                break;

            case KeyEvent.KEYCODE_FOCUS:
                if (down && !interactive && mCameraSleepOnRelease) {
                    mIsFocusPressed = true;
                } else if ((event.getAction() == KeyEvent.ACTION_UP)
                        && mScreenOnFully && mIsFocusPressed) {
                    // Check if screen is fully on before letting the device go to sleep
                    mPowerManager.goToSleep(SystemClock.uptimeMillis());
                    mIsFocusPressed = false;
                }
                break;

            case KeyEvent.KEYCODE_CAMERA:
                if (down && mIsFocusPressed) {
                    mIsFocusPressed = false;
                }
                if (down) {
                    mIsLongPress = false;
                    scheduleLongPressKeyEvent(event, KeyEvent.KEYCODE_CAMERA);
                    // Consume key down events of all presses.
                    break;
                } else {
                    mHandler.removeMessages(MSG_CAMERA_LONG_PRESS);
                    // Consume key up events of long presses only.
                    if (mIsLongPress && mCameraLaunch) {
                        Intent intent;
                        if (keyguardActive) {
                            intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
                        } else {
                            intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
                        }
                        isWakeKey = true;
                        startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
                    }
                }
                break;

            case KeyEvent.KEYCODE_ENDCALL: {
                result &= ~ACTION_PASS_TO_USER;
                if (down) {
@@ -5663,7 +5727,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private void scheduleLongPressKeyEvent(KeyEvent origEvent, int keyCode) {
        KeyEvent event = new KeyEvent(origEvent.getDownTime(), origEvent.getEventTime(),
                origEvent.getAction(), keyCode, 0);
        Message msg = mHandler.obtainMessage(MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK, event);
        Message msg;
        if (keyCode == KeyEvent.KEYCODE_CAMERA) {
            msg = mHandler.obtainMessage(MSG_CAMERA_LONG_PRESS, event);
        } else {
            msg = mHandler.obtainMessage(MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK, event);
        }
        msg.setAsynchronous(true);
        mHandler.sendMessageDelayed(msg, ViewConfiguration.getLongPressTimeout());
    }
@@ -5703,6 +5772,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                return mAssistWakeScreen;
            case KeyEvent.KEYCODE_APP_SWITCH:
                return mAppSwitchWakeScreen;
            case KeyEvent.KEYCODE_CAMERA:
            case KeyEvent.KEYCODE_FOCUS:
                return mCameraWakeScreen;
        }
        return true;
    }
@@ -5722,7 +5794,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            case KeyEvent.KEYCODE_VOLUME_MUTE:
                return mVolumeWakeScreen || mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;

            // ignore media and camera keys
            // ignore media keys
            case KeyEvent.KEYCODE_MUTE:
            case KeyEvent.KEYCODE_HEADSETHOOK:
            case KeyEvent.KEYCODE_MEDIA_PLAY:
@@ -5735,8 +5807,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            case KeyEvent.KEYCODE_MEDIA_RECORD:
            case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
            case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
            case KeyEvent.KEYCODE_CAMERA:
            case KeyEvent.KEYCODE_FOCUS:
                return false;

            case KeyEvent.KEYCODE_BACK:
@@ -5747,6 +5817,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                return mAssistWakeScreen;
            case KeyEvent.KEYCODE_APP_SWITCH:
                return mAppSwitchWakeScreen;
            case KeyEvent.KEYCODE_CAMERA:
            case KeyEvent.KEYCODE_FOCUS:
                return mCameraWakeScreen;
        }
        return true;
    }