From 546d867cb89099ed9036d54d1d49e11748c9a27e Mon Sep 17 00:00:00 2001 From: Jinsuk Kim Date: Mon, 24 Nov 2014 07:30:54 +0900 Subject: [PATCH] CEC: Do not issue non-effective CEC command should not be issued if old and new path are identical since it not only have no effect but also can lead certain devices to taking unexpected action. Bug: 18283251 Change-Id: I7a210b7aa20ce4b96ef0d260c4abfc10d4393e63 --- .../server/hdmi/ActiveSourceHandler.java | 7 ++--- .../server/hdmi/HdmiCecLocalDeviceTv.java | 30 +++++++++---------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/services/core/java/com/android/server/hdmi/ActiveSourceHandler.java b/services/core/java/com/android/server/hdmi/ActiveSourceHandler.java index 9593a9cb8e8aa..59d5605b8d858 100644 --- a/services/core/java/com/android/server/hdmi/ActiveSourceHandler.java +++ b/services/core/java/com/android/server/hdmi/ActiveSourceHandler.java @@ -89,11 +89,8 @@ final class ActiveSourceHandler { tv.updateActiveSource(current); invokeCallback(HdmiControlManager.RESULT_SUCCESS); } else { - HdmiCecMessage routingChange = HdmiCecMessageBuilder.buildRoutingChange( - getSourceAddress(), newActive.physicalAddress, current.physicalAddress); - mService.sendCecCommand(routingChange); - tv.addAndStartAction( - new RoutingControlAction(tv, current.physicalAddress, true, mCallback)); + tv.startRoutingControl(newActive.physicalAddress, current.physicalAddress, true, + mCallback); } } } diff --git a/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java b/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java index ec381243311de..3f78949623bdd 100644 --- a/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java +++ b/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java @@ -362,11 +362,22 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice { return; } int newPath = mService.portIdToPath(portId); + startRoutingControl(oldPath, newPath, true, callback); + } + + @ServiceThreadOnly + void startRoutingControl(int oldPath, int newPath, boolean queryDevicePowerStatus, + IHdmiControlCallback callback) { + assertRunOnServiceThread(); + if (oldPath == newPath) { + return; + } HdmiCecMessage routingChange = HdmiCecMessageBuilder.buildRoutingChange(mAddress, oldPath, newPath); mService.sendCecCommand(routingChange); removeAction(RoutingControlAction.class); - addAndStartAction(new RoutingControlAction(this, newPath, true, callback)); + addAndStartAction( + new RoutingControlAction(this, newPath, queryDevicePowerStatus, callback)); } @ServiceThreadOnly @@ -587,12 +598,9 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice { private boolean handleNewDeviceAtTheTailOfActivePath(int path) { // Seq #22 if (isTailOfActivePath(path, getActivePath())) { - removeAction(RoutingControlAction.class); int newPath = mService.portIdToPath(getActivePortId()); setActivePath(newPath); - mService.sendCecCommand(HdmiCecMessageBuilder.buildRoutingChange( - mAddress, getActivePath(), newPath)); - addAndStartAction(new RoutingControlAction(this, newPath, false, null)); + startRoutingControl(getActivePath(), newPath, false, null); return true; } return false; @@ -1346,12 +1354,8 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice { assertRunOnServiceThread(); // Seq #23 if (isTailOfActivePath(path, getActivePath())) { - removeAction(RoutingControlAction.class); int newPath = mService.portIdToPath(getActivePortId()); - mService.sendCecCommand(HdmiCecMessageBuilder.buildRoutingChange( - mAddress, getActivePath(), newPath)); - mActiveSource.invalidate(); - addAndStartAction(new RoutingControlAction(this, getActivePath(), true, null)); + startRoutingControl(getActivePath(), newPath, true, null); } } @@ -1367,13 +1371,9 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice { // Seq #24 if (getActivePortId() != Constants.INVALID_PORT_ID) { if (!routingForBootup && !isProhibitMode()) { - removeAction(RoutingControlAction.class); int newPath = mService.portIdToPath(getActivePortId()); setActivePath(newPath); - mService.sendCecCommand(HdmiCecMessageBuilder.buildRoutingChange(mAddress, - getActivePath(), newPath)); - addAndStartAction(new RoutingControlAction(this, getActivePortId(), - routingForBootup, null)); + startRoutingControl(getActivePath(), newPath, routingForBootup, null); } } else { int activePath = mService.getPhysicalAddress();