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

Commit aa6698b0 authored by Nathalie Le Clair's avatar Nathalie Le Clair Committed by Gerrit Code Review
Browse files

Merge changes I46fb8cfe,I4181b465,I99e1ca1d,I66b09693

* changes:
  Only invoke listener once physical address becomes known
  Don't remove devices on onHotplug()
  Assign local device portId 0
  Set device type on first message received
parents 3f0139b1 a598b936
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.hardware.hdmi.HdmiDeviceInfo;
 * Callback interface definition for HDMI client to get informed of
 * the CEC logical device status change event.
 *
 * Only to be used on TV panel and Audio System devices (b/226317598).
 *
 * @hide
 */
oneway interface IHdmiDeviceEventListener {
+1 −0
Original line number Diff line number Diff line
@@ -127,6 +127,7 @@ public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource {
        // We'll not invalidate the active source on the hotplug event to pass CETC 11.2.2-2 ~ 3.
        if (!connected) {
            getWakeLock().release();
            mService.getHdmiCecNetwork().removeDevicesConnectedToPort(portId);
        }
    }

+5 −0
Original line number Diff line number Diff line
@@ -1218,6 +1218,11 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
    @ServiceThreadOnly
    void onHotplug(int portId, boolean connected) {
        assertRunOnServiceThread();

        if (!connected) {
            mService.getHdmiCecNetwork().removeCecSwitches(portId);
        }

        // Turning System Audio Mode off when the AVR is unlugged or standby.
        // When the device is not unplugged but reawaken from standby, we check if the System
        // Audio Control Feature is enabled or not then decide if turning SAM on/off accordingly.
+59 −8
Original line number Diff line number Diff line
@@ -269,7 +269,10 @@ public class HdmiCecNetwork {
            // The addition of a local device should not notify listeners
            return;
        }
        if (old == null) {
        if (info.getPhysicalAddress() == HdmiDeviceInfo.PATH_INVALID) {
            // Don't notify listeners of devices that haven't reported their physical address yet
            return;
        } else if (old == null  || old.getPhysicalAddress() == HdmiDeviceInfo.PATH_INVALID) {
            invokeDeviceEventListener(info,
                    HdmiControlManager.DEVICE_EVENT_ADD_DEVICE);
        } else if (!old.equals(info)) {
@@ -296,7 +299,10 @@ public class HdmiCecNetwork {
        assertRunOnServiceThread();
        HdmiDeviceInfo old = addDeviceInfo(info);

        if (old == null) {
        if (info.getPhysicalAddress() == HdmiDeviceInfo.PATH_INVALID) {
            // Don't notify listeners of devices that haven't reported their physical address yet
            return;
        } else if (old == null  || old.getPhysicalAddress() == HdmiDeviceInfo.PATH_INVALID) {
            invokeDeviceEventListener(info,
                    HdmiControlManager.DEVICE_EVENT_ADD_DEVICE);
        } else if (!old.equals(info)) {
@@ -370,10 +376,12 @@ public class HdmiCecNetwork {
    // This only applies to TV devices.
    // Returns true if the policy is set to true, and the device to check does not have
    // a parent CEC device (which should be the CEC-enabled switch) in the list.
    // Devices with an invalid physical address are assumed to NOT be connected to a legacy switch.
    private boolean hideDevicesBehindLegacySwitch(HdmiDeviceInfo info) {
        return isLocalDeviceAddress(Constants.ADDR_TV)
                && HdmiConfig.HIDE_DEVICES_BEHIND_LEGACY_SWITCH
                && !isConnectedToCecSwitch(info.getPhysicalAddress(), getCecSwitches());
                && !isConnectedToCecSwitch(info.getPhysicalAddress(), getCecSwitches())
                && info.getPhysicalAddress() != HdmiDeviceInfo.PATH_INVALID;
    }

    /**
@@ -387,6 +395,10 @@ public class HdmiCecNetwork {
        HdmiDeviceInfo info = removeDeviceInfo(HdmiDeviceInfo.idForCecDevice(address));

        localDevice.mCecMessageCache.flushMessagesFrom(address);
        if (info.getPhysicalAddress() == HdmiDeviceInfo.PATH_INVALID) {
            // Don't notify listeners of devices that haven't reported their physical address yet
            return;
        }
        invokeDeviceEventListener(info,
                HdmiControlManager.DEVICE_EVENT_REMOVE_DEVICE);
    }
@@ -497,6 +509,34 @@ public class HdmiCecNetwork {
        return device.getPhysicalAddress() == physicalAddress;
    }

    /**
     * Attempts to deduce the device type of a device given its logical address.
     * If multiple types are possible, returns {@link HdmiDeviceInfo#DEVICE_RESERVED}.
     */
    private static int logicalAddressToDeviceType(int logicalAddress) {
        switch (logicalAddress) {
            case Constants.ADDR_TV:
                return HdmiDeviceInfo.DEVICE_TV;
            case Constants.ADDR_RECORDER_1:
            case Constants.ADDR_RECORDER_2:
            case Constants.ADDR_RECORDER_3:
                return HdmiDeviceInfo.DEVICE_RECORDER;
            case Constants.ADDR_TUNER_1:
            case Constants.ADDR_TUNER_2:
            case Constants.ADDR_TUNER_3:
            case Constants.ADDR_TUNER_4:
                return HdmiDeviceInfo.DEVICE_TUNER;
            case Constants.ADDR_PLAYBACK_1:
            case Constants.ADDR_PLAYBACK_2:
            case Constants.ADDR_PLAYBACK_3:
                return HdmiDeviceInfo.DEVICE_PLAYBACK;
            case Constants.ADDR_AUDIO_SYSTEM:
                return HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM;
            default:
                return HdmiDeviceInfo.DEVICE_RESERVED;
        }
    }

    /**
     * Passively listen to incoming CEC messages.
     *
@@ -510,7 +550,7 @@ public class HdmiCecNetwork {
        if (getCecDeviceInfo(sourceAddress) == null) {
            HdmiDeviceInfo newDevice = new HdmiDeviceInfo(sourceAddress,
                    HdmiDeviceInfo.PATH_INVALID, HdmiDeviceInfo.PORT_INVALID,
                    HdmiDeviceInfo.DEVICE_RESERVED, Constants.UNKNOWN_VENDOR_ID,
                    logicalAddressToDeviceType(sourceAddress), Constants.UNKNOWN_VENDOR_ID,
                    HdmiUtils.getDefaultDeviceName(sourceAddress));
            addCecDevice(newDevice);
        }
@@ -668,7 +708,7 @@ public class HdmiCecNetwork {
        return mCecSwitches;
    }

    void removeDevicesConnectedToPort(int portId) {
    void removeCecSwitches(int portId) {
        Iterator<Integer> it = mCecSwitches.iterator();
        while (it.hasNext()) {
            int path = it.next();
@@ -677,6 +717,11 @@ public class HdmiCecNetwork {
                it.remove();
            }
        }
    }

    void removeDevicesConnectedToPort(int portId) {
        removeCecSwitches(portId);

        List<Integer> toRemove = new ArrayList<>();
        for (int i = 0; i < mDeviceInfos.size(); i++) {
            int key = mDeviceInfos.keyAt(i);
@@ -788,7 +833,10 @@ public class HdmiCecNetwork {
    public void clearDeviceList() {
        assertRunOnServiceThread();
        for (HdmiDeviceInfo info : HdmiUtils.sparseArrayToList(mDeviceInfos)) {
            if (info.getPhysicalAddress() == getPhysicalAddress()) {
            if (info.getPhysicalAddress() == getPhysicalAddress()
                    || info.getPhysicalAddress() == HdmiDeviceInfo.PATH_INVALID) {
                // Don't notify listeners of local devices or devices that haven't reported their
                // physical address yet
                continue;
            }
            invokeDeviceEventListener(info,
@@ -835,10 +883,13 @@ public class HdmiCecNetwork {
     * on the current device.
     */
    int physicalAddressToPortId(int path) {
        int physicalAddress = getPhysicalAddress();
        if (path == physicalAddress) {
            // The local device isn't connected to any port; assign portId 0
            return Constants.CEC_SWITCH_HOME;
        }
        int mask = 0xF000;
        int finalMask = 0xF000;
        int physicalAddress;
        physicalAddress = getPhysicalAddress();
        int maskedAddress = physicalAddress;

        while (maskedAddress != 0) {
+0 −4
Original line number Diff line number Diff line
@@ -1251,10 +1251,6 @@ public class HdmiControlService extends SystemService {
            device.onHotplug(portId, connected);
        }

        if (!connected) {
            mHdmiCecNetwork.removeDevicesConnectedToPort(portId);
        }

        announceHotplugEvent(portId, connected);
    }

Loading