CEC: Add Analogue Timer validator

Used to validate <Set Analogue Timer> and
<Clear Analogue Timer> message parameters

Test: atest HdmiCecMessageValidatorTest
Bug: 170811408
Change-Id: I7f45d9555f7300fbb8f160f83f2b0c0563192607
This commit is contained in:
Shraddha Basantwani
2020-10-01 10:46:33 +05:30
parent f7633f065d
commit e8543c290e
2 changed files with 100 additions and 0 deletions

View File

@@ -123,6 +123,10 @@ public class HdmiCecMessageValidator {
new RecordStatusInfoValidator(), DEST_DIRECT);
// TODO: Handle messages for the Timer Programming.
addValidationInfo(
Constants.MESSAGE_CLEAR_ANALOG_TIMER, new AnalogueTimerValidator(), DEST_DIRECT);
addValidationInfo(
Constants.MESSAGE_SET_ANALOG_TIMER, new AnalogueTimerValidator(), DEST_DIRECT);
// Messages for the System Information.
FixedLengthValidator oneByteValidator = new FixedLengthValidator(1);
@@ -415,6 +419,42 @@ public class HdmiCecMessageValidator {
return (Integer.bitCount(value) <= 1);
}
/**
* Check if the given value is a valid analogue broadcast type. A valid value is one which falls
* within the range description defined in CEC 1.4 Specification : Operand Descriptions (Section
* 17)
*
* @param value analogue broadcast type
* @return true if the analogue broadcast type is valid
*/
private boolean isValidAnalogueBroadcastType(int value) {
return isWithinRange(value, 0x00, 0x02);
}
/**
* Check if the given value is a valid analogue frequency. A valid value is one which falls
* within the range description defined in CEC 1.4 Specification : Operand Descriptions (Section
* 17)
*
* @param value analogue frequency
* @return true if the analogue frequency is valid
*/
private boolean isValidAnalogueFrequency(int value) {
value = value & 0xFFFF;
return (value != 0x000 && value != 0xFFFF);
}
/**
* Check if the given value is a valid broadcast system. A valid value is one which falls within
* the range description defined in CEC 1.4 Specification : Operand Descriptions (Section 17)
*
* @param value broadcast system
* @return true if the broadcast system is valid
*/
private boolean isValidBroadcastSystem(int value) {
return isWithinRange(value, 0, 31);
}
private class PhysicalAddressValidator implements ParameterValidator {
@Override
public int isValid(byte[] params) {
@@ -544,4 +584,30 @@ public class HdmiCecMessageValidator {
return toErrorCode(isWithinRange(params[0], mMinValue, mMaxValue));
}
}
/**
* Check if the given Analogue Timer message parameters are valid. Valid parameters should
* adhere to message description of Analogue Timer defined in CEC 1.4 Specification : Message
* Descriptions for Timer Programming Feature (CEC Table 12)
*/
private class AnalogueTimerValidator implements ParameterValidator {
@Override
public int isValid(byte[] params) {
if (params.length < 11) {
return ERROR_PARAMETER_SHORT;
}
return toErrorCode(
isValidDayOfMonth(params[0]) // Day of Month
&& isValidMonthOfYear(params[1]) // Month of Year
&& isValidHour(params[2]) // Start Time - Hour
&& isValidMinute(params[3]) // Start Time - Minute
&& isValidDurationHours(params[4]) // Duration - Duration Hours
&& isValidMinute(params[5]) // Duration - Minute
&& isValidRecordingSequence(params[6]) // Recording Sequence
&& isValidAnalogueBroadcastType(params[7]) // Analogue Broadcast Type
&& isValidAnalogueFrequency(
HdmiUtils.twoBytesToInt(params, 8)) // Analogue Frequency
&& isValidBroadcastSystem(params[10])); // Broadcast System
}
}
}

View File

@@ -182,6 +182,40 @@ public class HdmiCecMessageValidatorTest {
assertMessageValidity("40:0A:30").isEqualTo(ERROR_PARAMETER);
}
@Test
public void isValid_setAnalogueTimer_clearAnalogueTimer() {
assertMessageValidity("04:33:0C:08:10:1E:04:30:08:00:13:AD:06").isEqualTo(OK);
assertMessageValidity("04:34:04:0C:16:0F:08:37:00:02:EA:60:03:34").isEqualTo(OK);
assertMessageValidity("0F:33:0C:08:10:1E:04:30:08:00:13:AD:06")
.isEqualTo(ERROR_DESTINATION);
assertMessageValidity("F0:34:04:0C:16:0F:08:37:00:02:EA:60:03").isEqualTo(ERROR_SOURCE);
assertMessageValidity("04:33:0C:08:10:1E:04:30:08:13:AD:06")
.isEqualTo(ERROR_PARAMETER_SHORT);
// Out of range Day of Month
assertMessageValidity("04:34:20:0C:16:0F:08:37:00:02:EA:60:03").isEqualTo(ERROR_PARAMETER);
// Out of range Month of Year
assertMessageValidity("04:33:0C:00:10:1E:04:30:08:00:13:AD:06").isEqualTo(ERROR_PARAMETER);
// Out of range Start Time - Hour
assertMessageValidity("04:34:04:0C:18:0F:08:37:00:02:EA:60:03").isEqualTo(ERROR_PARAMETER);
// Out of range Start Time - Minute
assertMessageValidity("04:33:0C:08:10:50:04:30:08:00:13:AD:06").isEqualTo(ERROR_PARAMETER);
// Out of range Duration - Duration Hours
assertMessageValidity("04:34:04:0C:16:0F:64:37:00:02:EA:60:03").isEqualTo(ERROR_PARAMETER);
// Out of range Duration - Minute
assertMessageValidity("04:33:0C:08:10:1E:04:64:08:00:13:AD:06").isEqualTo(ERROR_PARAMETER);
// Invalid Recording Sequence
assertMessageValidity("04:34:04:0C:16:0F:08:37:88:02:EA:60:03").isEqualTo(ERROR_PARAMETER);
// Invalid Recording Sequence
assertMessageValidity("04:33:0C:08:10:1E:04:30:A2:00:13:AD:06").isEqualTo(ERROR_PARAMETER);
// Out of range Analogue Broadcast Type
assertMessageValidity("04:34:04:0C:16:0F:08:37:00:03:EA:60:03").isEqualTo(ERROR_PARAMETER);
// Out of range Analogue Frequency
assertMessageValidity("04:33:0C:08:10:1E:04:30:08:00:FF:FF:06").isEqualTo(ERROR_PARAMETER);
// Out of range Broadcast System
assertMessageValidity("04:34:04:0C:16:0F:08:37:00:02:EA:60:20").isEqualTo(ERROR_PARAMETER);
}
private IntegerSubject assertMessageValidity(String message) {
return assertThat(mHdmiCecMessageValidator.isValid(buildMessage(message)));
}