diff --git a/core/java/android/view/KeyEvent.java b/core/java/android/view/KeyEvent.java index af0d13d8c273..8f6f0cfac118 100644 --- a/core/java/android/view/KeyEvent.java +++ b/core/java/android/view/KeyEvent.java @@ -1880,6 +1880,8 @@ public static final boolean isWakeKey(int keyCode) { 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; diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index ff232022e8f6..a107eef16afb 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -659,8 +659,16 @@ public void onDrawn() { boolean mMenuWakeScreen; boolean mAssistWakeScreen; boolean mAppSwitchWakeScreen; + boolean mCameraWakeScreen; boolean mVolumeWakeScreen; + // 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. @@ -915,6 +923,7 @@ public void onDrawn() { private static final int MSG_NOTIFY_USER_ACTIVITY = 29; private static final int MSG_RINGER_TOGGLE_CHORD = 30; private static final int MSG_TOGGLE_TORCH = 31; + private static final int MSG_CAMERA_LONG_PRESS = 32; private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0; private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1; @@ -1037,6 +1046,10 @@ public void handleMessage(Message msg) { case MSG_TOGGLE_TORCH: toggleTorch(); break; + case MSG_CAMERA_LONG_PRESS: + KeyEvent event = (KeyEvent) msg.obj; + mIsLongPress = true; + break; } } } @@ -1065,6 +1078,15 @@ void observe() { 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); @@ -2834,6 +2856,15 @@ public void updateSettings() { && ((mDeviceHardwareWakeKeys & KEY_MASK_VOLUME) != 0); mKillAppLongpressBack = LineageSettings.Secure.getInt(resolver, LineageSettings.Secure.KILL_APP_LONGPRESS_BACK, 0) == 1; + 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; // Configure wake gesture. boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver, @@ -6795,6 +6826,50 @@ public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { } 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 (mScreenOnFully && mIsFocusPressed) { + mPowerManager.goToSleep(SystemClock.uptimeMillis()); + } else { + 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) { @@ -7088,6 +7163,9 @@ private boolean isWakeKeyEnabled(int keyCode) { return mAssistWakeScreen; case KeyEvent.KEYCODE_APP_SWITCH: return mAppSwitchWakeScreen; + case KeyEvent.KEYCODE_CAMERA: + case KeyEvent.KEYCODE_FOCUS: + return mCameraWakeScreen; } return true; } @@ -7107,7 +7185,7 @@ private boolean isWakeKeyWhenScreenOff(int keyCode) { 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: @@ -7120,7 +7198,6 @@ private boolean isWakeKeyWhenScreenOff(int keyCode) { 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: @@ -7131,6 +7208,9 @@ private boolean isWakeKeyWhenScreenOff(int keyCode) { return mAssistWakeScreen; case KeyEvent.KEYCODE_APP_SWITCH: return mAppSwitchWakeScreen; + case KeyEvent.KEYCODE_CAMERA: + case KeyEvent.KEYCODE_FOCUS: + return mCameraWakeScreen; } return true; } @@ -7671,6 +7751,11 @@ private void finishScreenTurningOn() { } catch (RemoteException unhandled) { } } + + if (mFocusReleasedGoToSleep) { + mFocusReleasedGoToSleep = false; + mPowerManager.goToSleep(SystemClock.uptimeMillis()); + } } private void handleHideBootMessage() {