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

Commit fd836582 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 d2ad3baf
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1975,6 +1975,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
    public static final boolean isWakeKey(int keyCode) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_CAMERA:
            case KeyEvent.KEYCODE_FOCUS:
            case KeyEvent.KEYCODE_MENU:
            case KeyEvent.KEYCODE_PAIRING:
            case KeyEvent.KEYCODE_STEM_1:
+0 −13
Original line number Diff line number Diff line
@@ -150,19 +150,6 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler {
                    dispatcher.startTracking(event, this);
                } else if (event.isLongPress() && dispatcher.isTracking(event)) {
                    dispatcher.performedLongPress(event);
                    if (isUserSetupComplete()) {
                        mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                        sendCloseSystemWindows();
                        // Broadcast an intent that the Camera button was longpressed
                        Intent intent = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
                        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
                        intent.putExtra(Intent.EXTRA_KEY_EVENT, event);
                        mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF,
                                null, null, null, 0, null, null);
                    } else {
                        Log.i(TAG, "Not dispatching CAMERA long press because user "
                                + "setup is in progress.");
                    }
                }
                return true;
            }
+88 −0
Original line number Diff line number Diff line
@@ -518,8 +518,16 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    boolean mWakeOnHomeKeyPress;
    boolean mWakeOnMenuKeyPress;
    boolean mWakeOnAppSwitchKeyPress;
    boolean mWakeOnCameraKeyPress;
    boolean mWakeOnVolumeKeyPress;

    // Camera button control flags and actions
    boolean mCameraLaunch;
    boolean mCameraSleepOnRelease;
    boolean mFocusReleasedGoToSleep;
    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.
@@ -693,6 +701,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {

    // Lineage additions
    private static final int MSG_TOGGLE_TORCH = 100;
    private static final int MSG_CAMERA_LONG_PRESS = 101;

    private CameraManager mCameraManager;
    private String mRearFlashCameraId;
@@ -787,6 +796,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;
            }
        }
    }
@@ -815,6 +828,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(Settings.Secure.getUriFor(
                    Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR), 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.RING_HOME_BUTTON_BEHAVIOR), false, this,
                    UserHandle.USER_ALL);
@@ -2370,6 +2392,16 @@ 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);
            mWakeOnCameraKeyPress = (LineageSettings.System.getIntForUser(resolver,
                    LineageSettings.System.CAMERA_WAKE_SCREEN, 0, UserHandle.USER_CURRENT) == 1)
                    && ((mDeviceHardwareWakeKeys & KEY_MASK_CAMERA) != 0);
            mCameraSleepOnRelease = mWakeOnCameraKeyPress &&
                    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;

            // Configure wake gesture.
            boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
@@ -4304,6 +4336,50 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                }
                break;

            case KeyEvent.KEYCODE_FOCUS:
                if (down && !interactive && mCameraSleepOnRelease) {
                    mIsFocusPressed = true;
                } else if (!down) {
                    // Check if screen is fully on before letting the device go to sleep
                    if (mDefaultDisplayPolicy.isScreenOnFully() && mIsFocusPressed) {
                        mPowerManager.goToSleep(SystemClock.uptimeMillis());
                    } else if (!interactive && mCameraSleepOnRelease) {
                        mFocusReleasedGoToSleep = true;
                    }
                    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) {
@@ -4635,6 +4711,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                return mWakeOnAssistKeyPress;
            case KeyEvent.KEYCODE_APP_SWITCH:
                return mWakeOnAppSwitchKeyPress;
            case KeyEvent.KEYCODE_CAMERA:
            case KeyEvent.KEYCODE_FOCUS:
                return mWakeOnCameraKeyPress;
        }
        return true;
    }
@@ -4686,6 +4765,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {

            case KeyEvent.KEYCODE_APP_SWITCH:
                return mWakeOnAppSwitchKeyPress;

            case KeyEvent.KEYCODE_CAMERA:
            case KeyEvent.KEYCODE_FOCUS:
                return mWakeOnCameraKeyPress;
        }

        return true;
@@ -5183,6 +5266,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            } catch (RemoteException unhandled) {
            }
        }

        if (mFocusReleasedGoToSleep) {
            mFocusReleasedGoToSleep = false;
            mPowerManager.goToSleep(SystemClock.uptimeMillis());
        }
    }

    private void handleHideBootMessage() {