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

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

Merge "Add system audio control audio port switch check."

parents cc7700bb ac1a55ca
Loading
Loading
Loading
Loading
+31 −1
Original line number Diff line number Diff line
@@ -323,7 +323,11 @@ public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDevice {
        // Wake up device if System Audio Control is turned on but device is still on standby
        if (newSystemAudioMode && mService.isPowerStandbyOrTransient()) {
            mService.wakeUp();
            // TODO(amyjojo): Switch to the corresponding input
        }
        int targetPhysicalAddress = getActiveSource().physicalAddress;
        if (newSystemAudioMode &&
            !isPhysicalAddressMeOrBelow(targetPhysicalAddress)) {
            switchToAudioInput();
        }
        // Mute device when feature is turned off and unmute device when feature is turned on
        boolean currentMuteStatus =
@@ -347,6 +351,32 @@ public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDevice {
        return true;
    }

    /**
     * Method to check if the target device belongs to the subtree of the current device or not.
     * <p>Return true if it does or if the two devices share the same physical address.
     *
     * <p>This check assumes both device physical address and target address are valid.
     * @param targetPhysicalAddress is the physical address of the target device
     */
    protected boolean isPhysicalAddressMeOrBelow(int targetPhysicalAddress) {
        int myPhysicalAddress = mService.getPhysicalAddress();
        int xor = targetPhysicalAddress ^ myPhysicalAddress;
        // Return true if two addresses are the same
        // or if they only differs for one byte, but not the first byte,
        // and myPhysicalAddress is 0 after that byte
        if (xor == 0
            || ((xor & 0x0f00) == xor && (myPhysicalAddress & 0x0fff) == 0)
            || ((xor & 0x00f0) == xor && (myPhysicalAddress & 0x00ff) == 0)
            || ((xor & 0x000f) == xor && (myPhysicalAddress & 0x000f) == 0)) {
            return true;
        }
        return false;
    }

    protected void switchToAudioInput() {
        // TODO(b/111396634): switch input according to PROPERTY_SYSTEM_AUDIO_MODE_AUDIO_PORT
    }

    private void updateAudioManagerForSystemAudio(boolean on) {
        int device = mService.getAudioManager().setHdmiSystemAudioSupported(on);
        HdmiLogger.debug("[A]UpdateSystemAudio mode[on=%b] output=[%X]", on, device);
+9 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.os.MessageQueue;
import com.android.server.hdmi.HdmiCecController.NativeWrapper;
import java.util.ArrayList;
import java.util.List;
import com.android.internal.annotations.VisibleForTesting;

/** Fake {@link NativeWrapper} useful for testing. */
final class FakeNativeWrapper implements NativeWrapper {
@@ -44,6 +45,8 @@ final class FakeNativeWrapper implements NativeWrapper {
            };

    private final List<HdmiCecMessage> mResultMessages = new ArrayList<>();
    private HdmiCecMessage mResultMessage;
    private int mMyPhysicalAddress = 0;

    @Override
    public long nativeInit(HdmiCecController handler, MessageQueue messageQueue) {
@@ -71,7 +74,7 @@ final class FakeNativeWrapper implements NativeWrapper {

    @Override
    public int nativeGetPhysicalAddress(long controllerPtr) {
        return 0;
        return mMyPhysicalAddress;
    }

    @Override
@@ -119,4 +122,9 @@ final class FakeNativeWrapper implements NativeWrapper {
    public void setPollAddressResponse(int logicalAddress, int response) {
        mPollAddressResponse[logicalAddress] = response;
    }

    @VisibleForTesting
    protected void setPhysicalAddress(int physicalAddress) {
        mMyPhysicalAddress = physicalAddress;
    }
}
+39 −0
Original line number Diff line number Diff line
@@ -306,4 +306,43 @@ public class HdmiCecLocalDeviceAudioSystemTest {
        mTestLooper.dispatchAll();
        assertThat(mNativeWrapper.getResultMessages()).contains(expectedMessage);
    }

    @Test
    public void isPhysicalAddressMeOrBelow_isMe() {
        int targetPhysicalAddress = 0x1000;
        mNativeWrapper.setPhysicalAddress(0x1000);
        assertThat(mHdmiCecLocalDeviceAudioSystem.isPhysicalAddressMeOrBelow(targetPhysicalAddress))
            .isEqualTo(true);
    }

    @Test
    public void isPhysicalAddressMeOrBelow_isBelow() {
        int targetPhysicalAddress = 0x1100;
        mNativeWrapper.setPhysicalAddress(0x1000);
        assertThat(mHdmiCecLocalDeviceAudioSystem.isPhysicalAddressMeOrBelow(targetPhysicalAddress))
            .isEqualTo(true);
    }

    @Test
    public void isPhysicalAddressMeOrBelow_neitherMeNorBelow() {
        int targetPhysicalAddress = 0x3000;
        mNativeWrapper.setPhysicalAddress(0x2000);
        assertThat(mHdmiCecLocalDeviceAudioSystem.isPhysicalAddressMeOrBelow(targetPhysicalAddress))
            .isEqualTo(false);

        targetPhysicalAddress = 0x2200;
        mNativeWrapper.setPhysicalAddress(0x3300);
        assertThat(mHdmiCecLocalDeviceAudioSystem.isPhysicalAddressMeOrBelow(targetPhysicalAddress))
            .isEqualTo(false);

        targetPhysicalAddress = 0x2213;
        mNativeWrapper.setPhysicalAddress(0x2212);
        assertThat(mHdmiCecLocalDeviceAudioSystem.isPhysicalAddressMeOrBelow(targetPhysicalAddress))
            .isEqualTo(false);

        targetPhysicalAddress = 0x2340;
        mNativeWrapper.setPhysicalAddress(0x2310);
        assertThat(mHdmiCecLocalDeviceAudioSystem.isPhysicalAddressMeOrBelow(targetPhysicalAddress))
            .isEqualTo(false);
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -130,6 +130,11 @@ public class SystemAudioInitiationActionFromAvrTest {
            void wakeUp() {

            }

            @Override
            int getPhysicalAddress() {
                return 0;
            }
        };
        mHdmiCecLocalDeviceAudioSystem =
                new HdmiCecLocalDeviceAudioSystem(hdmiControlService) {