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

Commit 6eabbf9d 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

Change-Id: Ia515c04cca098bf0d20b077ebffc079ee4008f21
parent cd97f111
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1879,6 +1879,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;
+78 −2
Original line number Diff line number Diff line
@@ -611,8 +611,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    boolean mMenuWakeScreen;
    boolean mAssistWakeScreen;
    boolean mAppSwitchWakeScreen;
    boolean mCameraWakeScreen;
    boolean mVolumeWakeScreen;

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

    // 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.
@@ -898,6 +905,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private static final int MSG_SYSTEM_KEY_PRESS = 25;
    private static final int MSG_HANDLE_ALL_APPS = 26;
    private static final int MSG_TOGGLE_TORCH = 27;
    private static final int MSG_CAMERA_LONG_PRESS = 28;

    private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
    private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
@@ -1005,6 +1013,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                case MSG_TOGGLE_TORCH:
                    toggleTorch();
                    break;
                case MSG_CAMERA_LONG_PRESS:
                    KeyEvent event = (KeyEvent) msg.obj;
                    mIsLongPress = true;
                    break;
            }
        }
    }
@@ -1117,6 +1129,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.VOLUME_ANSWER_CALL), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.CAMERA_WAKE_SCREEN), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.CAMERA_SLEEP_ON_RELEASE), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.CAMERA_LAUNCH), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(LineageSettings.Secure.getUriFor(
                    LineageSettings.Secure.KILL_APP_LONGPRESS_BACK), false, this,
                    UserHandle.USER_ALL);
@@ -2647,6 +2668,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            mVolumeAnswerCall = (LineageSettings.System.getIntForUser(resolver,
                    LineageSettings.System.VOLUME_ANSWER_CALL, 0, UserHandle.USER_CURRENT) == 1)
                    && ((mDeviceHardwareWakeKeys & KEY_MASK_VOLUME) != 0);
            mCameraWakeScreen = (LineageSettings.System.getIntForUser(resolver,
                    LineageSettings.System.CAMERA_WAKE_SCREEN, 0, UserHandle.USER_CURRENT) == 1)
                    && ((mDeviceHardwareWakeKeys & KEY_MASK_CAMERA) != 0);
            mCameraSleepOnRelease = LineageSettings.System.getIntForUser(
                    resolver, LineageSettings.System.CAMERA_SLEEP_ON_RELEASE, 0,
                    UserHandle.USER_CURRENT) == 1;
            mCameraLaunch = LineageSettings.System.getIntForUser(
                    resolver, LineageSettings.System.CAMERA_LAUNCH, 0,
                    UserHandle.USER_CURRENT) == 1;
            mKillAppLongpressBack = LineageSettings.Secure.getInt(
                    resolver, LineageSettings.Secure.KILL_APP_LONGPRESS_BACK, 0) == 1;

@@ -6672,6 +6702,47 @@ 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;

                    KeyEvent newEvent = new KeyEvent(event.getDownTime(), event.getEventTime(),
                            event.getAction(), keyCode, 0);
                    Message msg = mHandler.obtainMessage(MSG_CAMERA_LONG_PRESS, newEvent);
                    msg.setAsynchronous(true);
                    mHandler.sendMessageDelayed(msg, ViewConfiguration.getLongPressTimeout());
                    // 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) {
@@ -6933,6 +7004,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;
    }
@@ -6952,7 +7026,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:
@@ -6965,7 +7039,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:
@@ -6976,6 +7049,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;
    }