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

Commit bdf27fbf authored by Jinsuk Kim's avatar Jinsuk Kim
Browse files

CEC: add getDeviceList()

Returns the list of all the connected CEC device information. This is
different from getInputDevices() which returns devices of source type only.

For this, turned the local device address list to unmodifiable so that it can
be used by any threads.

Now respects the device type info passed through <Report Physical Address>
rather than always defaulting to the one from HdmiUtil.getTypeFromAddress().
This ensures future compatibility when a device of reserved logical address
comes with a specific type.

Bug: 18046603
Change-Id: I5f7d5e31706efba1ad5dcf4bcfd4ffc918d1d940
parent 512c2330
Loading
Loading
Loading
Loading
+18 −0
Original line number Original line Diff line number Diff line
@@ -22,6 +22,9 @@ import android.hardware.hdmi.HdmiTimerRecordSources.TimerRecordSource;
import android.os.RemoteException;
import android.os.RemoteException;
import android.util.Log;
import android.util.Log;


import java.util.Collections;
import java.util.List;

import libcore.util.EmptyArray;
import libcore.util.EmptyArray;


/**
/**
@@ -149,6 +152,21 @@ public final class HdmiTvClient extends HdmiClient {
        };
        };
    }
    }


    /**
     * Returns all the CEC devices connected to TV.
     *
     * @return list of {@link HdmiDeviceInfo} for connected CEC devices.
     *         Empty list is returned if there is none.
     */
    public List<HdmiDeviceInfo> getDeviceList() {
        try {
            return mService.getDeviceList();
        } catch (RemoteException e) {
            Log.e("TAG", "Failed to call getDeviceList():", e);
            return Collections.<HdmiDeviceInfo>emptyList();
        }
    }

    /**
    /**
     * Set system audio volume
     * Set system audio volume
     *
     *
+1 −0
Original line number Original line Diff line number Diff line
@@ -59,6 +59,7 @@ interface IHdmiControlService {
    void setSystemAudioMute(boolean mute);
    void setSystemAudioMute(boolean mute);
    void setInputChangeListener(IHdmiInputChangeListener listener);
    void setInputChangeListener(IHdmiInputChangeListener listener);
    List<HdmiDeviceInfo> getInputDevices();
    List<HdmiDeviceInfo> getInputDevices();
    List<HdmiDeviceInfo> getDeviceList();
    void sendVendorCommand(int deviceType, int targetAddress, in byte[] params,
    void sendVendorCommand(int deviceType, int targetAddress, in byte[] params,
            boolean hasVendorId);
            boolean hasVendorId);
    void addVendorCommandListener(IHdmiVendorCommandListener listener, int deviceType);
    void addVendorCommandListener(IHdmiVendorCommandListener listener, int deviceType);
+3 −2
Original line number Original line Diff line number Diff line
@@ -57,8 +57,9 @@ final class ActiveSourceHandler {
     * Handles the incoming active source command.
     * Handles the incoming active source command.
     *
     *
     * @param newActive new active source information
     * @param newActive new active source information
     * @param deviceType device type of the new active source
     */
     */
    void process(ActiveSource newActive) {
    void process(ActiveSource newActive, int deviceType) {
        // Seq #17
        // Seq #17
        HdmiCecLocalDeviceTv tv = mSource;
        HdmiCecLocalDeviceTv tv = mSource;
        ActiveSource activeSource = tv.getActiveSource();
        ActiveSource activeSource = tv.getActiveSource();
@@ -68,7 +69,7 @@ final class ActiveSourceHandler {
        }
        }
        HdmiDeviceInfo device = mService.getDeviceInfo(newActive.logicalAddress);
        HdmiDeviceInfo device = mService.getDeviceInfo(newActive.logicalAddress);
        if (device == null) {
        if (device == null) {
            tv.startNewDeviceAction(newActive);
            tv.startNewDeviceAction(newActive, deviceType);
        }
        }


        if (!tv.isProhibitMode()) {
        if (!tv.isProhibitMode()) {
+33 −13
Original line number Original line Diff line number Diff line
@@ -110,6 +110,9 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
    // If true, TV wakes itself up when receiving <Text/Image View On>.
    // If true, TV wakes itself up when receiving <Text/Image View On>.
    private boolean mAutoWakeup;
    private boolean mAutoWakeup;


    // List of the logical address of local CEC devices. Unmodifiable, thread-safe.
    private List<Integer> mLocalDeviceAddresses;

    private final HdmiCecStandbyModeHandler mStandbyHandler;
    private final HdmiCecStandbyModeHandler mStandbyHandler;


    // If true, do not do routing control/send active source for internal source.
    // If true, do not do routing control/send active source for internal source.
@@ -141,10 +144,22 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        mSkipRoutingControl = (reason == HdmiControlService.INITIATED_BY_WAKE_UP_MESSAGE);
        mSkipRoutingControl = (reason == HdmiControlService.INITIATED_BY_WAKE_UP_MESSAGE);
        launchRoutingControl(reason != HdmiControlService.INITIATED_BY_ENABLE_CEC &&
        launchRoutingControl(reason != HdmiControlService.INITIATED_BY_ENABLE_CEC &&
                reason != HdmiControlService.INITIATED_BY_BOOT_UP);
                reason != HdmiControlService.INITIATED_BY_BOOT_UP);
        mLocalDeviceAddresses = initLocalDeviceAddresses();
        launchDeviceDiscovery();
        launchDeviceDiscovery();
        startQueuedActions();
        startQueuedActions();
    }
    }



    @ServiceThreadOnly
    private List<Integer> initLocalDeviceAddresses() {
        assertRunOnServiceThread();
        List<Integer> addresses = new ArrayList<>();
        for (HdmiCecLocalDevice device : mService.getAllLocalDevices()) {
            addresses.add(device.getDeviceInfo().getLogicalAddress());
        }
        return Collections.unmodifiableList(addresses);
    }

    @Override
    @Override
    @ServiceThreadOnly
    @ServiceThreadOnly
    protected int getPreferredAddress() {
    protected int getPreferredAddress() {
@@ -390,11 +405,12 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        assertRunOnServiceThread();
        assertRunOnServiceThread();
        int logicalAddress = message.getSource();
        int logicalAddress = message.getSource();
        int physicalAddress = HdmiUtils.twoBytesToInt(message.getParams());
        int physicalAddress = HdmiUtils.twoBytesToInt(message.getParams());
        if (getCecDeviceInfo(logicalAddress) == null) {
        HdmiDeviceInfo info = getCecDeviceInfo(logicalAddress);
        if (info == null) {
            handleNewDeviceAtTheTailOfActivePath(physicalAddress);
            handleNewDeviceAtTheTailOfActivePath(physicalAddress);
        } else {
        } else {
            ActiveSource activeSource = ActiveSource.of(logicalAddress, physicalAddress);
            ActiveSource activeSource = ActiveSource.of(logicalAddress, physicalAddress);
            ActiveSourceHandler.create(this, null).process(activeSource);
            ActiveSourceHandler.create(this, null).process(activeSource, info.getDeviceType());
        }
        }
        return true;
        return true;
    }
    }
@@ -484,7 +500,7 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        if (!isInDeviceList(address, path)) {
        if (!isInDeviceList(address, path)) {
            handleNewDeviceAtTheTailOfActivePath(path);
            handleNewDeviceAtTheTailOfActivePath(path);
        }
        }
        startNewDeviceAction(ActiveSource.of(address, path));
        startNewDeviceAction(ActiveSource.of(address, path), type);
        return true;
        return true;
    }
    }


@@ -520,7 +536,7 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        return false;
        return false;
    }
    }


    void startNewDeviceAction(ActiveSource activeSource) {
    void startNewDeviceAction(ActiveSource activeSource, int deviceType) {
        for (NewDeviceAction action : getActions(NewDeviceAction.class)) {
        for (NewDeviceAction action : getActions(NewDeviceAction.class)) {
            // If there is new device action which has the same logical address and path
            // If there is new device action which has the same logical address and path
            // ignore new request.
            // ignore new request.
@@ -536,7 +552,7 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        }
        }


        addAndStartAction(new NewDeviceAction(this, activeSource.logicalAddress,
        addAndStartAction(new NewDeviceAction(this, activeSource.logicalAddress,
                activeSource.physicalAddress));
                activeSource.physicalAddress, deviceType));
    }
    }


    private void handleNewDeviceAtTheTailOfActivePath(int path) {
    private void handleNewDeviceAtTheTailOfActivePath(int path) {
@@ -1195,15 +1211,8 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        }
        }
    }
    }


    @ServiceThreadOnly
    private boolean isLocalDeviceAddress(int address) {
    private boolean isLocalDeviceAddress(int address) {
        assertRunOnServiceThread();
        return mLocalDeviceAddresses.contains(address);
        for (HdmiCecLocalDevice device : mService.getAllLocalDevices()) {
            if (device.isAddressOf(address)) {
                return true;
            }
        }
        return false;
    }
    }


    @ServiceThreadOnly
    @ServiceThreadOnly
@@ -1253,6 +1262,17 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        }
        }
    }
    }


    List<HdmiDeviceInfo> getSafeCecDevicesLocked() {
        ArrayList<HdmiDeviceInfo> infoList = new ArrayList<>();
        for (HdmiDeviceInfo info : mSafeAllDeviceInfos) {
            if (isLocalDeviceAddress(info.getLogicalAddress())) {
                continue;
            }
            infoList.add(info);
        }
        return infoList;
    }

    /**
    /**
     * Called when a device is newly added or a new device is detected or
     * Called when a device is newly added or a new device is detected or
     * existing device is updated.
     * existing device is updated.
+13 −0
Original line number Original line Diff line number Diff line
@@ -1232,6 +1232,19 @@ public final class HdmiControlService extends SystemService {
            }
            }
        }
        }


        // Returns all the CEC devices on the bus including system audio, switch,
        // even those of reserved type.
        @Override
        public List<HdmiDeviceInfo> getDeviceList() {
            enforceAccessPermission();
            HdmiCecLocalDeviceTv tv = tv();
            synchronized (mLock) {
                return (tv == null)
                        ? Collections.<HdmiDeviceInfo>emptyList()
                        : tv.getSafeCecDevicesLocked();
            }
        }

        @Override
        @Override
        public void setSystemAudioVolume(final int oldIndex, final int newIndex,
        public void setSystemAudioVolume(final int oldIndex, final int newIndex,
                final int maxIndex) {
                final int maxIndex) {
Loading