Set device type on first message received
When receiving the first message from a new device, deduce its device type from its logical address if possible and store it in the network. Bug: 205082572 Test: atest HdmiCecNetworkTest Change-Id: I66b0969347e7d292f8222efb250156e0421e60ca
This commit is contained in:
committed by
Nathalie Le Clair
parent
3f31afd1cf
commit
6304e44df4
@@ -360,10 +360,12 @@ public class HdmiCecNetwork {
|
|||||||
// This only applies to TV devices.
|
// This only applies to TV devices.
|
||||||
// Returns true if the policy is set to true, and the device to check does not have
|
// Returns true if the policy is set to true, and the device to check does not have
|
||||||
// a parent CEC device (which should be the CEC-enabled switch) in the list.
|
// a parent CEC device (which should be the CEC-enabled switch) in the list.
|
||||||
|
// Devices with an invalid physical address are assumed to NOT be connected to a legacy switch.
|
||||||
private boolean hideDevicesBehindLegacySwitch(HdmiDeviceInfo info) {
|
private boolean hideDevicesBehindLegacySwitch(HdmiDeviceInfo info) {
|
||||||
return isLocalDeviceAddress(Constants.ADDR_TV)
|
return isLocalDeviceAddress(Constants.ADDR_TV)
|
||||||
&& HdmiConfig.HIDE_DEVICES_BEHIND_LEGACY_SWITCH
|
&& HdmiConfig.HIDE_DEVICES_BEHIND_LEGACY_SWITCH
|
||||||
&& !isConnectedToCecSwitch(info.getPhysicalAddress(), getCecSwitches());
|
&& !isConnectedToCecSwitch(info.getPhysicalAddress(), getCecSwitches())
|
||||||
|
&& info.getPhysicalAddress() != HdmiDeviceInfo.PATH_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -488,6 +490,34 @@ public class HdmiCecNetwork {
|
|||||||
return device.getPhysicalAddress() == physicalAddress;
|
return device.getPhysicalAddress() == physicalAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to deduce the device type of a device given its logical address.
|
||||||
|
* If multiple types are possible, returns {@link HdmiDeviceInfo#DEVICE_RESERVED}.
|
||||||
|
*/
|
||||||
|
private static int logicalAddressToDeviceType(int logicalAddress) {
|
||||||
|
switch (logicalAddress) {
|
||||||
|
case Constants.ADDR_TV:
|
||||||
|
return HdmiDeviceInfo.DEVICE_TV;
|
||||||
|
case Constants.ADDR_RECORDER_1:
|
||||||
|
case Constants.ADDR_RECORDER_2:
|
||||||
|
case Constants.ADDR_RECORDER_3:
|
||||||
|
return HdmiDeviceInfo.DEVICE_RECORDER;
|
||||||
|
case Constants.ADDR_TUNER_1:
|
||||||
|
case Constants.ADDR_TUNER_2:
|
||||||
|
case Constants.ADDR_TUNER_3:
|
||||||
|
case Constants.ADDR_TUNER_4:
|
||||||
|
return HdmiDeviceInfo.DEVICE_TUNER;
|
||||||
|
case Constants.ADDR_PLAYBACK_1:
|
||||||
|
case Constants.ADDR_PLAYBACK_2:
|
||||||
|
case Constants.ADDR_PLAYBACK_3:
|
||||||
|
return HdmiDeviceInfo.DEVICE_PLAYBACK;
|
||||||
|
case Constants.ADDR_AUDIO_SYSTEM:
|
||||||
|
return HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM;
|
||||||
|
default:
|
||||||
|
return HdmiDeviceInfo.DEVICE_RESERVED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Passively listen to incoming CEC messages.
|
* Passively listen to incoming CEC messages.
|
||||||
*
|
*
|
||||||
@@ -502,6 +532,7 @@ public class HdmiCecNetwork {
|
|||||||
HdmiDeviceInfo newDevice = HdmiDeviceInfo.cecDeviceBuilder()
|
HdmiDeviceInfo newDevice = HdmiDeviceInfo.cecDeviceBuilder()
|
||||||
.setLogicalAddress(sourceAddress)
|
.setLogicalAddress(sourceAddress)
|
||||||
.setDisplayName(HdmiUtils.getDefaultDeviceName(sourceAddress))
|
.setDisplayName(HdmiUtils.getDefaultDeviceName(sourceAddress))
|
||||||
|
.setDeviceType(logicalAddressToDeviceType(sourceAddress))
|
||||||
.build();
|
.build();
|
||||||
addCecDevice(newDevice);
|
addCecDevice(newDevice);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,6 +102,8 @@ public class HdmiCecNetworkTest {
|
|||||||
new HdmiPortInfo(5, HdmiPortInfo.PORT_OUTPUT, 0x0000, true, false, false);
|
new HdmiPortInfo(5, HdmiPortInfo.PORT_OUTPUT, 0x0000, true, false, false);
|
||||||
mNativeWrapper.setPortInfo(mHdmiPortInfo);
|
mNativeWrapper.setPortInfo(mHdmiPortInfo);
|
||||||
mHdmiCecNetwork.initPortInfo();
|
mHdmiCecNetwork.initPortInfo();
|
||||||
|
|
||||||
|
mHdmiCecNetwork = mHdmiControlService.getHdmiCecNetwork();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -143,6 +145,7 @@ public class HdmiCecNetworkTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void localDevices_verifyOne_tv() {
|
public void localDevices_verifyOne_tv() {
|
||||||
|
mHdmiCecNetwork.clearLocalDevices();
|
||||||
mHdmiCecNetwork.addLocalDevice(HdmiDeviceInfo.DEVICE_TV,
|
mHdmiCecNetwork.addLocalDevice(HdmiDeviceInfo.DEVICE_TV,
|
||||||
new HdmiCecLocalDeviceTv(mHdmiControlService));
|
new HdmiCecLocalDeviceTv(mHdmiControlService));
|
||||||
|
|
||||||
@@ -155,6 +158,7 @@ public class HdmiCecNetworkTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void localDevices_verifyOne_playback() {
|
public void localDevices_verifyOne_playback() {
|
||||||
|
mHdmiCecNetwork.clearLocalDevices();
|
||||||
mHdmiCecNetwork.addLocalDevice(HdmiDeviceInfo.DEVICE_PLAYBACK,
|
mHdmiCecNetwork.addLocalDevice(HdmiDeviceInfo.DEVICE_PLAYBACK,
|
||||||
new HdmiCecLocalDevicePlayback(mHdmiControlService));
|
new HdmiCecLocalDevicePlayback(mHdmiControlService));
|
||||||
|
|
||||||
@@ -177,7 +181,7 @@ public class HdmiCecNetworkTest {
|
|||||||
assertThat(cecDeviceInfo.getLogicalAddress()).isEqualTo(logicalAddress);
|
assertThat(cecDeviceInfo.getLogicalAddress()).isEqualTo(logicalAddress);
|
||||||
assertThat(cecDeviceInfo.getPhysicalAddress()).isEqualTo(
|
assertThat(cecDeviceInfo.getPhysicalAddress()).isEqualTo(
|
||||||
Constants.INVALID_PHYSICAL_ADDRESS);
|
Constants.INVALID_PHYSICAL_ADDRESS);
|
||||||
assertThat(cecDeviceInfo.getDeviceType()).isEqualTo(HdmiDeviceInfo.DEVICE_RESERVED);
|
assertThat(cecDeviceInfo.getDeviceType()).isEqualTo(HdmiDeviceInfo.DEVICE_PLAYBACK);
|
||||||
assertThat(cecDeviceInfo.getDisplayName()).isEqualTo(
|
assertThat(cecDeviceInfo.getDisplayName()).isEqualTo(
|
||||||
HdmiUtils.getDefaultDeviceName(logicalAddress));
|
HdmiUtils.getDefaultDeviceName(logicalAddress));
|
||||||
assertThat(cecDeviceInfo.getVendorId()).isEqualTo(Constants.VENDOR_ID_UNKNOWN);
|
assertThat(cecDeviceInfo.getVendorId()).isEqualTo(Constants.VENDOR_ID_UNKNOWN);
|
||||||
@@ -259,7 +263,7 @@ public class HdmiCecNetworkTest {
|
|||||||
assertThat(cecDeviceInfo.getLogicalAddress()).isEqualTo(logicalAddress);
|
assertThat(cecDeviceInfo.getLogicalAddress()).isEqualTo(logicalAddress);
|
||||||
assertThat(cecDeviceInfo.getPhysicalAddress()).isEqualTo(
|
assertThat(cecDeviceInfo.getPhysicalAddress()).isEqualTo(
|
||||||
Constants.INVALID_PHYSICAL_ADDRESS);
|
Constants.INVALID_PHYSICAL_ADDRESS);
|
||||||
assertThat(cecDeviceInfo.getDeviceType()).isEqualTo(HdmiDeviceInfo.DEVICE_RESERVED);
|
assertThat(cecDeviceInfo.getDeviceType()).isEqualTo(HdmiDeviceInfo.DEVICE_PLAYBACK);
|
||||||
assertThat(cecDeviceInfo.getVendorId()).isEqualTo(Constants.VENDOR_ID_UNKNOWN);
|
assertThat(cecDeviceInfo.getVendorId()).isEqualTo(Constants.VENDOR_ID_UNKNOWN);
|
||||||
assertThat(cecDeviceInfo.getDisplayName()).isEqualTo(
|
assertThat(cecDeviceInfo.getDisplayName()).isEqualTo(
|
||||||
HdmiUtils.getDefaultDeviceName(logicalAddress));
|
HdmiUtils.getDefaultDeviceName(logicalAddress));
|
||||||
@@ -280,7 +284,7 @@ public class HdmiCecNetworkTest {
|
|||||||
assertThat(cecDeviceInfo.getLogicalAddress()).isEqualTo(logicalAddress);
|
assertThat(cecDeviceInfo.getLogicalAddress()).isEqualTo(logicalAddress);
|
||||||
assertThat(cecDeviceInfo.getPhysicalAddress()).isEqualTo(
|
assertThat(cecDeviceInfo.getPhysicalAddress()).isEqualTo(
|
||||||
Constants.INVALID_PHYSICAL_ADDRESS);
|
Constants.INVALID_PHYSICAL_ADDRESS);
|
||||||
assertThat(cecDeviceInfo.getDeviceType()).isEqualTo(HdmiDeviceInfo.DEVICE_RESERVED);
|
assertThat(cecDeviceInfo.getDeviceType()).isEqualTo(HdmiDeviceInfo.DEVICE_PLAYBACK);
|
||||||
assertThat(cecDeviceInfo.getVendorId()).isEqualTo(Constants.VENDOR_ID_UNKNOWN);
|
assertThat(cecDeviceInfo.getVendorId()).isEqualTo(Constants.VENDOR_ID_UNKNOWN);
|
||||||
assertThat(cecDeviceInfo.getDisplayName()).isEqualTo(osdName);
|
assertThat(cecDeviceInfo.getDisplayName()).isEqualTo(osdName);
|
||||||
assertThat(cecDeviceInfo.getDevicePowerStatus()).isEqualTo(
|
assertThat(cecDeviceInfo.getDevicePowerStatus()).isEqualTo(
|
||||||
@@ -300,7 +304,7 @@ public class HdmiCecNetworkTest {
|
|||||||
assertThat(cecDeviceInfo.getLogicalAddress()).isEqualTo(logicalAddress);
|
assertThat(cecDeviceInfo.getLogicalAddress()).isEqualTo(logicalAddress);
|
||||||
assertThat(cecDeviceInfo.getPhysicalAddress()).isEqualTo(
|
assertThat(cecDeviceInfo.getPhysicalAddress()).isEqualTo(
|
||||||
Constants.INVALID_PHYSICAL_ADDRESS);
|
Constants.INVALID_PHYSICAL_ADDRESS);
|
||||||
assertThat(cecDeviceInfo.getDeviceType()).isEqualTo(HdmiDeviceInfo.DEVICE_RESERVED);
|
assertThat(cecDeviceInfo.getDeviceType()).isEqualTo(HdmiDeviceInfo.DEVICE_PLAYBACK);
|
||||||
assertThat(cecDeviceInfo.getDisplayName()).isEqualTo(
|
assertThat(cecDeviceInfo.getDisplayName()).isEqualTo(
|
||||||
HdmiUtils.getDefaultDeviceName(logicalAddress));
|
HdmiUtils.getDefaultDeviceName(logicalAddress));
|
||||||
assertThat(cecDeviceInfo.getVendorId()).isEqualTo(vendorId);
|
assertThat(cecDeviceInfo.getVendorId()).isEqualTo(vendorId);
|
||||||
@@ -431,7 +435,7 @@ public class HdmiCecNetworkTest {
|
|||||||
assertThat(cecDeviceInfo.getLogicalAddress()).isEqualTo(logicalAddress);
|
assertThat(cecDeviceInfo.getLogicalAddress()).isEqualTo(logicalAddress);
|
||||||
assertThat(cecDeviceInfo.getPhysicalAddress()).isEqualTo(
|
assertThat(cecDeviceInfo.getPhysicalAddress()).isEqualTo(
|
||||||
Constants.INVALID_PHYSICAL_ADDRESS);
|
Constants.INVALID_PHYSICAL_ADDRESS);
|
||||||
assertThat(cecDeviceInfo.getDeviceType()).isEqualTo(HdmiDeviceInfo.DEVICE_RESERVED);
|
assertThat(cecDeviceInfo.getDeviceType()).isEqualTo(HdmiDeviceInfo.DEVICE_PLAYBACK);
|
||||||
assertThat(cecDeviceInfo.getDisplayName()).isEqualTo(
|
assertThat(cecDeviceInfo.getDisplayName()).isEqualTo(
|
||||||
HdmiUtils.getDefaultDeviceName(logicalAddress));
|
HdmiUtils.getDefaultDeviceName(logicalAddress));
|
||||||
assertThat(cecDeviceInfo.getVendorId()).isEqualTo(updatedVendorId);
|
assertThat(cecDeviceInfo.getVendorId()).isEqualTo(updatedVendorId);
|
||||||
@@ -472,7 +476,7 @@ public class HdmiCecNetworkTest {
|
|||||||
assertThat(cecDeviceInfo.getLogicalAddress()).isEqualTo(logicalAddress);
|
assertThat(cecDeviceInfo.getLogicalAddress()).isEqualTo(logicalAddress);
|
||||||
assertThat(cecDeviceInfo.getPhysicalAddress()).isEqualTo(
|
assertThat(cecDeviceInfo.getPhysicalAddress()).isEqualTo(
|
||||||
Constants.INVALID_PHYSICAL_ADDRESS);
|
Constants.INVALID_PHYSICAL_ADDRESS);
|
||||||
assertThat(cecDeviceInfo.getDeviceType()).isEqualTo(HdmiDeviceInfo.DEVICE_RESERVED);
|
assertThat(cecDeviceInfo.getDeviceType()).isEqualTo(HdmiDeviceInfo.DEVICE_PLAYBACK);
|
||||||
assertThat(cecDeviceInfo.getVendorId()).isEqualTo(Constants.VENDOR_ID_UNKNOWN);
|
assertThat(cecDeviceInfo.getVendorId()).isEqualTo(Constants.VENDOR_ID_UNKNOWN);
|
||||||
assertThat(cecDeviceInfo.getDisplayName()).isEqualTo(
|
assertThat(cecDeviceInfo.getDisplayName()).isEqualTo(
|
||||||
HdmiUtils.getDefaultDeviceName(logicalAddress));
|
HdmiUtils.getDefaultDeviceName(logicalAddress));
|
||||||
|
|||||||
Reference in New Issue
Block a user