diff options
6 files changed, 50 insertions, 21 deletions
diff --git a/core/java/android/hardware/hdmi/HdmiCecMessage.java b/core/java/android/hardware/hdmi/HdmiCecMessage.java index ddaf870..a8aa376 100644 --- a/core/java/android/hardware/hdmi/HdmiCecMessage.java +++ b/core/java/android/hardware/hdmi/HdmiCecMessage.java @@ -123,6 +123,7 @@ public final class HdmiCecMessage implements Parcelable { * @param p HdmiCecMessage object to read the Rating from * @return a new HdmiCecMessage created from the data in the parcel */ + @Override public HdmiCecMessage createFromParcel(Parcel p) { int source = p.readInt(); int destination = p.readInt(); @@ -131,6 +132,7 @@ public final class HdmiCecMessage implements Parcelable { p.readByteArray(params); return new HdmiCecMessage(source, destination, opcode, params); } + @Override public HdmiCecMessage[] newArray(int size) { return new HdmiCecMessage[size]; } @@ -139,11 +141,40 @@ public final class HdmiCecMessage implements Parcelable { @Override public String toString() { StringBuffer s = new StringBuffer(); - s.append(String.format("src: %d dst: %d op: %2X params: ", mSource, mDestination, mOpcode)); - for (byte data : mParams) { - s.append(String.format("%02X ", data)); + s.append(String.format("<%s> src: %d, dst: %d", + opcodeToString(mOpcode), mSource, mDestination)); + if (mParams.length > 0) { + s.append(", params:"); + for (byte data : mParams) { + s.append(String.format(" %02X", data)); + } } return s.toString(); } + + private static String opcodeToString(int opcode) { + switch (opcode) { + case HdmiCec.MESSAGE_FEATURE_ABORT: + return "Feature Abort"; + case HdmiCec.MESSAGE_CEC_VERSION: + return "CEC Version"; + case HdmiCec.MESSAGE_REQUEST_ARC_INITIATION: + return "Request ARC Initiation"; + case HdmiCec.MESSAGE_REQUEST_ARC_TERMINATION: + return "Request ARC Termination"; + case HdmiCec.MESSAGE_REPORT_ARC_INITIATED: + return "Report ARC Initiated"; + case HdmiCec.MESSAGE_REPORT_ARC_TERMINATED: + return "Report ARC Terminated"; + case HdmiCec.MESSAGE_TEXT_VIEW_ON: + return "Text View On"; + case HdmiCec.MESSAGE_ACTIVE_SOURCE: + return "Active Source"; + case HdmiCec.MESSAGE_GIVE_DEVICE_POWER_STATUS: + return "Give Device Power Status"; + default: + return String.format("Opcode: %02X", opcode); + } + } } diff --git a/services/core/java/com/android/server/hdmi/HdmiCecController.java b/services/core/java/com/android/server/hdmi/HdmiCecController.java index 23044dd..7cad906 100644 --- a/services/core/java/com/android/server/hdmi/HdmiCecController.java +++ b/services/core/java/com/android/server/hdmi/HdmiCecController.java @@ -20,6 +20,7 @@ import android.hardware.hdmi.HdmiCec; import android.hardware.hdmi.HdmiCecDeviceInfo; import android.hardware.hdmi.HdmiCecMessage; import android.os.Handler; +import android.util.Slog; import android.util.SparseArray; import libcore.util.EmptyArray; @@ -54,9 +55,6 @@ final class HdmiCecController { private static final int NUM_LOGICAL_ADDRESS = 16; - // TODO: define other constants for errors. - private static final int ERROR_SUCCESS = 0; - // Handler instance to process synchronous I/O (mainly send) message. private Handler mIoHandler; @@ -195,7 +193,7 @@ final class HdmiCecController { // it as logical address of the device. int error = nativeSendCecCommand(mNativePtr, curAddress, curAddress, EMPTY_BODY); - if (error != ERROR_SUCCESS) { + if (error != HdmiControlService.SEND_RESULT_SUCCESS) { logicalAddress = curAddress; break; } @@ -394,6 +392,9 @@ final class HdmiCecController { byte[] body = buildBody(cecMessage.getOpcode(), cecMessage.getParams()); final int error = nativeSendCecCommand(mNativePtr, cecMessage.getSource(), cecMessage.getDestination(), body); + if (error != HdmiControlService.SEND_RESULT_SUCCESS) { + Slog.w(TAG, "Failed to send " + cecMessage); + } if (callback != null) { runOnServiceThread(new Runnable() { @Override diff --git a/services/core/java/com/android/server/hdmi/HdmiControlService.java b/services/core/java/com/android/server/hdmi/HdmiControlService.java index d7a2c1c..2cd3eab 100644 --- a/services/core/java/com/android/server/hdmi/HdmiControlService.java +++ b/services/core/java/com/android/server/hdmi/HdmiControlService.java @@ -49,6 +49,10 @@ public final class HdmiControlService extends SystemService { // TODO: Rename the permission to HDMI_CONTROL. private static final String PERMISSION = "android.permission.HDMI_CEC"; + static final int SEND_RESULT_SUCCESS = 0; + static final int SEND_RESULT_NAK = -1; + static final int SEND_RESULT_FAILURE = -2; + /** * Interface to report send result. */ @@ -56,10 +60,11 @@ public final class HdmiControlService extends SystemService { /** * Called when {@link HdmiControlService#sendCecCommand} is completed. * - * @param error result of send request. 0 if succeed. Otherwise it will be - * negative value + * @param error result of send request. + * @see {@link #SEND_RESULT_SUCCESS} + * @see {@link #SEND_RESULT_NAK} + * @see {@link #SEND_RESULT_FAILURE} */ - // TODO: define error code as constants and update javadoc. void onSendCompleted(int error); } diff --git a/services/core/java/com/android/server/hdmi/RequestArcInitiationAction.java b/services/core/java/com/android/server/hdmi/RequestArcInitiationAction.java index db9d28d..343aff7 100644 --- a/services/core/java/com/android/server/hdmi/RequestArcInitiationAction.java +++ b/services/core/java/com/android/server/hdmi/RequestArcInitiationAction.java @@ -17,7 +17,6 @@ package com.android.server.hdmi; import android.hardware.hdmi.HdmiCecMessage; -import android.util.Slog; /** * Feature action that handles ARC action initiated by TV devices. @@ -43,12 +42,10 @@ final class RequestArcInitiationAction extends RequestArcAction { sendCommand(command, new HdmiControlService.SendMessageCallback() { @Override public void onSendCompleted(int error) { - // success. - if (error == 0) { + if (error == HdmiControlService.SEND_RESULT_SUCCESS) { mState = STATE_WATING_FOR_REQUEST_ARC_REQUEST_RESPONSE; addTimer(mState, TIMEOUT_MS); } else { - Slog.w(TAG, "Failed to send <Request ARC Initiation>"); // If failed to send <Request ARC Initiation>, start "Disabled" // ARC transmission action. disableArcTransmission(); diff --git a/services/core/java/com/android/server/hdmi/RequestArcTerminationAction.java b/services/core/java/com/android/server/hdmi/RequestArcTerminationAction.java index 7669f87..d4a35f8 100644 --- a/services/core/java/com/android/server/hdmi/RequestArcTerminationAction.java +++ b/services/core/java/com/android/server/hdmi/RequestArcTerminationAction.java @@ -17,7 +17,6 @@ package com.android.server.hdmi; import android.hardware.hdmi.HdmiCecMessage; -import android.util.Slog; /** * Feature action to handle <Request ARC Termination>. @@ -43,11 +42,10 @@ final class RequestArcTerminationAction extends RequestArcAction { sendCommand(command, new HdmiControlService.SendMessageCallback() { @Override public void onSendCompleted(int error) { - if (error == 0) { + if (error == HdmiControlService.SEND_RESULT_SUCCESS) { mState = STATE_WATING_FOR_REQUEST_ARC_REQUEST_RESPONSE; addTimer(mState, TIMEOUT_MS); } else { - Slog.w(TAG, "Failed to send <Request ARC Initiation>"); // If failed to send <Request ARC Termination>, start "Disabled" ARC // transmission action. disableArcTransmission(); diff --git a/services/core/java/com/android/server/hdmi/SetArcTransmissionStateAction.java b/services/core/java/com/android/server/hdmi/SetArcTransmissionStateAction.java index 94776a2..e3525d8 100644 --- a/services/core/java/com/android/server/hdmi/SetArcTransmissionStateAction.java +++ b/services/core/java/com/android/server/hdmi/SetArcTransmissionStateAction.java @@ -78,7 +78,7 @@ final class SetArcTransmissionStateAction extends FeatureAction { sendCommand(command, new HdmiControlService.SendMessageCallback() { @Override public void onSendCompleted(int error) { - if (error == 0) { + if (error == HdmiControlService.SEND_RESULT_SUCCESS) { // Enable ARC status immediately after sending <Report Arc Initiated>. // If AVR responds with <Feature Abort>, disable ARC status again. // This is different from spec that says that turns ARC status to @@ -94,9 +94,6 @@ final class SetArcTransmissionStateAction extends FeatureAction { } else { // If fails to send <Report ARC Initiated>, disable ARC and // send <Report ARC Terminated> directly. - Slog.w(TAG, "Failed to send <Report ARC Initiated>:[source:" - + mSourceAddress - + ", avr Address:" + mAvrAddress + "]"); setArcStatus(false); finish(); } |