From 01711c113881f0416751c4dcaa936800656a75c2 Mon Sep 17 00:00:00 2001 From: Nathalie Le Clair Date: Fri, 12 Mar 2021 16:12:50 +0100 Subject: [PATCH] Reduce calls for target power state Only look up the target power state for 2.0 devices. Bug: 182460328 Test: atest DeviceSelectActionTest and OneTouchPlayActionTest Change-Id: I2471d20e750ae37719d70ea3e0215fe6fae94c6a --- .../server/hdmi/DeviceSelectAction.java | 24 ++++++++++------- .../server/hdmi/OneTouchPlayAction.java | 27 +++++++++++-------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/services/core/java/com/android/server/hdmi/DeviceSelectAction.java b/services/core/java/com/android/server/hdmi/DeviceSelectAction.java index 947ee24f8e02c..f6828d129728e 100644 --- a/services/core/java/com/android/server/hdmi/DeviceSelectAction.java +++ b/services/core/java/com/android/server/hdmi/DeviceSelectAction.java @@ -100,18 +100,22 @@ final class DeviceSelectAction extends HdmiCecFeatureAction { // Wake-up on was not mandatory before CEC 2.0. // The message is re-sent at the end of the action for devices that don't support 2.0. sendSetStreamPath(); - int targetPowerStatus = HdmiControlManager.POWER_STATUS_UNKNOWN; - HdmiDeviceInfo targetDevice = localDevice().mService.getHdmiCecNetwork().getCecDeviceInfo( - getTargetAddress()); - if (targetDevice != null) { - targetPowerStatus = targetDevice.getDevicePowerStatus(); - } - if (!mIsCec20 || targetPowerStatus == HdmiControlManager.POWER_STATUS_UNKNOWN) { + if (!mIsCec20) { queryDevicePowerStatus(); - } else if (targetPowerStatus == HdmiControlManager.POWER_STATUS_ON) { - finishWithCallback(HdmiControlManager.RESULT_SUCCESS); - return true; + } else { + int targetPowerStatus = HdmiControlManager.POWER_STATUS_UNKNOWN; + HdmiDeviceInfo targetDevice = localDevice().mService.getHdmiCecNetwork() + .getCecDeviceInfo(getTargetAddress()); + if (targetDevice != null) { + targetPowerStatus = targetDevice.getDevicePowerStatus(); + } + if (targetPowerStatus == HdmiControlManager.POWER_STATUS_UNKNOWN) { + queryDevicePowerStatus(); + } else if (targetPowerStatus == HdmiControlManager.POWER_STATUS_ON) { + finishWithCallback(HdmiControlManager.RESULT_SUCCESS); + return true; + } } mState = STATE_WAIT_FOR_REPORT_POWER_STATUS; addTimer(mState, HdmiConfig.TIMEOUT_MS); diff --git a/services/core/java/com/android/server/hdmi/OneTouchPlayAction.java b/services/core/java/com/android/server/hdmi/OneTouchPlayAction.java index 9d2db94cac8e0..979e7a452e431 100644 --- a/services/core/java/com/android/server/hdmi/OneTouchPlayAction.java +++ b/services/core/java/com/android/server/hdmi/OneTouchPlayAction.java @@ -89,7 +89,7 @@ final class OneTouchPlayAction extends HdmiCecFeatureAction { mSource = source(); sendCommand(HdmiCecMessageBuilder.buildTextViewOn(getSourceAddress(), mTargetAddress)); - boolean targetOnBefore = getTargetDevicePowerStatus(mSource, mTargetAddress, + boolean is20TargetOnBefore = mIsCec20 && getTargetDevicePowerStatus(mSource, mTargetAddress, HdmiControlManager.POWER_STATUS_UNKNOWN) == HdmiControlManager.POWER_STATUS_ON; broadcastActiveSource(); // If the device is not an audio system itself, request the connected audio system to @@ -98,18 +98,23 @@ final class OneTouchPlayAction extends HdmiCecFeatureAction { sendCommand(HdmiCecMessageBuilder.buildSystemAudioModeRequest(getSourceAddress(), Constants.ADDR_AUDIO_SYSTEM, getSourcePath(), true)); } - int targetPowerStatus = getTargetDevicePowerStatus(mSource, mTargetAddress, - HdmiControlManager.POWER_STATUS_UNKNOWN); - if (!mIsCec20 || targetPowerStatus == HdmiControlManager.POWER_STATUS_UNKNOWN) { + + if (!mIsCec20) { queryDevicePowerStatus(); - } else if (targetPowerStatus == HdmiControlManager.POWER_STATUS_ON) { - if (!targetOnBefore) { - // Suppress 2nd message if the target device was already on when - // the 1st one was sent. - broadcastActiveSource(); + } else { + int targetPowerStatus = getTargetDevicePowerStatus(mSource, mTargetAddress, + HdmiControlManager.POWER_STATUS_UNKNOWN); + if (targetPowerStatus == HdmiControlManager.POWER_STATUS_UNKNOWN) { + queryDevicePowerStatus(); + } else if (targetPowerStatus == HdmiControlManager.POWER_STATUS_ON) { + if (!is20TargetOnBefore) { + // Suppress 2nd message if the target device was already on when + // the 1st one was sent. + broadcastActiveSource(); + } + finishWithCallback(HdmiControlManager.RESULT_SUCCESS); + return true; } - finishWithCallback(HdmiControlManager.RESULT_SUCCESS); - return true; } mState = STATE_WAITING_FOR_REPORT_POWER_STATUS; addTimer(mState, HdmiConfig.TIMEOUT_MS);