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

Unverified Commit 1a38098b 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 7ba04f31
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -1993,6 +1993,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
    public static final boolean isWakeKey(int keyCode) {
    public static final boolean isWakeKey(int keyCode) {
        switch (keyCode) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_CAMERA:
            case KeyEvent.KEYCODE_CAMERA:
            case KeyEvent.KEYCODE_FOCUS:
            case KeyEvent.KEYCODE_MENU:
            case KeyEvent.KEYCODE_MENU:
            case KeyEvent.KEYCODE_PAIRING:
            case KeyEvent.KEYCODE_PAIRING:
            case KeyEvent.KEYCODE_STEM_1:
            case KeyEvent.KEYCODE_STEM_1:
+0 −12
Original line number Original line Diff line number Diff line
@@ -144,18 +144,6 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler {
                    dispatcher.startTracking(event, this);
                    dispatcher.startTracking(event, this);
                } else if (event.isLongPress() && dispatcher.isTracking(event)) {
                } else if (event.isLongPress() && dispatcher.isTracking(event)) {
                    dispatcher.performedLongPress(event);
                    dispatcher.performedLongPress(event);
                    if (isUserSetupComplete()) {
                        mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                        // 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;
                return true;
            }
            }
+96 −7
Original line number Original line Diff line number Diff line
@@ -531,8 +531,16 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    boolean mWakeOnHomeKeyPress;
    boolean mWakeOnHomeKeyPress;
    boolean mWakeOnMenuKeyPress;
    boolean mWakeOnMenuKeyPress;
    boolean mWakeOnAppSwitchKeyPress;
    boolean mWakeOnAppSwitchKeyPress;
    boolean mWakeOnCameraKeyPress;
    boolean mWakeOnVolumeKeyPress;
    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
    // 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.
@@ -680,6 +688,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {


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


    private CameraManager mCameraManager;
    private CameraManager mCameraManager;
    private String mRearFlashCameraId;
    private String mRearFlashCameraId;
@@ -759,6 +768,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                case MSG_TOGGLE_TORCH:
                case MSG_TOGGLE_TORCH:
                    toggleTorch();
                    toggleTorch();
                    break;
                    break;
                case MSG_CAMERA_LONG_PRESS:
                    KeyEvent event = (KeyEvent) msg.obj;
                    mIsLongPress = true;
                    break;
            }
            }
        }
        }
    }
    }
@@ -787,6 +800,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(Settings.Secure.getUriFor(
            resolver.registerContentObserver(Settings.Secure.getUriFor(
                    Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR), false, this,
                    Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR), false, this,
                    UserHandle.USER_ALL);
                    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(
            resolver.registerContentObserver(LineageSettings.Secure.getUriFor(
                    LineageSettings.Secure.RING_HOME_BUTTON_BEHAVIOR), false, this,
                    LineageSettings.Secure.RING_HOME_BUTTON_BEHAVIOR), false, this,
                    UserHandle.USER_ALL);
                    UserHandle.USER_ALL);
@@ -2479,6 +2501,16 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            mVolumeAnswerCall = (LineageSettings.System.getIntForUser(resolver,
            mVolumeAnswerCall = (LineageSettings.System.getIntForUser(resolver,
                    LineageSettings.System.VOLUME_ANSWER_CALL, 0, UserHandle.USER_CURRENT) == 1)
                    LineageSettings.System.VOLUME_ANSWER_CALL, 0, UserHandle.USER_CURRENT) == 1)
                    && ((mDeviceHardwareWakeKeys & KEY_MASK_VOLUME) != 0);
                    && ((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.
            // Configure wake gesture.
            boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
            boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
@@ -3909,7 +3941,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        final int displayId = event.getDisplayId();
        final int displayId = event.getDisplayId();
        final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
        final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;


        if (DEBUG_INPUT) {
        // If screen is off then we treat the case where the keyguard is open but hidden
        // If screen is off then we treat the case where the keyguard is open but hidden
        // the same as if it were open and in front.
        // the same as if it were open and in front.
        // This will prevent any keys other than the power button from waking the screen
        // This will prevent any keys other than the power button from waking the screen
@@ -3917,6 +3948,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        final boolean keyguardActive = (mKeyguardDelegate != null
        final boolean keyguardActive = (mKeyguardDelegate != null
                && (interactive ? isKeyguardShowingAndNotOccluded() :
                && (interactive ? isKeyguardShowingAndNotOccluded() :
                mKeyguardDelegate.isShowing()));
                mKeyguardDelegate.isShowing()));

        if (DEBUG_INPUT) {
            Log.d(TAG, "interceptKeyTq keycode=" + keyCode
            Log.d(TAG, "interceptKeyTq keycode=" + keyCode
                    + " interactive=" + interactive + " keyguardActive=" + keyguardActive
                    + " interactive=" + interactive + " keyguardActive=" + keyguardActive
                    + " policyFlags=" + Integer.toHexString(policyFlags));
                    + " policyFlags=" + Integer.toHexString(policyFlags));
@@ -4147,6 +4180,50 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                }
                }
                break;
                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: {
            case KeyEvent.KEYCODE_ENDCALL: {
                result &= ~ACTION_PASS_TO_USER;
                result &= ~ACTION_PASS_TO_USER;
                if (down) {
                if (down) {
@@ -4511,6 +4588,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                return mWakeOnAssistKeyPress;
                return mWakeOnAssistKeyPress;
            case KeyEvent.KEYCODE_APP_SWITCH:
            case KeyEvent.KEYCODE_APP_SWITCH:
                return mWakeOnAppSwitchKeyPress;
                return mWakeOnAppSwitchKeyPress;
            case KeyEvent.KEYCODE_CAMERA:
            case KeyEvent.KEYCODE_FOCUS:
                return mWakeOnCameraKeyPress;
        }
        }
        return true;
        return true;
    }
    }
@@ -4562,6 +4642,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {


            case KeyEvent.KEYCODE_APP_SWITCH:
            case KeyEvent.KEYCODE_APP_SWITCH:
                return mWakeOnAppSwitchKeyPress;
                return mWakeOnAppSwitchKeyPress;

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


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

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


    private void handleHideBootMessage() {
    private void handleHideBootMessage() {