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 "OSD (display) name" of all acknowledge devices
|
||||||
* <li>Gather "Vendor id" of all acknowledge devices
|
* <li>Gather "Vendor id" of all acknowledge devices
|
||||||
* </ol>
|
* </ol>
|
||||||
|
* We attempt to get OSD name/vendor ID up to 5 times in case the communication fails.
|
||||||
*/
|
*/
|
||||||
final class DeviceDiscoveryAction extends HdmiCecFeatureAction {
|
final class DeviceDiscoveryAction extends HdmiCecFeatureAction {
|
||||||
private static final String TAG = "DeviceDiscoveryAction";
|
private static final String TAG = "DeviceDiscoveryAction";
|
||||||
@@ -87,6 +88,7 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction {
|
|||||||
private final ArrayList<DeviceInfo> mDevices = new ArrayList<>();
|
private final ArrayList<DeviceInfo> mDevices = new ArrayList<>();
|
||||||
private final DeviceDiscoveryCallback mCallback;
|
private final DeviceDiscoveryCallback mCallback;
|
||||||
private int mProcessedDeviceCount = 0;
|
private int mProcessedDeviceCount = 0;
|
||||||
|
private int mTimeoutRetry = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -309,6 +311,7 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction {
|
|||||||
|
|
||||||
private void increaseProcessedDeviceCount() {
|
private void increaseProcessedDeviceCount() {
|
||||||
mProcessedDeviceCount++;
|
mProcessedDeviceCount++;
|
||||||
|
mTimeoutRetry = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeDevice(int index) {
|
private void removeDevice(int index) {
|
||||||
@@ -353,19 +356,23 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int address = mDevices.get(mProcessedDeviceCount).mLogicalAddress;
|
sendQueryCommand();
|
||||||
switch (mState) {
|
}
|
||||||
case STATE_WAITING_FOR_PHYSICAL_ADDRESS:
|
}
|
||||||
queryPhysicalAddress(address);
|
|
||||||
return;
|
private void sendQueryCommand() {
|
||||||
case STATE_WAITING_FOR_OSD_NAME:
|
int address = mDevices.get(mProcessedDeviceCount).mLogicalAddress;
|
||||||
queryOsdName(address);
|
switch (mState) {
|
||||||
return;
|
case STATE_WAITING_FOR_PHYSICAL_ADDRESS:
|
||||||
case STATE_WAITING_FOR_VENDOR_ID:
|
queryPhysicalAddress(address);
|
||||||
queryVendorId(address);
|
return;
|
||||||
default:
|
case STATE_WAITING_FOR_OSD_NAME:
|
||||||
return;
|
queryOsdName(address);
|
||||||
}
|
return;
|
||||||
|
case STATE_WAITING_FOR_VENDOR_ID:
|
||||||
|
queryVendorId(address);
|
||||||
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,6 +382,11 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (++mTimeoutRetry < HdmiConfig.TIMEOUT_RETRY) {
|
||||||
|
sendQueryCommand();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mTimeoutRetry = 0;
|
||||||
Slog.v(TAG, "Timeout[State=" + mState + ", Processed=" + mProcessedDeviceCount);
|
Slog.v(TAG, "Timeout[State=" + mState + ", Processed=" + mProcessedDeviceCount);
|
||||||
removeDevice(mProcessedDeviceCount);
|
removeDevice(mProcessedDeviceCount);
|
||||||
checkAndProceedStage();
|
checkAndProceedStage();
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ final class HdmiConfig {
|
|||||||
// Number of retries for polling each device in address allocation mechanism.
|
// Number of retries for polling each device in address allocation mechanism.
|
||||||
static final int ADDRESS_ALLOCATION_RETRY = 3;
|
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.
|
// 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
|
// 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
|
// RETRANSMISSION_COUNT + 1. Note that it affects only to normal commands
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ final class NewDeviceAction extends HdmiCecFeatureAction {
|
|||||||
|
|
||||||
private int mVendorId;
|
private int mVendorId;
|
||||||
private String mDisplayName;
|
private String mDisplayName;
|
||||||
|
private int mTimeoutRetry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -71,15 +72,22 @@ final class NewDeviceAction extends HdmiCecFeatureAction {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean start() {
|
public boolean start() {
|
||||||
|
requestOsdName(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void requestOsdName(boolean firstTry) {
|
||||||
|
if (firstTry) {
|
||||||
|
mTimeoutRetry = 0;
|
||||||
|
}
|
||||||
mState = STATE_WAITING_FOR_SET_OSD_NAME;
|
mState = STATE_WAITING_FOR_SET_OSD_NAME;
|
||||||
if (mayProcessCommandIfCached(mDeviceLogicalAddress, Constants.MESSAGE_SET_OSD_NAME)) {
|
if (mayProcessCommandIfCached(mDeviceLogicalAddress, Constants.MESSAGE_SET_OSD_NAME)) {
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendCommand(HdmiCecMessageBuilder.buildGiveOsdNameCommand(getSourceAddress(),
|
sendCommand(HdmiCecMessageBuilder.buildGiveOsdNameCommand(getSourceAddress(),
|
||||||
mDeviceLogicalAddress));
|
mDeviceLogicalAddress));
|
||||||
addTimer(mState, HdmiConfig.TIMEOUT_MS);
|
addTimer(mState, HdmiConfig.TIMEOUT_MS);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -103,12 +111,12 @@ final class NewDeviceAction extends HdmiCecFeatureAction {
|
|||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
Slog.e(TAG, "Failed to get OSD name: " + e.getMessage());
|
Slog.e(TAG, "Failed to get OSD name: " + e.getMessage());
|
||||||
}
|
}
|
||||||
requestVendorId();
|
requestVendorId(true);
|
||||||
return true;
|
return true;
|
||||||
} else if (opcode == Constants.MESSAGE_FEATURE_ABORT) {
|
} else if (opcode == Constants.MESSAGE_FEATURE_ABORT) {
|
||||||
int requestOpcode = params[0] & 0xFF;
|
int requestOpcode = params[0] & 0xFF;
|
||||||
if (requestOpcode == Constants.MESSAGE_GIVE_OSD_NAME) {
|
if (requestOpcode == Constants.MESSAGE_GIVE_OSD_NAME) {
|
||||||
requestVendorId();
|
requestVendorId(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,7 +146,10 @@ final class NewDeviceAction extends HdmiCecFeatureAction {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void requestVendorId() {
|
private void requestVendorId(boolean firstTry) {
|
||||||
|
if (firstTry) {
|
||||||
|
mTimeoutRetry = 0;
|
||||||
|
}
|
||||||
// At first, transit to waiting status for <Device Vendor Id>.
|
// At first, transit to waiting status for <Device Vendor Id>.
|
||||||
mState = STATE_WAITING_FOR_DEVICE_VENDOR_ID;
|
mState = STATE_WAITING_FOR_DEVICE_VENDOR_ID;
|
||||||
// If the message is already in cache, process it.
|
// If the message is already in cache, process it.
|
||||||
@@ -176,9 +187,17 @@ final class NewDeviceAction extends HdmiCecFeatureAction {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (state == STATE_WAITING_FOR_SET_OSD_NAME) {
|
if (state == STATE_WAITING_FOR_SET_OSD_NAME) {
|
||||||
|
if (++mTimeoutRetry < HdmiConfig.TIMEOUT_RETRY) {
|
||||||
|
requestOsdName(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Osd name request timed out. Try vendor id
|
// Osd name request timed out. Try vendor id
|
||||||
requestVendorId();
|
requestVendorId(true);
|
||||||
} else if (state == STATE_WAITING_FOR_DEVICE_VENDOR_ID) {
|
} 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.
|
// vendor id timed out. Go ahead creating the device info what we've got so far.
|
||||||
addDeviceInfo();
|
addDeviceInfo();
|
||||||
finish();
|
finish();
|
||||||
|
|||||||
Reference in New Issue
Block a user