diff options
| author | Jinsuk Kim <jinsukkim@google.com> | 2014-12-08 19:11:58 +0000 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2014-12-08 19:11:58 +0000 |
| commit | 3f771d879cb75a4d8e3b1a2d98f02f76c16cccd1 (patch) | |
| tree | daa5a0abe17a03b7e6d24b749257118939dba880 | |
| parent | 7039f6b423d2795eea6bebc932c9cb0d8422de88 (diff) | |
| parent | d1133ba8855199b34c22b369f34c987a14c68b85 (diff) | |
| download | frameworks_base-3f771d879cb75a4d8e3b1a2d98f02f76c16cccd1.zip frameworks_base-3f771d879cb75a4d8e3b1a2d98f02f76c16cccd1.tar.gz frameworks_base-3f771d879cb75a4d8e3b1a2d98f02f76c16cccd1.tar.bz2 | |
am d1133ba8: am 60747974: Merge "CEC: Introduce the retry for commands on the new device discovery." into lmp-mr1-dev
* commit 'd1133ba8855199b34c22b369f34c987a14c68b85':
CEC: Introduce the retry for commands on the new device discovery.
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 da404c4..97a6e85 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; * <li>Gather "OSD (display) name" of all acknowledge devices * <li>Gather "Vendor id" of all acknowledge devices * </ol> + * 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<DeviceInfo> 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 046f393..a787c12 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 64f0703..3d64cc5 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 <Device Vendor Id>. 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(); |
