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

Commit 9e2ae7e5 authored by HazouPH's avatar HazouPH Committed by Steve Kondik
Browse files

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 8f9c28bc
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -1863,6 +1863,8 @@ public class KeyEvent extends InputEvent implements Parcelable {
            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_VOLUME_DOWN:
            case KeyEvent.KEYCODE_VOLUME_DOWN:
            case KeyEvent.KEYCODE_VOLUME_MUTE:
            case KeyEvent.KEYCODE_VOLUME_MUTE:
            case KeyEvent.KEYCODE_CAMERA:
            case KeyEvent.KEYCODE_FOCUS:
                return true;
                return true;
        }
        }
        return false;
        return false;
+2 −0
Original line number Original line Diff line number Diff line
@@ -32,4 +32,6 @@


    <!-- LED pulse -->
    <!-- LED pulse -->
    <java-symbol type="bool" name="config_ledCanPulse" />
    <java-symbol type="bool" name="config_ledCanPulse" />

    <java-symbol type="bool" name="config_singleStageCameraKey" />
</resources>
</resources>
+4 −0
Original line number Original line Diff line number Diff line
@@ -1054,6 +1054,10 @@
         config to 7. -->
         config to 7. -->
    <integer name="config_deviceHardwareWakeKeys">79</integer>
    <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.
    <!-- Minimum screen brightness setting allowed by the power manager.
         The user is forbidden from setting the brightness below this level. -->
         The user is forbidden from setting the brightness below this level. -->
    <integer name="config_screenBrightnessSettingMinimum">10</integer>
    <integer name="config_screenBrightnessSettingMinimum">10</integer>
+77 −3
Original line number Original line Diff line number Diff line
@@ -514,8 +514,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    boolean mMenuWakeScreen;
    boolean mMenuWakeScreen;
    boolean mAssistWakeScreen;
    boolean mAssistWakeScreen;
    boolean mAppSwitchWakeScreen;
    boolean mAppSwitchWakeScreen;
    boolean mCameraWakeScreen;
    boolean mVolumeWakeScreen;
    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
    // 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
    // until the key is released. This is required since the beep sound is produced
    // post keypressed.
    // post keypressed.
@@ -785,6 +791,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private static final int MSG_BACK_LONG_PRESS = 18;
    private static final int MSG_BACK_LONG_PRESS = 18;
    private static final int MSG_DISPOSE_INPUT_CONSUMER = 19;
    private static final int MSG_DISPOSE_INPUT_CONSUMER = 19;
    private static final int MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK = 20;
    private static final int MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK = 20;
    private static final int MSG_CAMERA_LONG_PRESS = 21;


    private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
    private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
    private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
    private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
@@ -863,6 +870,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                            KeyEvent.changeAction(event, KeyEvent.ACTION_UP));
                            KeyEvent.changeAction(event, KeyEvent.ACTION_UP));
                    break;
                    break;
                }
                }
                case MSG_CAMERA_LONG_PRESS: {
                    KeyEvent event = (KeyEvent) msg.obj;
                    mIsLongPress = true;
                    break;
                }
            }
            }
        }
        }
    }
    }
@@ -951,6 +963,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(Settings.System.getUriFor(
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.APP_SWITCH_WAKE_SCREEN), false, this,
                    Settings.System.APP_SWITCH_WAKE_SCREEN), false, this,
                    UserHandle.USER_ALL);
                    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(
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.VOLUME_WAKE_SCREEN), false, this,
                    Settings.System.VOLUME_WAKE_SCREEN), false, this,
                    UserHandle.USER_ALL);
                    UserHandle.USER_ALL);
@@ -2205,6 +2226,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            mAppSwitchWakeScreen = (Settings.System.getIntForUser(resolver,
            mAppSwitchWakeScreen = (Settings.System.getIntForUser(resolver,
                    Settings.System.APP_SWITCH_WAKE_SCREEN, 0, UserHandle.USER_CURRENT) == 1) &&
                    Settings.System.APP_SWITCH_WAKE_SCREEN, 0, UserHandle.USER_CURRENT) == 1) &&
                    ((mDeviceHardwareWakeKeys & KEY_MASK_APP_SWITCH) != 0);
                    ((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,
            mVolumeWakeScreen = (Settings.System.getIntForUser(resolver,
                    Settings.System.VOLUME_WAKE_SCREEN, 0, UserHandle.USER_CURRENT) == 1) &&
                    Settings.System.VOLUME_WAKE_SCREEN, 0, UserHandle.USER_CURRENT) == 1) &&
                    ((mDeviceHardwareWakeKeys & KEY_MASK_VOLUME) != 0);
                    ((mDeviceHardwareWakeKeys & KEY_MASK_VOLUME) != 0);
@@ -6099,6 +6127,42 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                }
                }
                break;
                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: {
            case KeyEvent.KEYCODE_ENDCALL: {
                result &= ~ACTION_PASS_TO_USER;
                result &= ~ACTION_PASS_TO_USER;
                if (down) {
                if (down) {
@@ -6270,7 +6334,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private void scheduleLongPressKeyEvent(KeyEvent origEvent, int keyCode) {
    private void scheduleLongPressKeyEvent(KeyEvent origEvent, int keyCode) {
        KeyEvent event = new KeyEvent(origEvent.getDownTime(), origEvent.getEventTime(),
        KeyEvent event = new KeyEvent(origEvent.getDownTime(), origEvent.getEventTime(),
                origEvent.getAction(), keyCode, 0);
                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);
        msg.setAsynchronous(true);
        mHandler.sendMessageDelayed(msg, ViewConfiguration.getLongPressTimeout());
        mHandler.sendMessageDelayed(msg, ViewConfiguration.getLongPressTimeout());
    }
    }
@@ -6310,6 +6379,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                return mAssistWakeScreen;
                return mAssistWakeScreen;
            case KeyEvent.KEYCODE_APP_SWITCH:
            case KeyEvent.KEYCODE_APP_SWITCH:
                return mAppSwitchWakeScreen;
                return mAppSwitchWakeScreen;
            case KeyEvent.KEYCODE_CAMERA:
            case KeyEvent.KEYCODE_FOCUS:
                return mCameraWakeScreen;
        }
        }
        return true;
        return true;
    }
    }
@@ -6329,7 +6401,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            case KeyEvent.KEYCODE_VOLUME_MUTE:
            case KeyEvent.KEYCODE_VOLUME_MUTE:
                return mVolumeWakeScreen || mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
                return mVolumeWakeScreen || mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;


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


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