From 46350382ee1974fd635d43c7273dc44854edf7c7 Mon Sep 17 00:00:00 2001 From: Yuncheol Heo Date: Wed, 3 Dec 2014 22:29:45 +0900 Subject: [PATCH] CEC: Introduce the retry for commands on the new device discovery. - ChromeCast needs some preparation time to work properly after it reboots. Bug: 18489614 Change-Id: I74ff05820c3bda84e2f042fb91bf510ab9444e55 --- .../server/hdmi/DeviceDiscoveryAction.java | 38 ++++++++++++------- .../com/android/server/hdmi/HdmiConfig.java | 4 ++ .../android/server/hdmi/NewDeviceAction.java | 31 ++++++++++++--- 3 files changed, 54 insertions(+), 19 deletions(-) diff --git a/services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java b/services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java index da404c4324a2a..97a6e850654b5 100644 --- a/services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java +++ b/services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java @@ -38,6 +38,7 @@ import java.util.List; *
  • Gather "OSD (display) name" of all acknowledge devices *
  • Gather "Vendor id" of all acknowledge devices * + * We attempt to get OSD name/vendor ID up to 5 times in case the communication fails. */ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { private static final String TAG = "DeviceDiscoveryAction"; @@ -87,6 +88,7 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { private final ArrayList mDevices = new ArrayList<>(); private final DeviceDiscoveryCallback mCallback; private int mProcessedDeviceCount = 0; + private int mTimeoutRetry = 0; /** * Constructor. @@ -309,6 +311,7 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { private void increaseProcessedDeviceCount() { mProcessedDeviceCount++; + mTimeoutRetry = 0; } private void removeDevice(int index) { @@ -353,19 +356,23 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { return; } } else { - int address = mDevices.get(mProcessedDeviceCount).mLogicalAddress; - switch (mState) { - case STATE_WAITING_FOR_PHYSICAL_ADDRESS: - queryPhysicalAddress(address); - return; - case STATE_WAITING_FOR_OSD_NAME: - queryOsdName(address); - return; - case STATE_WAITING_FOR_VENDOR_ID: - queryVendorId(address); - default: - return; - } + sendQueryCommand(); + } + } + + private void sendQueryCommand() { + int address = mDevices.get(mProcessedDeviceCount).mLogicalAddress; + switch (mState) { + case STATE_WAITING_FOR_PHYSICAL_ADDRESS: + queryPhysicalAddress(address); + return; + case STATE_WAITING_FOR_OSD_NAME: + queryOsdName(address); + return; + case STATE_WAITING_FOR_VENDOR_ID: + queryVendorId(address); + default: + return; } } @@ -375,6 +382,11 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { return; } + if (++mTimeoutRetry < HdmiConfig.TIMEOUT_RETRY) { + sendQueryCommand(); + return; + } + mTimeoutRetry = 0; Slog.v(TAG, "Timeout[State=" + mState + ", Processed=" + mProcessedDeviceCount); removeDevice(mProcessedDeviceCount); checkAndProceedStage(); diff --git a/services/core/java/com/android/server/hdmi/HdmiConfig.java b/services/core/java/com/android/server/hdmi/HdmiConfig.java index 046f393a07567..a787c12311567 100644 --- a/services/core/java/com/android/server/hdmi/HdmiConfig.java +++ b/services/core/java/com/android/server/hdmi/HdmiConfig.java @@ -39,6 +39,10 @@ final class HdmiConfig { // Number of retries for polling each device in address allocation mechanism. static final int ADDRESS_ALLOCATION_RETRY = 3; + // Number of retries for sendCommand in actions related to new device discovery. + // Number 5 comes from 10 seconds for Chromecast preparation time. + static final int TIMEOUT_RETRY = 5; + // CEC spec said that it should try retransmission at least once. // The actual number of send request for a single command will be at most // RETRANSMISSION_COUNT + 1. Note that it affects only to normal commands diff --git a/services/core/java/com/android/server/hdmi/NewDeviceAction.java b/services/core/java/com/android/server/hdmi/NewDeviceAction.java index 64f0703394053..3d64cc52f5192 100644 --- a/services/core/java/com/android/server/hdmi/NewDeviceAction.java +++ b/services/core/java/com/android/server/hdmi/NewDeviceAction.java @@ -51,6 +51,7 @@ final class NewDeviceAction extends HdmiCecFeatureAction { private int mVendorId; private String mDisplayName; + private int mTimeoutRetry; /** * Constructor. @@ -71,15 +72,22 @@ final class NewDeviceAction extends HdmiCecFeatureAction { @Override public boolean start() { + requestOsdName(true); + return true; + } + + private void requestOsdName(boolean firstTry) { + if (firstTry) { + mTimeoutRetry = 0; + } mState = STATE_WAITING_FOR_SET_OSD_NAME; if (mayProcessCommandIfCached(mDeviceLogicalAddress, Constants.MESSAGE_SET_OSD_NAME)) { - return true; + return; } sendCommand(HdmiCecMessageBuilder.buildGiveOsdNameCommand(getSourceAddress(), mDeviceLogicalAddress)); addTimer(mState, HdmiConfig.TIMEOUT_MS); - return true; } @Override @@ -103,12 +111,12 @@ final class NewDeviceAction extends HdmiCecFeatureAction { } catch (UnsupportedEncodingException e) { Slog.e(TAG, "Failed to get OSD name: " + e.getMessage()); } - requestVendorId(); + requestVendorId(true); return true; } else if (opcode == Constants.MESSAGE_FEATURE_ABORT) { int requestOpcode = params[0] & 0xFF; if (requestOpcode == Constants.MESSAGE_GIVE_OSD_NAME) { - requestVendorId(); + requestVendorId(true); return true; } } @@ -138,7 +146,10 @@ final class NewDeviceAction extends HdmiCecFeatureAction { return false; } - private void requestVendorId() { + private void requestVendorId(boolean firstTry) { + if (firstTry) { + mTimeoutRetry = 0; + } // At first, transit to waiting status for . mState = STATE_WAITING_FOR_DEVICE_VENDOR_ID; // If the message is already in cache, process it. @@ -176,9 +187,17 @@ final class NewDeviceAction extends HdmiCecFeatureAction { return; } if (state == STATE_WAITING_FOR_SET_OSD_NAME) { + if (++mTimeoutRetry < HdmiConfig.TIMEOUT_RETRY) { + requestOsdName(false); + return; + } // Osd name request timed out. Try vendor id - requestVendorId(); + requestVendorId(true); } else if (state == STATE_WAITING_FOR_DEVICE_VENDOR_ID) { + if (++mTimeoutRetry < HdmiConfig.TIMEOUT_RETRY) { + requestVendorId(false); + return; + } // vendor id timed out. Go ahead creating the device info what we've got so far. addDeviceInfo(); finish();