Hook up the CEC playback API to service internal logic.
This change enables CEC playback API (oneTouchPlay, queryDisplayStatus).
Also updated local device list type to SparseArray to make it easy
to get one based on device type.
Change-Id: I6f88b2dac2d873c493a90411549a4e5719a5e460
diff --git a/services/core/java/com/android/server/hdmi/HdmiCecController.java b/services/core/java/com/android/server/hdmi/HdmiCecController.java
index 8d0696b..68ce607 100644
--- a/services/core/java/com/android/server/hdmi/HdmiCecController.java
+++ b/services/core/java/com/android/server/hdmi/HdmiCecController.java
@@ -80,8 +80,8 @@
// A logical address of device is used as key of container.
private final SparseArray<HdmiCecDeviceInfo> mDeviceInfos = new SparseArray<>();
- // Stores the local CEC devices in the system.
- private final ArrayList<HdmiCecLocalDevice> mLocalDevices = new ArrayList<>();
+ // Stores the local CEC devices in the system. Device type is used for key.
+ private final SparseArray<HdmiCecLocalDevice> mLocalDevices = new SparseArray<>();
// Private constructor. Use HdmiCecController.create().
private HdmiCecController() {
@@ -131,7 +131,7 @@
// TODO: Consider restoring the local device addresses from persistent storage
// to allocate the same addresses again if possible.
device.setPreferredAddress(HdmiCec.ADDR_UNREGISTERED);
- mLocalDevices.add(device);
+ mLocalDevices.put(type, device);
device.init();
}
}
@@ -290,6 +290,17 @@
}
/**
+ * Return the locally hosted logical device of a given type.
+ *
+ * @param deviceType logical device type
+ * @return {@link HdmiCecLocalDevice} instance if the instance of the type is available;
+ * otherwise null.
+ */
+ HdmiCecLocalDevice getLocalDevice(int deviceType) {
+ return mLocalDevices.get(deviceType);
+ }
+
+ /**
* Add a new logical address to the device. Device's HW should be notified
* when a new logical address is assigned to a device, so that it can accept
* a command having available destinations.
@@ -317,8 +328,8 @@
assertRunOnServiceThread();
// TODO: consider to backup logical address so that new logical address
// allocation can use it as preferred address.
- for (HdmiCecLocalDevice device : mLocalDevices) {
- device.clearAddress();
+ for (int i = 0; i < mLocalDevices.size(); ++i) {
+ mLocalDevices.valueAt(i).clearAddress();
}
nativeClearLogicalAddress(mNativePtr);
}
@@ -379,8 +390,8 @@
}
private boolean isAllocatedLocalDeviceAddress(int address) {
- for (HdmiCecLocalDevice device : mLocalDevices) {
- if (device.isAddressOf(address)) {
+ for (int i = 0; i < mLocalDevices.size(); ++i) {
+ if (mLocalDevices.valueAt(i).isAddressOf(address)) {
return true;
}
}