CEC: Add Digital Timer validator
Used to validate <Set Digital Timer> and <Clear Digital Timer> message parameters Test: atest HdmiCecMessageValidatorTest Bug: 170811408 Change-Id: I60d845acf7ae9d9f26b129bab49ed28450d39a00
This commit is contained in:
@@ -125,10 +125,14 @@ public class HdmiCecMessageValidator {
|
||||
// TODO: Handle messages for the Timer Programming.
|
||||
addValidationInfo(
|
||||
Constants.MESSAGE_CLEAR_ANALOG_TIMER, new AnalogueTimerValidator(), DEST_DIRECT);
|
||||
addValidationInfo(
|
||||
Constants.MESSAGE_CLEAR_DIGITAL_TIMER, new DigitalTimerValidator(), DEST_DIRECT);
|
||||
addValidationInfo(
|
||||
Constants.MESSAGE_CLEAR_EXTERNAL_TIMER, new ExternalTimerValidator(), DEST_DIRECT);
|
||||
addValidationInfo(
|
||||
Constants.MESSAGE_SET_ANALOG_TIMER, new AnalogueTimerValidator(), DEST_DIRECT);
|
||||
addValidationInfo(
|
||||
Constants.MESSAGE_SET_DIGITAL_TIMER, new DigitalTimerValidator(), DEST_DIRECT);
|
||||
addValidationInfo(
|
||||
Constants.MESSAGE_SET_EXTERNAL_TIMER, new ExternalTimerValidator(), DEST_DIRECT);
|
||||
addValidationInfo(
|
||||
@@ -461,6 +465,95 @@ public class HdmiCecMessageValidator {
|
||||
return isWithinRange(value, 0, 31);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given value is a ARIB type. A valid value is one which falls within the range
|
||||
* description defined in CEC 1.4 Specification : Operand Descriptions (Section 17)
|
||||
*
|
||||
* @param value Digital Broadcast System
|
||||
* @return true if the Digital Broadcast System is ARIB type
|
||||
*/
|
||||
private boolean isAribDbs(int value) {
|
||||
return (value == 0x00 || isWithinRange(value, 0x08, 0x0A));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given value is a ATSC type. A valid value is one which falls within the range
|
||||
* description defined in CEC 1.4 Specification : Operand Descriptions (Section 17)
|
||||
*
|
||||
* @param value Digital Broadcast System
|
||||
* @return true if the Digital Broadcast System is ATSC type
|
||||
*/
|
||||
private boolean isAtscDbs(int value) {
|
||||
return (value == 0x01 || isWithinRange(value, 0x10, 0x12));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given value is a DVB type. A valid value is one which falls within the range
|
||||
* description defined in CEC 1.4 Specification : Operand Descriptions (Section 17)
|
||||
*
|
||||
* @param value Digital Broadcast System
|
||||
* @return true if the Digital Broadcast System is DVB type
|
||||
*/
|
||||
private boolean isDvbDbs(int value) {
|
||||
return (value == 0x02 || isWithinRange(value, 0x18, 0x1B));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given value is a valid Digital 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 Digital Broadcast System
|
||||
* @return true if the Digital Broadcast System is valid
|
||||
*/
|
||||
private boolean isValidDigitalBroadcastSystem(int value) {
|
||||
return (isAribDbs(value) || isAtscDbs(value) || isDvbDbs(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given value is a valid Digital Service Identification. A valid value is one
|
||||
* which falls within the range description defined in CEC 1.4 Specification : Operand
|
||||
* Descriptions (Section 17)
|
||||
*
|
||||
* @param params Digital Timer Message parameters
|
||||
* @param offset start offset of Digital Service Identification
|
||||
* @return true if the Digital Service Identification is valid
|
||||
*/
|
||||
private boolean isValidDigitalServiceIdentification(byte[] params, int offset) {
|
||||
// MSB contains Service Identification Method
|
||||
int serviceIdentificationMethod = params[offset] & 0x80;
|
||||
// Last 7 bits contains Digital Broadcast System
|
||||
int digitalBroadcastSystem = params[offset] & 0x7F;
|
||||
offset = offset + 1;
|
||||
if (serviceIdentificationMethod == 0x00) {
|
||||
// Services identified by Digital IDs
|
||||
if (isAribDbs(digitalBroadcastSystem)) {
|
||||
// Validate ARIB type have 6 byte data
|
||||
return params.length - offset >= 6;
|
||||
} else if (isAtscDbs(digitalBroadcastSystem)) {
|
||||
// Validate ATSC type have 4 byte data
|
||||
return params.length - offset >= 4;
|
||||
} else if (isDvbDbs(digitalBroadcastSystem)) {
|
||||
// Validate DVB type have 6 byte data
|
||||
return params.length - offset >= 6;
|
||||
}
|
||||
} else if (serviceIdentificationMethod == 0x80) {
|
||||
// Services identified by Channel
|
||||
if (isValidDigitalBroadcastSystem(digitalBroadcastSystem)) {
|
||||
// First 6 bits contain Channel Number Format
|
||||
int channelNumberFormat = params[offset] & 0xFC;
|
||||
if (channelNumberFormat == 0x04) {
|
||||
// Validate it contains 1-part Channel Number data (16 bits)
|
||||
return params.length - offset >= 3;
|
||||
} else if (channelNumberFormat == 0x08) {
|
||||
// Validate it contains Major Channel Number and Minor Channel Number (26 bits)
|
||||
return params.length - offset >= 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given value is a valid External Plug. A valid value is one which falls within
|
||||
* the range description defined in CEC 1.4 Specification : Operand Descriptions (Section 17)
|
||||
@@ -651,6 +744,30 @@ public class HdmiCecMessageValidator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given Digital Timer message parameters are valid. Valid parameters should adhere
|
||||
* to message description of Digital Timer defined in CEC 1.4 Specification : Message
|
||||
* Descriptions for Timer Programming Feature (CEC Table 12)
|
||||
*/
|
||||
private class DigitalTimerValidator 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
|
||||
&& isValidDigitalServiceIdentification(
|
||||
params, 7)); // Digital Service Identification
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given External Timer message parameters are valid. Valid parameters should
|
||||
* adhere to message description of External Timer defined in CEC 1.4 Specification : Message
|
||||
|
||||
@@ -227,6 +227,67 @@ public class HdmiCecMessageValidatorTest {
|
||||
assertMessageValidity("04:34:04:0C:16:0F:08:37:00:02:EA:60:20").isEqualTo(ERROR_PARAMETER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isValid_setDigitalTimer_clearDigitalTimer() {
|
||||
// Services identified by Digital IDs - ARIB Broadcast System
|
||||
assertMessageValidity("04:99:0C:08:15:05:04:1E:00:00:C4:C2:11:D8:75:30").isEqualTo(OK);
|
||||
// Service identified by Digital IDs - ATSC Broadcast System
|
||||
assertMessageValidity("04:97:1E:07:12:20:50:28:01:01:8B:5E:39:5A").isEqualTo(OK);
|
||||
// Service identified by Digital IDs - DVB Broadcast System
|
||||
assertMessageValidity("04:99:05:0C:06:0A:19:3B:40:19:8B:44:03:11:04:FC").isEqualTo(OK);
|
||||
// Service identified by Channel - 1 part channel number
|
||||
assertMessageValidity("04:97:12:06:0C:2D:5A:19:08:91:04:00:B1").isEqualTo(OK);
|
||||
// Service identified by Channel - 2 part channel number
|
||||
assertMessageValidity("04:99:15:09:00:0F:00:2D:04:82:09:C8:72:C8").isEqualTo(OK);
|
||||
|
||||
assertMessageValidity("4F:97:0C:08:15:05:04:1E:00:00:C4:C2:11:D8:75:30")
|
||||
.isEqualTo(ERROR_DESTINATION);
|
||||
assertMessageValidity("F0:99:15:09:00:0F:00:2D:04:82:09:C8:72:C8").isEqualTo(ERROR_SOURCE);
|
||||
assertMessageValidity("04:97:1E:12:20:58:01:01:8B:5E:39:5A")
|
||||
.isEqualTo(ERROR_PARAMETER_SHORT);
|
||||
// Out of range Day of Month
|
||||
assertMessageValidity("04:99:24:0C:06:0A:19:3B:40:19:8B:44:03:11:04:FC")
|
||||
.isEqualTo(ERROR_PARAMETER);
|
||||
// Out of range Month of Year
|
||||
assertMessageValidity("04:97:12:10:0C:2D:5A:19:08:91:04:00:B1").isEqualTo(ERROR_PARAMETER);
|
||||
// Out of range Start Time - Hour
|
||||
assertMessageValidity("04:99:0C:08:20:05:04:1E:00:00:C4:C2:11:D8:75:30")
|
||||
.isEqualTo(ERROR_PARAMETER);
|
||||
// Out of range Start Time - Minute
|
||||
assertMessageValidity("04:97:15:09:00:4B:00:2D:04:82:09:C8:72:C8")
|
||||
.isEqualTo(ERROR_PARAMETER);
|
||||
// Out of range Duration - Duration Hours
|
||||
assertMessageValidity("04:99:1E:07:12:20:78:28:01:01:8B:5E:39:5A")
|
||||
.isEqualTo(ERROR_PARAMETER);
|
||||
// Out of range Duration - Minute
|
||||
assertMessageValidity("04:97:05:0C:06:0A:19:48:40:19:8B:44:03:11:04:FC")
|
||||
.isEqualTo(ERROR_PARAMETER);
|
||||
// Invalid Recording Sequence
|
||||
assertMessageValidity("04:99:12:06:0C:2D:5A:19:90:91:04:00:B1").isEqualTo(ERROR_PARAMETER);
|
||||
// Invalid Recording Sequence
|
||||
assertMessageValidity("04:97:0C:08:15:05:04:1E:21:00:C4:C2:11:D8:75:30")
|
||||
.isEqualTo(ERROR_PARAMETER);
|
||||
|
||||
// Invalid Digital Broadcast System
|
||||
assertMessageValidity("04:99:1E:07:12:20:50:28:01:04:8B:5E:39:5A")
|
||||
.isEqualTo(ERROR_PARAMETER);
|
||||
// Invalid Digital Broadcast System
|
||||
assertMessageValidity("04:97:05:0C:06:0A:19:3B:40:93:8B:44:03:11:04:FC")
|
||||
.isEqualTo(ERROR_PARAMETER);
|
||||
// Insufficient data for ARIB Broadcast system
|
||||
assertMessageValidity("04:99:0C:08:15:05:04:1E:00:00:C4:C2:11:D8:75")
|
||||
.isEqualTo(ERROR_PARAMETER);
|
||||
// Insufficient data for ATSC Broadcast system
|
||||
assertMessageValidity("04:97:1E:07:12:20:50:28:01:01:8B:5E:39").isEqualTo(ERROR_PARAMETER);
|
||||
// Insufficient data for DVB Broadcast system
|
||||
assertMessageValidity("04:99:05:0C:06:0A:19:3B:40:19:8B:44:03:11:04")
|
||||
.isEqualTo(ERROR_PARAMETER);
|
||||
// Insufficient data for 2 part channel number
|
||||
assertMessageValidity("04:97:15:09:00:0F:00:2D:04:82:09:C8:72").isEqualTo(ERROR_PARAMETER);
|
||||
// Invalid Channel Number format
|
||||
assertMessageValidity("04:99:12:06:0C:2D:5A:19:08:91:0D:00:B1").isEqualTo(ERROR_PARAMETER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isValid_setExternalTimer_clearExternalTimer() {
|
||||
assertMessageValidity("40:A1:0C:08:15:05:04:1E:02:04:20").isEqualTo(OK);
|
||||
|
||||
Reference in New Issue
Block a user