Skip to content

Commit

Permalink
Camera button support
Browse files Browse the repository at this point in the history
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
  • Loading branch information
HazouPH authored and bgcngm committed Sep 29, 2018
1 parent 4739407 commit bb8262d
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 2 deletions.
2 changes: 2 additions & 0 deletions core/java/android/view/KeyEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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;
}
Expand Down Expand Up @@ -7671,6 +7751,11 @@ private void finishScreenTurningOn() {
} catch (RemoteException unhandled) {
}
}

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

private void handleHideBootMessage() {
Expand Down

0 comments on commit bb8262d

Please sign in to comment.