Merge "CEC: Handles initiation of press-and-hold correctly" into lmp-mr1-dev

This commit is contained in:
Jinsuk Kim
2015-01-23 21:10:37 +00:00
committed by Android (Google) Code Review

View File

@@ -35,14 +35,25 @@ import android.view.KeyEvent;
final class SendKeyAction extends HdmiCecFeatureAction { final class SendKeyAction extends HdmiCecFeatureAction {
private static final String TAG = "SendKeyAction"; 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, // 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 // 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. // event, which can lead the device on the receiving end to generating unintended key repeats.
private static final int AWAIT_RELEASE_KEY_MS = 1000; 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 // State in which the long press is being checked at the beginning. The state is set in
// persists throughout the process till it is set back to {@code STATE_NONE} at the end. // {@link #start()} and lasts for {@link #AWAIT_LONGPRESS_MS}.
private static final int STATE_PROCESSING_KEYCODE = 1; 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. // Logical address of the device to which the UCP/UCP commands are sent.
private final int mTargetAddress; private final int mTargetAddress;
@@ -77,8 +88,8 @@ final class SendKeyAction extends HdmiCecFeatureAction {
finish(); finish();
return true; return true;
} }
mState = STATE_PROCESSING_KEYCODE; mState = STATE_CHECKING_LONGPRESS;
addTimer(mState, AWAIT_RELEASE_KEY_MS); addTimer(mState, AWAIT_LONGPRESS_MS);
return true; return true;
} }
@@ -93,7 +104,7 @@ final class SendKeyAction extends HdmiCecFeatureAction {
* @param isPressed true if the key event is of {@link KeyEvent#ACTION_DOWN} * @param isPressed true if the key event is of {@link KeyEvent#ACTION_DOWN}
*/ */
void processKeyEvent(int keycode, boolean isPressed) { 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"); Slog.w(TAG, "Not in a valid state");
return; return;
} }
@@ -152,12 +163,23 @@ final class SendKeyAction extends HdmiCecFeatureAction {
@Override @Override
public void handleTimerEvent(int state) { public void handleTimerEvent(int state) {
// Timeout on waiting for the release key event. Send UCR and quit the action. switch (mState) {
if (mState != STATE_PROCESSING_KEYCODE) { case STATE_CHECKING_LONGPRESS:
Slog.w(TAG, "Not in a valid state"); // The first key press lasts long enough to start press-and-hold.
return; 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();
} }
} }