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

Commit 65224864 authored by Paul Colta's avatar Paul Colta
Browse files

HDMI: Avoid NPE on Hotplug In

In b/278002479#comment109, we discussed with MTK about a NullPointerException (NPE) that occurs when there are two consecutive Hotplugs (In & Out). This leads to an unsynchronized physical address between the HAL and framework, which results in the framework receiving an invalid physical address for the hotplug in.

Bug: 316343326
Bug: 278002479
Test: atest HdmiControlServiceTest
Change-Id: I16db00396e0f677e383c343515cb3338374bb9c2
parent 4de6bb88
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -201,7 +201,8 @@ public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDeviceSource {
        if (WAKE_ON_HOTPLUG && connected) {
            mService.wakeUp();
        }
        if (mService.getPortInfo(portId).getType() == HdmiPortInfo.PORT_OUTPUT) {
        HdmiPortInfo portInfo = mService.getPortInfo(portId);
        if (portInfo != null && portInfo.getType() == HdmiPortInfo.PORT_OUTPUT) {
            mCecMessageCache.flushAll();
            if (!connected) {
                if (isSystemAudioActivated()) {
+2 −1
Original line number Diff line number Diff line
@@ -92,7 +92,8 @@ abstract class HdmiCecLocalDeviceSource extends HdmiCecLocalDevice {
    @ServiceThreadOnly
    void onHotplug(int portId, boolean connected) {
        assertRunOnServiceThread();
        if (mService.getPortInfo(portId).getType() == HdmiPortInfo.PORT_OUTPUT) {
        HdmiPortInfo portInfo = mService.getPortInfo(portId);
        if (portInfo != null && portInfo.getType() == HdmiPortInfo.PORT_OUTPUT) {
            mCecMessageCache.flushAll();
        }
        // We'll not invalidate the active source on the hotplug event to pass CETC 11.2.2-2 ~ 3.
+2 −1
Original line number Diff line number Diff line
@@ -1783,8 +1783,9 @@ public class HdmiControlService extends SystemService {
        // initPortInfo at hotplug event.
        mHdmiCecNetwork.initPortInfo();

        HdmiPortInfo portInfo = getPortInfo(portId);
        if (connected && !isTvDevice()
                && getPortInfo(portId).getType() == HdmiPortInfo.PORT_OUTPUT) {
                && portInfo != null && portInfo.getType() == HdmiPortInfo.PORT_OUTPUT) {
            ArrayList<HdmiCecLocalDevice> localDevices = new ArrayList<>();
            for (int type : getCecLocalDeviceTypes()) {
                HdmiCecLocalDevice localDevice = mHdmiCecNetwork.getLocalDevice(type);
+9 −0
Original line number Diff line number Diff line
@@ -1706,6 +1706,15 @@ public class HdmiControlServiceTest {
        verify(mHdmiControlServiceSpy, times(1)).startArcAction(eq(false), any());
    }

    @Test
    public void onHotplugIn_invalidPortId_noAddressAllocation() {
        mHdmiControlServiceSpy.onHotplug(-1, true);
        mTestLooper.dispatchAll();

        verify(mHdmiControlServiceSpy, times(0))
                .allocateLogicalAddress(any(), eq(INITIATED_BY_HOTPLUG));
    }

    protected static class MockPlaybackDevice extends HdmiCecLocalDevicePlayback {

        private boolean mCanGoToStandby;