From f7633f065d5b9ecac4bd2a02477443bb21bd92a5 Mon Sep 17 00:00:00 2001 From: Shraddha Basantwani Date: Tue, 13 Oct 2020 14:15:24 +0530 Subject: [PATCH] CEC : Add validity check methods for some common operands Add validity checks for Day of Month, Month of Year, Hour, Minute, Duration Hours and Recording sequence. Test: make Bug: 170811408 Change-Id: I99c727e8063883e7f6b007d9dc69d91ab05d875d --- .../server/hdmi/HdmiCecMessageValidator.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/services/core/java/com/android/server/hdmi/HdmiCecMessageValidator.java b/services/core/java/com/android/server/hdmi/HdmiCecMessageValidator.java index 7d766285bdfab..e65614307368b 100644 --- a/services/core/java/com/android/server/hdmi/HdmiCecMessageValidator.java +++ b/services/core/java/com/android/server/hdmi/HdmiCecMessageValidator.java @@ -343,6 +343,78 @@ public class HdmiCecMessageValidator { return true; } + /** + * Check if the given value is a valid day of month. A valid value is one which falls within the + * range description defined in CEC 1.4 Specification : Operand Descriptions (Section 17) + * + * @param value day of month + * @return true if the day of month is valid + */ + private boolean isValidDayOfMonth(int value) { + return isWithinRange(value, 1, 31); + } + + /** + * Check if the given value is a valid month of year. A valid value is one which falls within + * the range description defined in CEC 1.4 Specification : Operand Descriptions (Section 17) + * + * @param value month of year + * @return true if the month of year is valid + */ + private boolean isValidMonthOfYear(int value) { + return isWithinRange(value, 1, 12); + } + + /** + * Check if the given value is a valid hour. A valid value is one which falls within the range + * description defined in CEC 1.4 Specification : Operand Descriptions (Section 17) + * + * @param value hour + * @return true if the hour is valid + */ + private boolean isValidHour(int value) { + return isWithinRange(value, 0, 23); + } + + /** + * Check if the given value is a valid minute. A valid value is one which falls within the range + * description defined in CEC 1.4 Specification : Operand Descriptions (Section 17) + * + * @param value minute + * @return true if the minute is valid + */ + private boolean isValidMinute(int value) { + return isWithinRange(value, 0, 59); + } + + /** + * Check if the given value is a valid duration hours. A valid value is one which falls within + * the range description defined in CEC 1.4 Specification : Operand Descriptions (Section 17) + * + * @param value duration hours + * @return true if the duration hours is valid + */ + private boolean isValidDurationHours(int value) { + return isWithinRange(value, 0, 99); + } + + /** + * Check if the given value is a valid recording sequence. A valid value is adheres to range + * description defined in CEC 1.4 Specification : Operand Descriptions (Section 17) + * + * @param value recording sequence + * @return true if the given recording sequence is valid + */ + private boolean isValidRecordingSequence(int value) { + value = value & 0xFF; + // Validate bit 7 is set to zero + if ((value & 0x80) != 0x00) { + return false; + } + // Validate than not more than one bit is set + return (Integer.bitCount(value) <= 1); + } + private class PhysicalAddressValidator implements ParameterValidator { @Override public int isValid(byte[] params) {