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

Commit 2e8f1b63 authored by Jungshik Jang's avatar Jungshik Jang
Browse files

CEC: Revamp volume control action.

Here is a list of changes
1. Change volume control into event base not level base
2. Hide volume ui if volume change is triggered by CEC
3. Report volume change triggered by CEC in OSD message
4. Revamp HdmiLogger so that normal class uses static method only.
5. Apply format message to HdmiLogger's helper methods.

Bug: 17367215

Change-Id: I9f3cd41f7c66f76919059b463df956ed5176b054
parent 649db7f0
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -54,11 +54,30 @@ public final class HdmiControlManager {
     */
    public static final int OSD_MESSAGE_ARC_CONNECTED_INVALID_PORT = 1;

    /**
     * Message used by TV to receive volume status from Audio Receiver. It should check volume value
     * that is retrieved from extra value with the key {@link #EXTRA_MESSAGE_EXTRAM_PARAM1}. If the
     * value is in range of [0,100], it is current volume of Audio Receiver. And there is another
     * value, {@link #AVR_VOLUME_MUTED}, which is used to inform volume mute.
     */
    public static final int OSD_MESSAGE_AVR_VOLUME_CHANGED = 2;

    /**
     * Used as an extra field in the intent {@link #ACTION_OSD_MESSAGE}. Contains the ID of
     * the message to display on screen.
     */
    public static final String EXTRA_MESSAGE_ID = "android.hardware.hdmi.extra.MESSAGE_ID";
    /**
     * Used as an extra field in the intent {@link #ACTION_OSD_MESSAGE}. Contains the extra value
     * of the message.
     */
    public static final String EXTRA_MESSAGE_EXTRAM_PARAM1 =
            "android.hardware.hdmi.extra.MESSAGE_EXTRA_PARAM1";

    /**
     * Volume value for mute state.
     */
    public static final int AVR_VOLUME_MUTED = 101;

    public static final int POWER_STATUS_UNKNOWN = -1;
    public static final int POWER_STATUS_ON = 0;
+6 −15
Original line number Diff line number Diff line
@@ -31,8 +31,6 @@ import com.android.server.hdmi.HdmiControlService.DevicePollingCallback;

import libcore.util.EmptyArray;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

@@ -102,11 +100,6 @@ final class HdmiCecController {
    // Stores the local CEC devices in the system. Device type is used for key.
    private final SparseArray<HdmiCecLocalDevice> mLocalDevices = new SparseArray<>();

    @IoThreadOnly
    private final HdmiLogger mIoThreadLogger = new HdmiLogger(TAG);
    @ServiceThreadOnly
    private final HdmiLogger mServiceThreadLogger = new HdmiLogger(TAG);

    // Private constructor.  Use HdmiCecController.create().
    private HdmiCecController(HdmiControlService service) {
        mService = service;
@@ -210,9 +203,8 @@ final class HdmiCecController {
        }

        final int assignedAddress = logicalAddress;
        mIoThreadLogger.debug(
                String.format("New logical address for device [%d]: [preferred:%d, assigned:%d]",
                        deviceType, preferredAddress, assignedAddress));
        HdmiLogger.debug("New logical address for device [%d]: [preferred:%d, assigned:%d]",
                        deviceType, preferredAddress, assignedAddress);
        if (callback != null) {
            runOnServiceThread(new Runnable() {
                @Override
@@ -449,7 +441,7 @@ final class HdmiCecController {
                        allocated.add(address);
                    }
                }
                mIoThreadLogger.debug("[P]:Allocated Address=" + allocated);
                HdmiLogger.debug("[P]:Allocated Address=" + allocated);
                if (callback != null) {
                    runOnServiceThread(new Runnable() {
                        @Override
@@ -551,7 +543,7 @@ final class HdmiCecController {
        runOnIoThread(new Runnable() {
            @Override
            public void run() {
                mIoThreadLogger.debug("[S]:" + cecMessage);
                HdmiLogger.debug("[S]:" + cecMessage);
                byte[] body = buildBody(cecMessage.getOpcode(), cecMessage.getParams());
                int i = 0;
                int errorCode = Constants.SEND_RESULT_SUCCESS;
@@ -586,7 +578,7 @@ final class HdmiCecController {
    private void handleIncomingCecCommand(int srcAddress, int dstAddress, byte[] body) {
        assertRunOnServiceThread();
        HdmiCecMessage command = HdmiCecMessageBuilder.of(srcAddress, dstAddress, body);
        mServiceThreadLogger.debug("[R]:" + command);
        HdmiLogger.debug("[R]:" + command);
        onReceiveCommand(command);
    }

@@ -596,8 +588,7 @@ final class HdmiCecController {
    @ServiceThreadOnly
    private void handleHotplug(int port, boolean connected) {
        assertRunOnServiceThread();
        mServiceThreadLogger.debug(
                "Hotplug event:[port:" + port + " , connected:" + connected + "]");
        HdmiLogger.debug("Hotplug event:[port:%d, connected:%b]", port, connected);
        mService.onHotplug(port, connected);
    }

+1 −7
Original line number Diff line number Diff line
@@ -43,9 +43,6 @@ import java.util.List;
 */
abstract class HdmiCecFeatureAction {
    private static final String TAG = "HdmiCecFeatureAction";
    // As all actions run in the same thread (service thread), it's fine to have single logger.
    // TODO: create global logger for each threads and use them.
    protected static final HdmiLogger DLOGGER = new HdmiLogger(TAG);

    // Timer handler message used for timeout event
    protected static final int MSG_TIMEOUT = 100;
@@ -264,10 +261,7 @@ abstract class HdmiCecFeatureAction {
    }

    protected final void sendUserControlPressedAndReleased(int targetAddress, int uiCommand) {
        sendCommand(HdmiCecMessageBuilder.buildUserControlPressed(
                getSourceAddress(), targetAddress, uiCommand));
        sendCommand(HdmiCecMessageBuilder.buildUserControlReleased(
                getSourceAddress(), targetAddress));
        mSource.sendUserControlPressedAndReleased(targetAddress, uiCommand);
    }

    protected final void addOnFinishedCallback(HdmiCecFeatureAction action, Runnable runnable) {
+7 −0
Original line number Diff line number Diff line
@@ -810,6 +810,13 @@ abstract class HdmiCecLocalDevice {
        Slog.w(TAG, "sendKeyEvent not implemented");
    }

    void sendUserControlPressedAndReleased(int targetAddress, int cecKeycode) {
        mService.sendCecCommand(HdmiCecMessageBuilder.buildUserControlPressed(
                mAddress, targetAddress, cecKeycode));
        mService.sendCecCommand(HdmiCecMessageBuilder.buildUserControlReleased(
                mAddress, targetAddress));
    }

    /**
     * Dump internal status of HdmiCecLocalDevice object.
     */
+21 −14
Original line number Diff line number Diff line
@@ -120,8 +120,6 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
    // other CEC devices since they might not have logical address.
    private final ArraySet<Integer> mCecSwitches = new ArraySet<Integer>();

    private final HdmiLogger mSafeLogger = new HdmiLogger(TAG);

    HdmiCecLocalDeviceTv(HdmiControlService service) {
        super(service, HdmiDeviceInfo.DEVICE_TV);
        mPrevPortId = Constants.INVALID_PORT_ID;
@@ -700,8 +698,7 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {

    // # Seq 25
    void setSystemAudioMode(boolean on, boolean updateSetting) {
        mSafeLogger.debug(String.format("System Audio Mode change[old:%b new:%b]",
                mSystemAudioActivated, on));
        HdmiLogger.debug("System Audio Mode change[old:%b new:%b]", mSystemAudioActivated, on);

        if (updateSetting) {
            mService.writeBooleanSetting(Global.HDMI_SYSTEM_AUDIO_ENABLED, on);
@@ -832,6 +829,8 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
                    AudioManager.STREAM_MUSIC);
            mService.setAudioStatus(mute,
                    VolumeControlAction.scaleToCustomVolume(volume, maxVolume));
            displayOsd(HdmiControlManager.OSD_MESSAGE_AVR_VOLUME_CHANGED,
                    mute ? HdmiControlManager.AVR_VOLUME_MUTED : volume);
        }
    }

@@ -855,12 +854,13 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
            }
        }

        // Remove existing volume action.
        removeAction(VolumeControlAction.class);

        HdmiDeviceInfo avr = getAvrDeviceInfo();
        addAndStartAction(VolumeControlAction.ofVolumeChange(this, avr.getLogicalAddress(),
                cecVolume, delta > 0));
        List<VolumeControlAction> actions = getActions(VolumeControlAction.class);
        if (actions.isEmpty()) {
            addAndStartAction(new VolumeControlAction(this,
                    getAvrDeviceInfo().getLogicalAddress(), delta > 0));
        } else {
            actions.get(0).handleVolumeChange(delta > 0);
        }
    }

    @ServiceThreadOnly
@@ -872,8 +872,9 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {

        // Remove existing volume action.
        removeAction(VolumeControlAction.class);
        HdmiDeviceInfo avr = getAvrDeviceInfo();
        addAndStartAction(VolumeControlAction.ofMute(this, avr.getLogicalAddress(), mute));
        sendUserControlPressedAndReleased(getAvrDeviceInfo().getLogicalAddress(),
                mute ? HdmiCecKeycode.CEC_KEYCODE_MUTE_FUNCTION :
                        HdmiCecKeycode.CEC_KEYCODE_RESTORE_VOLUME_FUNCTION);
    }

    @Override
@@ -935,7 +936,7 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
    protected boolean handleSetSystemAudioMode(HdmiCecMessage message) {
        assertRunOnServiceThread();
        if (!isMessageForSystemAudio(message)) {
            mSafeLogger.warning("Invalid <Set System Audio Mode> message:" + message);
            HdmiLogger.warning("Invalid <Set System Audio Mode> message:" + message);
            return false;
        }
        SystemAudioActionFromAvr action = new SystemAudioActionFromAvr(this,
@@ -949,7 +950,7 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
    protected boolean handleSystemAudioModeStatus(HdmiCecMessage message) {
        assertRunOnServiceThread();
        if (!isMessageForSystemAudio(message)) {
            mSafeLogger.warning("Invalid <System Audio Mode Status> message:" + message);
            HdmiLogger.warning("Invalid <System Audio Mode Status> message:" + message);
            return false;
        }
        setSystemAudioMode(HdmiUtils.parseCommandParamSystemAudioStatus(message), true);
@@ -1445,6 +1446,12 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        mService.displayOsd(messageId);
    }

    @ServiceThreadOnly
    void displayOsd(int messageId, int extra) {
        assertRunOnServiceThread();
        mService.displayOsd(messageId, extra);
    }

    // Seq #54 and #55
    @ServiceThreadOnly
    void startOneTouchRecord(int recorderAddress, byte[] recordSource) {
Loading