Loading services/core/java/com/android/server/hdmi/OneTouchPlayAction.java +10 −1 Original line number Diff line number Diff line Loading @@ -54,7 +54,9 @@ final class OneTouchPlayAction extends HdmiCecFeatureAction { // The maximum number of times we send <Give Device Power Status> before we give up. // We wait up to RESPONSE_TIMEOUT_MS * LOOP_COUNTER_MAX = 20 seconds. private static final int LOOP_COUNTER_MAX = 10; // Every 3 timeouts we send a <Text View On> in case the TV missed it and ignored it. @VisibleForTesting static final int LOOP_COUNTER_MAX = 10; private final int mTargetAddress; private final boolean mIsCec20; Loading Loading @@ -181,6 +183,7 @@ final class OneTouchPlayAction extends HdmiCecFeatureAction { if (cmd.getOpcode() == Constants.MESSAGE_REPORT_POWER_STATUS) { int status = cmd.getParams()[0]; if (status == HdmiControlManager.POWER_STATUS_ON) { HdmiLogger.debug("TV's power status is on. Action finished successfully"); // If the device is still the active source, send the <Active Source> message // again. maySendActiveSource(); Loading @@ -199,6 +202,12 @@ final class OneTouchPlayAction extends HdmiCecFeatureAction { switch (state) { case STATE_WAITING_FOR_REPORT_POWER_STATUS: if (mPowerStatusCounter++ < LOOP_COUNTER_MAX) { if (mPowerStatusCounter % 3 == 0) { HdmiLogger.debug("Retry sending <Text View On> in case the TV " + "missed the message."); sendCommand(HdmiCecMessageBuilder.buildTextViewOn(getSourceAddress(), mTargetAddress)); } queryDevicePowerStatus(); addTimer(mState, HdmiConfig.TIMEOUT_MS); } else { Loading services/tests/servicestests/src/com/android/server/hdmi/OneTouchPlayActionTest.java +117 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static com.android.server.SystemService.PHASE_SYSTEM_SERVICES_READY; import static com.android.server.hdmi.Constants.ADDR_TV; import static com.android.server.hdmi.HdmiControlService.INITIATED_BY_ENABLE_CEC; import static com.android.server.hdmi.HdmiControlService.WAKE_UP_SCREEN_ON; import static com.android.server.hdmi.OneTouchPlayAction.LOOP_COUNTER_MAX; import static com.android.server.hdmi.OneTouchPlayAction.STATE_WAITING_FOR_REPORT_POWER_STATUS; import static com.google.common.truth.Truth.assertThat; Loading Loading @@ -335,7 +336,7 @@ public class OneTouchPlayActionTest { mTestLooper.dispatchAll(); } assertThat(mNativeWrapper.getResultMessages()).doesNotContain(textViewOn); assertThat(mNativeWrapper.getResultMessages()).contains(textViewOn); assertThat(mNativeWrapper.getResultMessages()).doesNotContain(activeSource); assertThat(mNativeWrapper.getResultMessages()).contains(giveDevicePowerStatus); action.handleTimerEvent(STATE_WAITING_FOR_REPORT_POWER_STATUS); Loading Loading @@ -672,7 +673,122 @@ public class OneTouchPlayActionTest { mHdmiControlService.playback().getDeviceInfo().getLogicalAddress(), ADDR_TV); assertThat(mNativeWrapper.getResultMessages()).doesNotContain(textViewOn); } @Test public void waitForReportPowerStatus_resendTextViewOn_timeout() throws Exception { setUp(true); HdmiCecLocalDevicePlayback playbackDevice = mHdmiControlService.playback(); mTestLooper.dispatchAll(); mNativeWrapper.setPollAddressResponse(ADDR_TV, SendMessageResult.SUCCESS); mHdmiControlService.getHdmiCecNetwork().addCecDevice(INFO_TV); mTestLooper.dispatchAll(); mNativeWrapper.clearResultMessages(); TestActionTimer actionTimer = new TestActionTimer(); TestCallback callback = new TestCallback(); OneTouchPlayAction action = createOneTouchPlayAction(playbackDevice, actionTimer, callback, false); playbackDevice.addAndStartAction(action); mTestLooper.dispatchAll(); HdmiCecMessage activeSource = HdmiCecMessageBuilder.buildActiveSource( playbackDevice.getDeviceInfo().getLogicalAddress(), mPhysicalAddress); HdmiCecMessage textViewOn = HdmiCecMessageBuilder.buildTextViewOn( playbackDevice.getDeviceInfo().getLogicalAddress(), ADDR_TV); HdmiCecMessage giveDevicePowerStatus = HdmiCecMessageBuilder.buildGiveDevicePowerStatus( playbackDevice.getDeviceInfo().getLogicalAddress(), ADDR_TV); assertThat(mNativeWrapper.getResultMessages()).contains(textViewOn); assertThat(mNativeWrapper.getResultMessages()).contains(activeSource); assertThat(mNativeWrapper.getResultMessages()).contains(giveDevicePowerStatus); mNativeWrapper.clearResultMessages(); assertThat(actionTimer.getState()).isEqualTo(STATE_WAITING_FOR_REPORT_POWER_STATUS); int counter = 0; while (counter++ < LOOP_COUNTER_MAX) { action.handleTimerEvent(STATE_WAITING_FOR_REPORT_POWER_STATUS); mTestLooper.dispatchAll(); if (counter % 3 == 0) { assertThat(mNativeWrapper.getResultMessages()).contains(textViewOn); } assertThat(mNativeWrapper.getResultMessages()).contains(giveDevicePowerStatus); mNativeWrapper.clearResultMessages(); mTestLooper.dispatchAll(); } action.handleTimerEvent(STATE_WAITING_FOR_REPORT_POWER_STATUS); assertThat(callback.getResult()).isEqualTo(HdmiControlManager.RESULT_TIMEOUT); } @Test public void waitForReportPowerStatus_resendTextViewOn_success() throws Exception { setUp(true); HdmiCecLocalDevicePlayback playbackDevice = mHdmiControlService.playback(); mTestLooper.dispatchAll(); mNativeWrapper.setPollAddressResponse(ADDR_TV, SendMessageResult.SUCCESS); mHdmiControlService.getHdmiCecNetwork().addCecDevice(INFO_TV); mTestLooper.dispatchAll(); mNativeWrapper.clearResultMessages(); TestActionTimer actionTimer = new TestActionTimer(); TestCallback callback = new TestCallback(); OneTouchPlayAction action = createOneTouchPlayAction(playbackDevice, actionTimer, callback, false); playbackDevice.addAndStartAction(action); mTestLooper.dispatchAll(); HdmiCecMessage activeSource = HdmiCecMessageBuilder.buildActiveSource( playbackDevice.getDeviceInfo().getLogicalAddress(), mPhysicalAddress); HdmiCecMessage textViewOn = HdmiCecMessageBuilder.buildTextViewOn( playbackDevice.getDeviceInfo().getLogicalAddress(), ADDR_TV); HdmiCecMessage giveDevicePowerStatus = HdmiCecMessageBuilder.buildGiveDevicePowerStatus( playbackDevice.getDeviceInfo().getLogicalAddress(), ADDR_TV); assertThat(mNativeWrapper.getResultMessages()).contains(textViewOn); assertThat(mNativeWrapper.getResultMessages()).contains(activeSource); assertThat(mNativeWrapper.getResultMessages()).contains(giveDevicePowerStatus); mNativeWrapper.clearResultMessages(); assertThat(actionTimer.getState()).isEqualTo(STATE_WAITING_FOR_REPORT_POWER_STATUS); int counter = 0; while (counter++ < LOOP_COUNTER_MAX) { action.handleTimerEvent(STATE_WAITING_FOR_REPORT_POWER_STATUS); mTestLooper.dispatchAll(); if (counter % 3 == 0) { assertThat(mNativeWrapper.getResultMessages()).contains(textViewOn); } assertThat(mNativeWrapper.getResultMessages()).contains(giveDevicePowerStatus); mNativeWrapper.clearResultMessages(); mTestLooper.dispatchAll(); } assertThat(actionTimer.getState()).isEqualTo(STATE_WAITING_FOR_REPORT_POWER_STATUS); HdmiCecMessage reportPowerStatusOn = HdmiCecMessage.build( ADDR_TV, playbackDevice.getDeviceInfo().getLogicalAddress(), Constants.MESSAGE_REPORT_POWER_STATUS, POWER_ON); action.processCommand(reportPowerStatusOn); mTestLooper.dispatchAll(); assertThat(mNativeWrapper.getResultMessages()).doesNotContain(textViewOn); assertThat(mNativeWrapper.getResultMessages()).contains(activeSource); assertThat(mNativeWrapper.getResultMessages()).doesNotContain(giveDevicePowerStatus); assertThat(callback.getResult()).isEqualTo(HdmiControlManager.RESULT_SUCCESS); } private static class TestActionTimer implements ActionTimer { Loading Loading
services/core/java/com/android/server/hdmi/OneTouchPlayAction.java +10 −1 Original line number Diff line number Diff line Loading @@ -54,7 +54,9 @@ final class OneTouchPlayAction extends HdmiCecFeatureAction { // The maximum number of times we send <Give Device Power Status> before we give up. // We wait up to RESPONSE_TIMEOUT_MS * LOOP_COUNTER_MAX = 20 seconds. private static final int LOOP_COUNTER_MAX = 10; // Every 3 timeouts we send a <Text View On> in case the TV missed it and ignored it. @VisibleForTesting static final int LOOP_COUNTER_MAX = 10; private final int mTargetAddress; private final boolean mIsCec20; Loading Loading @@ -181,6 +183,7 @@ final class OneTouchPlayAction extends HdmiCecFeatureAction { if (cmd.getOpcode() == Constants.MESSAGE_REPORT_POWER_STATUS) { int status = cmd.getParams()[0]; if (status == HdmiControlManager.POWER_STATUS_ON) { HdmiLogger.debug("TV's power status is on. Action finished successfully"); // If the device is still the active source, send the <Active Source> message // again. maySendActiveSource(); Loading @@ -199,6 +202,12 @@ final class OneTouchPlayAction extends HdmiCecFeatureAction { switch (state) { case STATE_WAITING_FOR_REPORT_POWER_STATUS: if (mPowerStatusCounter++ < LOOP_COUNTER_MAX) { if (mPowerStatusCounter % 3 == 0) { HdmiLogger.debug("Retry sending <Text View On> in case the TV " + "missed the message."); sendCommand(HdmiCecMessageBuilder.buildTextViewOn(getSourceAddress(), mTargetAddress)); } queryDevicePowerStatus(); addTimer(mState, HdmiConfig.TIMEOUT_MS); } else { Loading
services/tests/servicestests/src/com/android/server/hdmi/OneTouchPlayActionTest.java +117 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static com.android.server.SystemService.PHASE_SYSTEM_SERVICES_READY; import static com.android.server.hdmi.Constants.ADDR_TV; import static com.android.server.hdmi.HdmiControlService.INITIATED_BY_ENABLE_CEC; import static com.android.server.hdmi.HdmiControlService.WAKE_UP_SCREEN_ON; import static com.android.server.hdmi.OneTouchPlayAction.LOOP_COUNTER_MAX; import static com.android.server.hdmi.OneTouchPlayAction.STATE_WAITING_FOR_REPORT_POWER_STATUS; import static com.google.common.truth.Truth.assertThat; Loading Loading @@ -335,7 +336,7 @@ public class OneTouchPlayActionTest { mTestLooper.dispatchAll(); } assertThat(mNativeWrapper.getResultMessages()).doesNotContain(textViewOn); assertThat(mNativeWrapper.getResultMessages()).contains(textViewOn); assertThat(mNativeWrapper.getResultMessages()).doesNotContain(activeSource); assertThat(mNativeWrapper.getResultMessages()).contains(giveDevicePowerStatus); action.handleTimerEvent(STATE_WAITING_FOR_REPORT_POWER_STATUS); Loading Loading @@ -672,7 +673,122 @@ public class OneTouchPlayActionTest { mHdmiControlService.playback().getDeviceInfo().getLogicalAddress(), ADDR_TV); assertThat(mNativeWrapper.getResultMessages()).doesNotContain(textViewOn); } @Test public void waitForReportPowerStatus_resendTextViewOn_timeout() throws Exception { setUp(true); HdmiCecLocalDevicePlayback playbackDevice = mHdmiControlService.playback(); mTestLooper.dispatchAll(); mNativeWrapper.setPollAddressResponse(ADDR_TV, SendMessageResult.SUCCESS); mHdmiControlService.getHdmiCecNetwork().addCecDevice(INFO_TV); mTestLooper.dispatchAll(); mNativeWrapper.clearResultMessages(); TestActionTimer actionTimer = new TestActionTimer(); TestCallback callback = new TestCallback(); OneTouchPlayAction action = createOneTouchPlayAction(playbackDevice, actionTimer, callback, false); playbackDevice.addAndStartAction(action); mTestLooper.dispatchAll(); HdmiCecMessage activeSource = HdmiCecMessageBuilder.buildActiveSource( playbackDevice.getDeviceInfo().getLogicalAddress(), mPhysicalAddress); HdmiCecMessage textViewOn = HdmiCecMessageBuilder.buildTextViewOn( playbackDevice.getDeviceInfo().getLogicalAddress(), ADDR_TV); HdmiCecMessage giveDevicePowerStatus = HdmiCecMessageBuilder.buildGiveDevicePowerStatus( playbackDevice.getDeviceInfo().getLogicalAddress(), ADDR_TV); assertThat(mNativeWrapper.getResultMessages()).contains(textViewOn); assertThat(mNativeWrapper.getResultMessages()).contains(activeSource); assertThat(mNativeWrapper.getResultMessages()).contains(giveDevicePowerStatus); mNativeWrapper.clearResultMessages(); assertThat(actionTimer.getState()).isEqualTo(STATE_WAITING_FOR_REPORT_POWER_STATUS); int counter = 0; while (counter++ < LOOP_COUNTER_MAX) { action.handleTimerEvent(STATE_WAITING_FOR_REPORT_POWER_STATUS); mTestLooper.dispatchAll(); if (counter % 3 == 0) { assertThat(mNativeWrapper.getResultMessages()).contains(textViewOn); } assertThat(mNativeWrapper.getResultMessages()).contains(giveDevicePowerStatus); mNativeWrapper.clearResultMessages(); mTestLooper.dispatchAll(); } action.handleTimerEvent(STATE_WAITING_FOR_REPORT_POWER_STATUS); assertThat(callback.getResult()).isEqualTo(HdmiControlManager.RESULT_TIMEOUT); } @Test public void waitForReportPowerStatus_resendTextViewOn_success() throws Exception { setUp(true); HdmiCecLocalDevicePlayback playbackDevice = mHdmiControlService.playback(); mTestLooper.dispatchAll(); mNativeWrapper.setPollAddressResponse(ADDR_TV, SendMessageResult.SUCCESS); mHdmiControlService.getHdmiCecNetwork().addCecDevice(INFO_TV); mTestLooper.dispatchAll(); mNativeWrapper.clearResultMessages(); TestActionTimer actionTimer = new TestActionTimer(); TestCallback callback = new TestCallback(); OneTouchPlayAction action = createOneTouchPlayAction(playbackDevice, actionTimer, callback, false); playbackDevice.addAndStartAction(action); mTestLooper.dispatchAll(); HdmiCecMessage activeSource = HdmiCecMessageBuilder.buildActiveSource( playbackDevice.getDeviceInfo().getLogicalAddress(), mPhysicalAddress); HdmiCecMessage textViewOn = HdmiCecMessageBuilder.buildTextViewOn( playbackDevice.getDeviceInfo().getLogicalAddress(), ADDR_TV); HdmiCecMessage giveDevicePowerStatus = HdmiCecMessageBuilder.buildGiveDevicePowerStatus( playbackDevice.getDeviceInfo().getLogicalAddress(), ADDR_TV); assertThat(mNativeWrapper.getResultMessages()).contains(textViewOn); assertThat(mNativeWrapper.getResultMessages()).contains(activeSource); assertThat(mNativeWrapper.getResultMessages()).contains(giveDevicePowerStatus); mNativeWrapper.clearResultMessages(); assertThat(actionTimer.getState()).isEqualTo(STATE_WAITING_FOR_REPORT_POWER_STATUS); int counter = 0; while (counter++ < LOOP_COUNTER_MAX) { action.handleTimerEvent(STATE_WAITING_FOR_REPORT_POWER_STATUS); mTestLooper.dispatchAll(); if (counter % 3 == 0) { assertThat(mNativeWrapper.getResultMessages()).contains(textViewOn); } assertThat(mNativeWrapper.getResultMessages()).contains(giveDevicePowerStatus); mNativeWrapper.clearResultMessages(); mTestLooper.dispatchAll(); } assertThat(actionTimer.getState()).isEqualTo(STATE_WAITING_FOR_REPORT_POWER_STATUS); HdmiCecMessage reportPowerStatusOn = HdmiCecMessage.build( ADDR_TV, playbackDevice.getDeviceInfo().getLogicalAddress(), Constants.MESSAGE_REPORT_POWER_STATUS, POWER_ON); action.processCommand(reportPowerStatusOn); mTestLooper.dispatchAll(); assertThat(mNativeWrapper.getResultMessages()).doesNotContain(textViewOn); assertThat(mNativeWrapper.getResultMessages()).contains(activeSource); assertThat(mNativeWrapper.getResultMessages()).doesNotContain(giveDevicePowerStatus); assertThat(callback.getResult()).isEqualTo(HdmiControlManager.RESULT_SUCCESS); } private static class TestActionTimer implements ActionTimer { Loading