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

Commit 61ced38d authored by Yuncheol Heo's avatar Yuncheol Heo Committed by Jungshik Jang
Browse files

DO NOT MERGE: Add the constants for the callback result of SendCecCommand().

- Move the send failure warning messages into HdmiCecController.sendCommand()
  from each Actions.
- Stringfy with more detail messages for some opcodes.

Change-Id: Ib7ce24dd2a1f290e6c3a0b26738772ef1d4a9630
parent 47927f75
Loading
Loading
Loading
Loading
+34 −3
Original line number Diff line number Diff line
@@ -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));
        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);
        }
    }
}
+5 −4
Original line number Diff line number Diff line
@@ -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
+8 −3
Original line number Diff line number Diff line
@@ -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);
    }

+1 −4
Original line number Diff line number Diff line
@@ -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();
+1 −3
Original line number Diff line number Diff line
@@ -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();
Loading