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

Commit fb0e36e2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "CEC: Handle error coming during getPhysicalAddress from HAL."

parents 8f2ed82c fede8f7c
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.server.hdmi;

import android.annotation.CallSuper;
import android.annotation.Nullable;
import android.hardware.hdmi.HdmiControlManager;
import android.hardware.hdmi.HdmiDeviceInfo;
import android.hardware.hdmi.IHdmiControlCallback;
@@ -282,7 +281,7 @@ abstract class HdmiCecLocalDevice {
            case Constants.MESSAGE_SET_MENU_LANGUAGE:
                return handleSetMenuLanguage(message);
            case Constants.MESSAGE_GIVE_PHYSICAL_ADDRESS:
                return handleGivePhysicalAddress(null);
                return handleGivePhysicalAddress(message);
            case Constants.MESSAGE_GIVE_OSD_NAME:
                return handleGiveOsdName(message);
            case Constants.MESSAGE_GIVE_DEVICE_VENDOR_ID:
@@ -381,14 +380,17 @@ abstract class HdmiCecLocalDevice {

    @ServiceThreadOnly
    @Constants.HandleMessageResult
    protected int handleGivePhysicalAddress(@Nullable SendMessageCallback callback) {
    protected int handleGivePhysicalAddress(HdmiCecMessage message) {
        assertRunOnServiceThread();

        int physicalAddress = mService.getPhysicalAddress();
        if (physicalAddress == Constants.INVALID_PHYSICAL_ADDRESS) {
            mService.maySendFeatureAbortCommand(message, Constants.ABORT_UNABLE_TO_DETERMINE);
        } else {
            HdmiCecMessage cecMessage =
                    HdmiCecMessageBuilder.buildReportPhysicalAddressCommand(
                            mAddress, physicalAddress, mDeviceType);
        mService.sendCecCommand(cecMessage, callback);
            mService.sendCecCommand(cecMessage);
        }
        return Constants.HANDLED;
    }

+27 −17
Original line number Diff line number Diff line
@@ -18,10 +18,8 @@ package com.android.server.hdmi;
import static android.hardware.hdmi.HdmiDeviceInfo.DEVICE_TV;

import static com.android.server.hdmi.Constants.ADDR_AUDIO_SYSTEM;
import static com.android.server.hdmi.Constants.ADDR_BROADCAST;
import static com.android.server.hdmi.Constants.ADDR_PLAYBACK_1;
import static com.android.server.hdmi.Constants.ADDR_TV;
import static com.android.server.hdmi.Constants.ADDR_UNREGISTERED;
import static com.android.server.hdmi.Constants.MESSAGE_DEVICE_VENDOR_ID;
import static com.android.server.hdmi.Constants.MESSAGE_REPORT_PHYSICAL_ADDRESS;
import static com.android.server.hdmi.HdmiControlService.INITIATED_BY_ENABLE_CEC;
@@ -223,24 +221,36 @@ public class HdmiCecLocalDeviceTest {

    @Test
    public void handleGivePhysicalAddress_success() {
        mSrcAddr = ADDR_UNREGISTERED;
        mDesAddr = ADDR_BROADCAST;
        param =
                new byte[] {
                    (byte) ((mPhysicalAddr >> 8) & 0xFF),
                    (byte) (mPhysicalAddr & 0xFF),
                    (byte) (DEVICE_TV & 0xFF)
                };
        callbackResult = -1;
        @Constants.HandleMessageResult int handleResult =
        mNativeWrapper.setPhysicalAddress(0x0);
        HdmiCecMessage expectedMessage =
                HdmiCecMessageBuilder.buildReportPhysicalAddressCommand(ADDR_TV, 0, DEVICE_TV);
        @Constants.HandleMessageResult
        int handleResult =
                mHdmiLocalDevice.handleGivePhysicalAddress(
                        (int finalResult) -> callbackResult = finalResult);
                        HdmiCecMessageBuilder.buildGivePhysicalAddress(
                                ADDR_PLAYBACK_1, ADDR_TV));
        mTestLooper.dispatchAll();
        assertEquals(Constants.HANDLED, handleResult);
        assertThat(mNativeWrapper.getOnlyResultMessage()).isEqualTo(expectedMessage);
    }

    @Test
    public void handleGivePhysicalAddress_failure() {
        mNativeWrapper.setPhysicalAddress(Constants.INVALID_PHYSICAL_ADDRESS);
        HdmiCecMessage expectedMessage =
                HdmiCecMessageBuilder.buildFeatureAbortCommand(
                        ADDR_TV,
                        ADDR_PLAYBACK_1,
                        Constants.MESSAGE_GIVE_PHYSICAL_ADDRESS,
                        Constants.ABORT_UNABLE_TO_DETERMINE);
        @Constants.HandleMessageResult
        int handleResult =
                mHdmiLocalDevice.handleGivePhysicalAddress(
                        HdmiCecMessageBuilder.buildGivePhysicalAddress(
                                ADDR_PLAYBACK_1, ADDR_TV));
        mTestLooper.dispatchAll();
        /**
         * Test if CecMessage is sent successfully SendMessageResult#SUCCESS is defined in HAL as 0
         */
        assertEquals(0, callbackResult);
        assertEquals(Constants.HANDLED, handleResult);
        assertThat(mNativeWrapper.getOnlyResultMessage()).isEqualTo(expectedMessage);
    }

    @Test