Loading services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceAudioSystem.java +31 −1 Original line number Diff line number Diff line Loading @@ -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 = Loading @@ -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); Loading services/tests/servicestests/src/com/android/server/hdmi/FakeNativeWrapper.java +9 −1 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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) { Loading Loading @@ -71,7 +74,7 @@ final class FakeNativeWrapper implements NativeWrapper { @Override public int nativeGetPhysicalAddress(long controllerPtr) { return 0; return mMyPhysicalAddress; } @Override Loading Loading @@ -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; } } services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDeviceAudioSystemTest.java +39 −0 Original line number Diff line number Diff line Loading @@ -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); } } services/tests/servicestests/src/com/android/server/hdmi/SystemAudioInitiationActionFromAvrTest.java +5 −0 Original line number Diff line number Diff line Loading @@ -130,6 +130,11 @@ public class SystemAudioInitiationActionFromAvrTest { void wakeUp() { } @Override int getPhysicalAddress() { return 0; } }; mHdmiCecLocalDeviceAudioSystem = new HdmiCecLocalDeviceAudioSystem(hdmiControlService) { Loading Loading
services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceAudioSystem.java +31 −1 Original line number Diff line number Diff line Loading @@ -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 = Loading @@ -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); Loading
services/tests/servicestests/src/com/android/server/hdmi/FakeNativeWrapper.java +9 −1 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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) { Loading Loading @@ -71,7 +74,7 @@ final class FakeNativeWrapper implements NativeWrapper { @Override public int nativeGetPhysicalAddress(long controllerPtr) { return 0; return mMyPhysicalAddress; } @Override Loading Loading @@ -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; } }
services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDeviceAudioSystemTest.java +39 −0 Original line number Diff line number Diff line Loading @@ -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); } }
services/tests/servicestests/src/com/android/server/hdmi/SystemAudioInitiationActionFromAvrTest.java +5 −0 Original line number Diff line number Diff line Loading @@ -130,6 +130,11 @@ public class SystemAudioInitiationActionFromAvrTest { void wakeUp() { } @Override int getPhysicalAddress() { return 0; } }; mHdmiCecLocalDeviceAudioSystem = new HdmiCecLocalDeviceAudioSystem(hdmiControlService) { Loading