diff options
author | Jinsuk Kim <jinsukkim@google.com> | 2015-01-23 21:10:37 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-01-23 21:10:38 +0000 |
commit | 56c119abde951146951e3887796eb64ee05d25d3 (patch) | |
tree | 5b50568359238585eb2c59ce18f161e969a4bbb4 /services/core/java/com/android/server/hdmi | |
parent | 94474515e035d726ff24c48233c452ce34ef7c01 (diff) | |
parent | c4228a72817e3e3b507c3b376a0ed1a77be89267 (diff) | |
download | frameworks_base-56c119abde951146951e3887796eb64ee05d25d3.zip frameworks_base-56c119abde951146951e3887796eb64ee05d25d3.tar.gz frameworks_base-56c119abde951146951e3887796eb64ee05d25d3.tar.bz2 |
Merge "CEC: Handles initiation of press-and-hold correctly" into lmp-mr1-dev
Diffstat (limited to 'services/core/java/com/android/server/hdmi')
-rw-r--r-- | services/core/java/com/android/server/hdmi/SendKeyAction.java | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/services/core/java/com/android/server/hdmi/SendKeyAction.java b/services/core/java/com/android/server/hdmi/SendKeyAction.java index eef5010..40d2583 100644 --- a/services/core/java/com/android/server/hdmi/SendKeyAction.java +++ b/services/core/java/com/android/server/hdmi/SendKeyAction.java @@ -35,14 +35,25 @@ import android.view.KeyEvent; final class SendKeyAction extends HdmiCecFeatureAction { private static final String TAG = "SendKeyAction"; + // If the first key press lasts this much amount of time without any other key event + // coming down, we trigger the press-and-hold operation. Set to the value slightly + // shorter than the threshold(500ms) between two successive key press events + // as specified in the standard for the operation. + private static final int AWAIT_LONGPRESS_MS = 400; + // Amount of time this action waits for a new release key input event. When timed out, // the action sends out UCR and finishes its lifecycle. Used to deal with missing key release // event, which can lead the device on the receiving end to generating unintended key repeats. private static final int AWAIT_RELEASE_KEY_MS = 1000; - // State in which the action is at work. The state is set in {@link #start()} and - // persists throughout the process till it is set back to {@code STATE_NONE} at the end. - private static final int STATE_PROCESSING_KEYCODE = 1; + // State in which the long press is being checked at the beginning. The state is set in + // {@link #start()} and lasts for {@link #AWAIT_LONGPRESS_MS}. + private static final int STATE_CHECKING_LONGPRESS = 1; + + // State in which the action is handling incoming keys. Persists throughout the process + // till it is set back to {@code STATE_NONE} at the end when a release key event for + // the last key is processed. + private static final int STATE_PROCESSING_KEYCODE = 2; // Logical address of the device to which the UCP/UCP commands are sent. private final int mTargetAddress; @@ -77,8 +88,8 @@ final class SendKeyAction extends HdmiCecFeatureAction { finish(); return true; } - mState = STATE_PROCESSING_KEYCODE; - addTimer(mState, AWAIT_RELEASE_KEY_MS); + mState = STATE_CHECKING_LONGPRESS; + addTimer(mState, AWAIT_LONGPRESS_MS); return true; } @@ -93,7 +104,7 @@ final class SendKeyAction extends HdmiCecFeatureAction { * @param isPressed true if the key event is of {@link KeyEvent#ACTION_DOWN} */ void processKeyEvent(int keycode, boolean isPressed) { - if (mState != STATE_PROCESSING_KEYCODE) { + if (mState != STATE_CHECKING_LONGPRESS && mState != STATE_PROCESSING_KEYCODE) { Slog.w(TAG, "Not in a valid state"); return; } @@ -152,12 +163,23 @@ final class SendKeyAction extends HdmiCecFeatureAction { @Override public void handleTimerEvent(int state) { - // Timeout on waiting for the release key event. Send UCR and quit the action. - if (mState != STATE_PROCESSING_KEYCODE) { - Slog.w(TAG, "Not in a valid state"); - return; + switch (mState) { + case STATE_CHECKING_LONGPRESS: + // The first key press lasts long enough to start press-and-hold. + mActionTimer.clearTimerMessage(); + mState = STATE_PROCESSING_KEYCODE; + sendKeyDown(mLastKeycode); + mLastSendKeyTime = getCurrentTime(); + addTimer(mState, AWAIT_RELEASE_KEY_MS); + break; + case STATE_PROCESSING_KEYCODE: + // Timeout on waiting for the release key event. Send UCR and quit the action. + sendKeyUp(); + finish(); + break; + default: + Slog.w(TAG, "Not in a valid state"); + break; } - sendKeyUp(); - finish(); } } |