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

Unverified Commit e5208823 authored by HazouPH's avatar HazouPH Committed by Michael Bestas
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 afd04125
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1876,6 +1876,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;
+2 −0
Original line number Diff line number Diff line
@@ -32,4 +32,6 @@

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

    <java-symbol type="bool" name="config_singleStageCameraKey" />
</resources>
+4 −0
Original line number Diff line number Diff line
@@ -1099,6 +1099,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 −3
Original line number Diff line number Diff line
@@ -541,8 +541,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.
@@ -819,6 +825,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private static final int MSG_BACK_LONG_PRESS = 18;
    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_CAMERA_LONG_PRESS = 21;

    private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
    private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
@@ -899,6 +906,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;
                }
            }
        }
    }
@@ -987,6 +999,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);
@@ -2253,6 +2274,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);
@@ -6297,6 +6325,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) {
@@ -6480,7 +6544,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());
    }
@@ -6537,6 +6606,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;
    }
@@ -6556,7 +6628,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:
@@ -6569,7 +6641,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:
                return false;

            case KeyEvent.KEYCODE_BACK:
@@ -6580,6 +6651,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;
    }