From 09ffc846af78f949d2847003db9f793bfb5eefaa Mon Sep 17 00:00:00 2001 From: Jinsuk Kim Date: Fri, 11 Jul 2014 17:04:32 +0900 Subject: [PATCH] Store active source/active port in HdmiControlService when disabled This lets the service keep track of the latest change made by TV app or TIF regarding active source/port. Bug: 16222083 Change-Id: I0f1a4520eb3e52ca5024567b0f1fbe4fd59e8cbf --- .../server/hdmi/HdmiCecLocalDeviceTv.java | 24 +++++++++++++------ .../server/hdmi/HdmiControlService.java | 9 +++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java b/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java index 9fc2b927bc078..bc68882d7f601 100644 --- a/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java +++ b/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java @@ -162,6 +162,11 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice { handleSelectInternalSource(callback); return; } + if (!mService.isControlEnabled()) { + setActiveSource(targetAddress); + invokeCallback(callback, HdmiControlManager.RESULT_INCORRECT_MODE); + return; + } HdmiCecDeviceInfo targetDevice = getDeviceInfo(targetAddress); if (targetDevice == null) { invokeCallback(callback, HdmiControlManager.RESULT_TARGET_NOT_AVAILABLE); @@ -240,18 +245,23 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice { void doManualPortSwitching(int portId, IHdmiControlCallback callback) { assertRunOnServiceThread(); // Seq #20 - if (!mService.isControlEnabled() || portId == getActivePortId()) { + if (!mService.isValidPortId(portId)) { invokeCallback(callback, HdmiControlManager.RESULT_INCORRECT_MODE); return; } - // TODO: Make sure this call does not stem from message reception. - + if (!mService.isControlEnabled()) { + setActivePortId(portId); + invokeCallback(callback, HdmiControlManager.RESULT_INCORRECT_MODE); + return; + } + if (portId == getActivePortId()) { + invokeCallback(callback, HdmiControlManager.RESULT_SUCCESS); + return; + } setActivePortId(portId); // TODO: Return immediately if the operation is triggered by - // and this is the first notification about the active input after power-on. - // TODO: Handle invalid port id / active input which should be treated as an - // internal tuner. - + // and this is the first notification about the active input after power-on + // (switch to HDMI didn't happen so far but is expected to happen soon). removeAction(RoutingControlAction.class); int oldPath = mService.portIdToPath(mService.portIdToPath(getActivePortId())); diff --git a/services/core/java/com/android/server/hdmi/HdmiControlService.java b/services/core/java/com/android/server/hdmi/HdmiControlService.java index c04b2bad064fc..a9a391bf367dd 100644 --- a/services/core/java/com/android/server/hdmi/HdmiControlService.java +++ b/services/core/java/com/android/server/hdmi/HdmiControlService.java @@ -398,6 +398,15 @@ public final class HdmiControlService extends SystemService { return Constants.INVALID_PORT_ID; } + boolean isValidPortId(int portId) { + for (HdmiPortInfo info : mPortInfo) { + if (portId == info.getId()) { + return true; + } + } + return false; + } + /** * Returns {@link Looper} for IO operation. *