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 Merged-In: I66b0969347e7d292f8222efb250156e0421e60ca
This commit is contained in:
committed by
Nathalie Le Clair
parent
6bda795c2b
commit
888ee5bea0
@@ -370,10 +370,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -497,6 +499,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.
|
||||||
*
|
*
|
||||||
@@ -510,7 +540,7 @@ public class HdmiCecNetwork {
|
|||||||
if (getCecDeviceInfo(sourceAddress) == null) {
|
if (getCecDeviceInfo(sourceAddress) == null) {
|
||||||
HdmiDeviceInfo newDevice = new HdmiDeviceInfo(sourceAddress,
|
HdmiDeviceInfo newDevice = new HdmiDeviceInfo(sourceAddress,
|
||||||
HdmiDeviceInfo.PATH_INVALID, HdmiDeviceInfo.PORT_INVALID,
|
HdmiDeviceInfo.PATH_INVALID, HdmiDeviceInfo.PORT_INVALID,
|
||||||
HdmiDeviceInfo.DEVICE_RESERVED, Constants.UNKNOWN_VENDOR_ID,
|
logicalAddressToDeviceType(sourceAddress), Constants.UNKNOWN_VENDOR_ID,
|
||||||
HdmiUtils.getDefaultDeviceName(sourceAddress));
|
HdmiUtils.getDefaultDeviceName(sourceAddress));
|
||||||
addCecDevice(newDevice);
|
addCecDevice(newDevice);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,6 +100,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
|
||||||
@@ -141,6 +143,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));
|
||||||
|
|
||||||
@@ -153,6 +156,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));
|
||||||
|
|
||||||
@@ -175,7 +179,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.UNKNOWN_VENDOR_ID);
|
assertThat(cecDeviceInfo.getVendorId()).isEqualTo(Constants.UNKNOWN_VENDOR_ID);
|
||||||
@@ -257,7 +261,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.UNKNOWN_VENDOR_ID);
|
assertThat(cecDeviceInfo.getVendorId()).isEqualTo(Constants.UNKNOWN_VENDOR_ID);
|
||||||
assertThat(cecDeviceInfo.getDisplayName()).isEqualTo(
|
assertThat(cecDeviceInfo.getDisplayName()).isEqualTo(
|
||||||
HdmiUtils.getDefaultDeviceName(logicalAddress));
|
HdmiUtils.getDefaultDeviceName(logicalAddress));
|
||||||
@@ -278,7 +282,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.UNKNOWN_VENDOR_ID);
|
assertThat(cecDeviceInfo.getVendorId()).isEqualTo(Constants.UNKNOWN_VENDOR_ID);
|
||||||
assertThat(cecDeviceInfo.getDisplayName()).isEqualTo(osdName);
|
assertThat(cecDeviceInfo.getDisplayName()).isEqualTo(osdName);
|
||||||
assertThat(cecDeviceInfo.getDevicePowerStatus()).isEqualTo(
|
assertThat(cecDeviceInfo.getDevicePowerStatus()).isEqualTo(
|
||||||
@@ -298,7 +302,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);
|
||||||
@@ -429,7 +433,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);
|
||||||
@@ -470,7 +474,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.UNKNOWN_VENDOR_ID);
|
assertThat(cecDeviceInfo.getVendorId()).isEqualTo(Constants.UNKNOWN_VENDOR_ID);
|
||||||
assertThat(cecDeviceInfo.getDisplayName()).isEqualTo(
|
assertThat(cecDeviceInfo.getDisplayName()).isEqualTo(
|
||||||
HdmiUtils.getDefaultDeviceName(logicalAddress));
|
HdmiUtils.getDefaultDeviceName(logicalAddress));
|
||||||
|
|||||||
Reference in New Issue
Block a user