Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 29b3e79d authored by Yuncheol Heo's avatar Yuncheol Heo Committed by Android (Google) Code Review
Browse files

Merge "Respond <Feature Abort: Invaild operand> for the invaild messages." into lmp-dev

parents 094d24c9 4c212897
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
@@ -25,6 +25,11 @@ import android.util.SparseArray;
public final class HdmiCecMessageValidator {
    private static final String TAG = "HdmiCecMessageValidator";

    static final int OK = 0;
    static final int ERROR_SOURCE = 1;
    static final int ERROR_DESTINATION = 2;
    static final int ERROR_PARAMETER = 3;

    private final HdmiControlService mService;

    interface ParameterValidator {
@@ -178,39 +183,39 @@ public final class HdmiCecMessageValidator {
        mValidationInfo.append(opcode, new ValidationInfo(validator, addrType));
    }

    boolean isValid(HdmiCecMessage message) {
    int isValid(HdmiCecMessage message) {
        int opcode = message.getOpcode();
        ValidationInfo info = mValidationInfo.get(opcode);
        if (info == null) {
            HdmiLogger.warning("No validation information for the message: " + message);
            return true;
            return OK;
        }

        // Check the source field.
        if (message.getSource() == Constants.ADDR_UNREGISTERED &&
                (info.addressType & SRC_UNREGISTERED) == 0) {
            HdmiLogger.warning("Unexpected source: " + message);
            return false;
            return ERROR_SOURCE;
        }
        // Check the destination field.
        if (message.getDestination() == Constants.ADDR_BROADCAST) {
            if ((info.addressType & DEST_BROADCAST) == 0) {
                HdmiLogger.warning("Unexpected broadcast message: " + message);
                return false;
                return ERROR_DESTINATION;
            }
        } else {  // Direct addressing.
            if ((info.addressType & DEST_DIRECT) == 0) {
                HdmiLogger.warning("Unexpected direct message: " + message);
                return false;
                return ERROR_DESTINATION;
            }
        }

        // Check the parameter type.
        if (!info.parameterValidator.isValid(message.getParams())) {
            HdmiLogger.warning("Unexpected parameters: " + message);
            return false;
            return ERROR_PARAMETER;
        }
        return true;
        return OK;
    }

    private static class FixedLengthValidator implements ParameterValidator {
+8 −3
Original line number Diff line number Diff line
@@ -651,7 +651,7 @@ public final class HdmiControlService extends SystemService {
    @ServiceThreadOnly
    void sendCecCommand(HdmiCecMessage command, @Nullable SendMessageCallback callback) {
        assertRunOnServiceThread();
        if (mMessageValidator.isValid(command)) {
        if (mMessageValidator.isValid(command) == HdmiCecMessageValidator.OK) {
            mCecController.sendCommand(command, callback);
        } else {
            HdmiLogger.error("Invalid message type:" + command);
@@ -682,8 +682,13 @@ public final class HdmiControlService extends SystemService {
    @ServiceThreadOnly
    boolean handleCecCommand(HdmiCecMessage message) {
        assertRunOnServiceThread();
        if (!mMessageValidator.isValid(message)) {
            return false;
        int errorCode = mMessageValidator.isValid(message);
        if (errorCode != HdmiCecMessageValidator.OK) {
            // We'll not response on the messages with the invalid source or destination.
            if (errorCode == HdmiCecMessageValidator.ERROR_PARAMETER) {
                maySendFeatureAbortCommand(message, Constants.ABORT_INVALID_OPERAND);
            }
            return true;
        }
        return dispatchMessageToLocalDevice(message);
    }