Merge "CEC: Introduce the retry for commands on the new device discovery." into lmp-mr1-dev
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user