diff options
| author | 2015-01-23 21:16:48 +0000 | |
|---|---|---|
| committer | 2015-01-23 21:16:48 +0000 | |
| commit | ca1384dc5abb2d29906310fd577c5ed6fba25f24 (patch) | |
| tree | d08ed7928fe0416d28125f0d12ae8f18d25a0110 | |
| parent | bb8d7ffeae187e8782a9494e252e335db537b2a1 (diff) | |
| parent | 56c119abde951146951e3887796eb64ee05d25d3 (diff) | |
am 56c119ab: Merge "CEC: Handles initiation of press-and-hold correctly" into lmp-mr1-dev
* commit '56c119abde951146951e3887796eb64ee05d25d3':
CEC: Handles initiation of press-and-hold correctly
| -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 eef5010f00d2..40d2583691c6 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(); } } |