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

Commit 7fd409de authored by daren.liao's avatar daren.liao Committed by Winni Chang
Browse files

Change Update System Information behavior on receiving Report Physical Address

[Description]
For some devices that send <Report physical address> repeatly
They keep starting NewDeviceAction and re-add deviceInfo
- If the deivce is AMP, ARC will be re-connected
- if the device is playback device, HDMI source might be re-flash

We ignore re-add device, if the device info is same as old device

[Test Report]
Plug Xiaomi Box2, no flash screen, no OSD name change
Plug BD player between Port1 and Port2 10 times, behaves well

Bug: 183580473
Bug: 307811135
Change-Id: Iee84f13b1ec276fb3fd593bb9f42e8b0919a7760
parent c15578db
Loading
Loading
Loading
Loading
+55 −6
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ final class NewDeviceAction extends HdmiCecFeatureAction {
    private int mVendorId;
    private String mDisplayName;
    private int mTimeoutRetry;
    private HdmiDeviceInfo mOldDeviceInfo;

    /**
     * Constructor.
@@ -73,6 +74,38 @@ final class NewDeviceAction extends HdmiCecFeatureAction {

    @Override
    public boolean start() {
        mOldDeviceInfo =
            localDevice().mService.getHdmiCecNetwork().getCecDeviceInfo(mDeviceLogicalAddress);
        // If there's deviceInfo with same (logical address, physical address) set
        // Then addCecDevice should be delayed until system information process is finished
        if (mOldDeviceInfo != null
                && mOldDeviceInfo.getPhysicalAddress() == mDevicePhysicalAddress) {
            Slog.d(TAG, "Start NewDeviceAction with old deviceInfo:["
                    + mOldDeviceInfo.toString() + "]");
        } else {
            // Add the device ahead with default information to handle <Active Source>
            // promptly, rather than waiting till the new device action is finished.
            Slog.d(TAG, "Start NewDeviceAction with default deviceInfo");
            HdmiDeviceInfo deviceInfo = HdmiDeviceInfo.cecDeviceBuilder()
                    .setLogicalAddress(mDeviceLogicalAddress)
                    .setPhysicalAddress(mDevicePhysicalAddress)
                    .setPortId(tv().getPortId(mDevicePhysicalAddress))
                    .setDeviceType(mDeviceType)
                    .setVendorId(Constants.VENDOR_ID_UNKNOWN)
                    .build();
            // If a deviceInfo with same logical address but different physical address exists
            // We should remove the old deviceInfo first
            // This will happen if the interval between unplugging and plugging device is too short
            // and HotplugDetection Action fails to remove the old deviceInfo, or when the newly
            // plugged device violates HDMI Spec and uses an occupied logical address
            if (mOldDeviceInfo != null) {
                Slog.d(TAG, "Remove device by NewDeviceAction, logical address conflicts: "
                        + mDevicePhysicalAddress);
                localDevice().mService.getHdmiCecNetwork().removeCecDevice(
                        localDevice(), mDeviceLogicalAddress);
            }
            localDevice().mService.getHdmiCecNetwork().addCecDevice(deviceInfo);
        }
        requestOsdName(true);
        return true;
    }
@@ -182,16 +215,32 @@ final class NewDeviceAction extends HdmiCecFeatureAction {
                .setVendorId(mVendorId)
                .setDisplayName(mDisplayName)
                .build();
        localDevice().mService.getHdmiCecNetwork().updateCecDevice(deviceInfo);

        // Check if oldDevice is same as newDevice
        // If so, don't add newDevice info, preventing ARC or HDMI source re-connection
        if (mOldDeviceInfo != null
                && mOldDeviceInfo.getLogicalAddress() == mDeviceLogicalAddress
                && mOldDeviceInfo.getPhysicalAddress() == mDevicePhysicalAddress
                && mOldDeviceInfo.getDeviceType() == mDeviceType
                && mOldDeviceInfo.getVendorId() == mVendorId
                && mOldDeviceInfo.getDisplayName().equals(mDisplayName)) {
            // Consume CEC messages we already got for this newly found device.
            tv().processDelayedMessages(mDeviceLogicalAddress);
            Slog.d(TAG, "Ignore NewDevice, deviceInfo is same as current device");
            Slog.d(TAG, "Old:[" + mOldDeviceInfo.toString()
                    + "]; New:[" + deviceInfo.toString() + "]");
        } else {
            Slog.d(TAG, "Add NewDevice:[" + deviceInfo.toString() + "]");
            localDevice().mService.getHdmiCecNetwork().addCecDevice(deviceInfo);

            // Consume CEC messages we already got for this newly found device.
            tv().processDelayedMessages(mDeviceLogicalAddress);
            if (HdmiUtils.isEligibleAddressForDevice(HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM,
                        mDeviceLogicalAddress)) {
                tv().onNewAvrAdded(deviceInfo);
            }
        }
    }

    @Override
    public void handleTimerEvent(int state) {