From 3cd30516ad16150dee55ad8f704a0c3bf20b58b2 Mon Sep 17 00:00:00 2001 From: Jinsuk Kim Date: Thu, 4 Dec 2014 11:05:09 +0900 Subject: [PATCH] CEC: Generate hotplug events upon adding listener CEC HAL does not report initial connection state of the HDMI port but does it only when the state is updated. For the listeners which want to get the initial state of the ports, this CL generates hotplug event per each port when a new listener is added. Bug: 18488079 Change-Id: I6915a96e3c14ee0db1bfb6912ab77d3ea1bd2f07 --- .../server/hdmi/HdmiControlService.java | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/hdmi/HdmiControlService.java b/services/core/java/com/android/server/hdmi/HdmiControlService.java index 5f8b3899486ef..5df36b4cd7962 100644 --- a/services/core/java/com/android/server/hdmi/HdmiControlService.java +++ b/services/core/java/com/android/server/hdmi/HdmiControlService.java @@ -993,6 +993,19 @@ public final class HdmiControlService extends SystemService { mHotplugEventListenerRecords.remove(this); } } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof HotplugEventListenerRecord)) return false; + if (obj == this) return true; + HotplugEventListenerRecord other = (HotplugEventListenerRecord) obj; + return other.mListener == this.mListener; + } + + @Override + public int hashCode() { + return mListener.hashCode(); + } } private final class DeviceEventListenerRecord implements IBinder.DeathRecipient { @@ -1549,8 +1562,8 @@ public final class HdmiControlService extends SystemService { source.queryDisplayStatus(callback); } - private void addHotplugEventListener(IHdmiHotplugEventListener listener) { - HotplugEventListenerRecord record = new HotplugEventListenerRecord(listener); + private void addHotplugEventListener(final IHdmiHotplugEventListener listener) { + final HotplugEventListenerRecord record = new HotplugEventListenerRecord(listener); try { listener.asBinder().linkToDeath(record, 0); } catch (RemoteException e) { @@ -1560,6 +1573,24 @@ public final class HdmiControlService extends SystemService { synchronized (mLock) { mHotplugEventListenerRecords.add(record); } + + // Inform the listener of the initial state of each HDMI port by generating + // hotplug events. + runOnServiceThread(new Runnable() { + @Override + public void run() { + synchronized (mLock) { + if (!mHotplugEventListenerRecords.contains(record)) return; + } + for (HdmiPortInfo port : mPortInfo) { + HdmiHotplugEvent event = new HdmiHotplugEvent(port.getId(), + mCecController.isConnected(port.getId())); + synchronized (mLock) { + invokeHotplugEventListenerLocked(listener, event); + } + } + } + }); } private void removeHotplugEventListener(IHdmiHotplugEventListener listener) {