Fix missing iteration policy on device discover action
Device polling requires both pick policy and pick iteration policy, however, device discovery action has no iteration policy. Along with fix, move send result and pick policy constants to HdmiConstants package Change-Id: Ibbcfdc482a189bbc3aa2c61143422541da78447d
This commit is contained in:
@@ -119,7 +119,8 @@ final class DeviceDiscoveryAction extends FeatureAction {
|
||||
allocateDevices(ackedAddress);
|
||||
startPhysicalAddressStage();
|
||||
}
|
||||
}, HdmiControlService.POLL_STRATEGY_REMOTES_DEVICES, DEVICE_POLLING_RETRY);
|
||||
}, HdmiConstants.POLL_ITERATION_REVERSE_ORDER
|
||||
| HdmiConstants.POLL_STRATEGY_REMOTES_DEVICES, DEVICE_POLLING_RETRY);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -366,29 +366,29 @@ final class HdmiCecController {
|
||||
}
|
||||
|
||||
private List<Integer> pickPollCandidates(int pickStrategy) {
|
||||
int strategy = pickStrategy & HdmiControlService.POLL_STRATEGY_MASK;
|
||||
int strategy = pickStrategy & HdmiConstants.POLL_STRATEGY_MASK;
|
||||
Predicate<Integer> pickPredicate = null;
|
||||
switch (strategy) {
|
||||
case HdmiControlService.POLL_STRATEGY_SYSTEM_AUDIO:
|
||||
case HdmiConstants.POLL_STRATEGY_SYSTEM_AUDIO:
|
||||
pickPredicate = mSystemAudioAddressPredicate;
|
||||
break;
|
||||
case HdmiControlService.POLL_STRATEGY_REMOTES_DEVICES:
|
||||
case HdmiConstants.POLL_STRATEGY_REMOTES_DEVICES:
|
||||
default: // The default is POLL_STRATEGY_REMOTES_DEVICES.
|
||||
pickPredicate = mRemoteDeviceAddressPredicate;
|
||||
break;
|
||||
}
|
||||
|
||||
int iterationStrategy = pickStrategy & HdmiControlService.POLL_ITERATION_STRATEGY_MASK;
|
||||
int iterationStrategy = pickStrategy & HdmiConstants.POLL_ITERATION_STRATEGY_MASK;
|
||||
ArrayList<Integer> pollingCandidates = new ArrayList<>();
|
||||
switch (iterationStrategy) {
|
||||
case HdmiControlService.POLL_ITERATION_IN_ORDER:
|
||||
case HdmiConstants.POLL_ITERATION_IN_ORDER:
|
||||
for (int i = HdmiCec.ADDR_TV; i <= HdmiCec.ADDR_SPECIFIC_USE; ++i) {
|
||||
if (pickPredicate.apply(i)) {
|
||||
pollingCandidates.add(i);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case HdmiControlService.POLL_ITERATION_REVERSE_ORDER:
|
||||
case HdmiConstants.POLL_ITERATION_REVERSE_ORDER:
|
||||
default: // The default is reverse order.
|
||||
for (int i = HdmiCec.ADDR_SPECIFIC_USE; i >= HdmiCec.ADDR_TV; --i) {
|
||||
if (pickPredicate.apply(i)) {
|
||||
@@ -442,7 +442,7 @@ final class HdmiCecController {
|
||||
// new logical address for the device because no device uses
|
||||
// it as logical address of the device.
|
||||
if (nativeSendCecCommand(mNativePtr, address, address, EMPTY_BODY)
|
||||
== HdmiControlService.SEND_RESULT_SUCCESS) {
|
||||
== HdmiConstants.SEND_RESULT_SUCCESS) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -509,7 +509,7 @@ final class HdmiCecController {
|
||||
byte[] body = buildBody(cecMessage.getOpcode(), cecMessage.getParams());
|
||||
final int error = nativeSendCecCommand(mNativePtr, cecMessage.getSource(),
|
||||
cecMessage.getDestination(), body);
|
||||
if (error != HdmiControlService.SEND_RESULT_SUCCESS) {
|
||||
if (error != HdmiConstants.SEND_RESULT_SUCCESS) {
|
||||
Slog.w(TAG, "Failed to send " + cecMessage);
|
||||
}
|
||||
if (callback != null) {
|
||||
|
||||
@@ -80,5 +80,20 @@ final class HdmiConstants {
|
||||
static final int INVALID_PORT_ID = -1;
|
||||
static final int INVALID_PHYSICAL_ADDRESS = 0xFFFF;
|
||||
|
||||
// Send result codes.
|
||||
static final int SEND_RESULT_SUCCESS = 0;
|
||||
static final int SEND_RESULT_NAK = -1;
|
||||
static final int SEND_RESULT_FAILURE = -2;
|
||||
|
||||
// Strategy for device polling.
|
||||
// Should use "OR(|) operation of POLL_STRATEGY_XXX and POLL_ITERATION_XXX.
|
||||
static final int POLL_STRATEGY_MASK = 0x3; // first and second bit.
|
||||
static final int POLL_STRATEGY_REMOTES_DEVICES = 0x1;
|
||||
static final int POLL_STRATEGY_SYSTEM_AUDIO = 0x2;
|
||||
|
||||
static final int POLL_ITERATION_STRATEGY_MASK = 0x30000; // first and second bit.
|
||||
static final int POLL_ITERATION_IN_ORDER = 0x10000;
|
||||
static final int POLL_ITERATION_REVERSE_ORDER = 0x20000;
|
||||
|
||||
private HdmiConstants() { /* cannot be instantiated */ }
|
||||
}
|
||||
|
||||
@@ -54,18 +54,6 @@ public final class HdmiControlService extends SystemService {
|
||||
// TODO: Rename the permission to HDMI_CONTROL.
|
||||
private static final String PERMISSION = "android.permission.HDMI_CEC";
|
||||
|
||||
static final int SEND_RESULT_SUCCESS = 0;
|
||||
static final int SEND_RESULT_NAK = -1;
|
||||
static final int SEND_RESULT_FAILURE = -2;
|
||||
|
||||
static final int POLL_STRATEGY_MASK = 0x3; // first and second bit.
|
||||
static final int POLL_STRATEGY_REMOTES_DEVICES = 0x1;
|
||||
static final int POLL_STRATEGY_SYSTEM_AUDIO = 0x2;
|
||||
|
||||
static final int POLL_ITERATION_STRATEGY_MASK = 0x30000; // first and second bit.
|
||||
static final int POLL_ITERATION_IN_ORDER = 0x10000;
|
||||
static final int POLL_ITERATION_REVERSE_ORDER = 0x20000;
|
||||
|
||||
/**
|
||||
* Interface to report send result.
|
||||
*/
|
||||
@@ -430,11 +418,11 @@ public final class HdmiControlService extends SystemService {
|
||||
}
|
||||
|
||||
private int checkPollStrategy(int pickStrategy) {
|
||||
int strategy = pickStrategy & POLL_STRATEGY_MASK;
|
||||
int strategy = pickStrategy & HdmiConstants.POLL_STRATEGY_MASK;
|
||||
if (strategy == 0) {
|
||||
throw new IllegalArgumentException("Invalid poll strategy:" + pickStrategy);
|
||||
}
|
||||
int iterationStrategy = pickStrategy & POLL_ITERATION_STRATEGY_MASK;
|
||||
int iterationStrategy = pickStrategy & HdmiConstants.POLL_ITERATION_STRATEGY_MASK;
|
||||
if (iterationStrategy == 0) {
|
||||
throw new IllegalArgumentException("Invalid iteration strategy:" + pickStrategy);
|
||||
}
|
||||
|
||||
@@ -125,8 +125,8 @@ final class HotplugDetectionAction extends FeatureAction {
|
||||
public void onPollingFinished(List<Integer> ackedAddress) {
|
||||
checkHotplug(ackedAddress, false);
|
||||
}
|
||||
}, HdmiControlService.POLL_ITERATION_IN_ORDER
|
||||
| HdmiControlService.POLL_STRATEGY_REMOTES_DEVICES, POLL_RETRY_COUNT);
|
||||
}, HdmiConstants.POLL_ITERATION_IN_ORDER
|
||||
| HdmiConstants.POLL_STRATEGY_REMOTES_DEVICES, POLL_RETRY_COUNT);
|
||||
}
|
||||
|
||||
private void pollAudioSystem() {
|
||||
@@ -137,8 +137,8 @@ final class HotplugDetectionAction extends FeatureAction {
|
||||
public void onPollingFinished(List<Integer> ackedAddress) {
|
||||
checkHotplug(ackedAddress, true);
|
||||
}
|
||||
}, HdmiControlService.POLL_ITERATION_IN_ORDER
|
||||
| HdmiControlService.POLL_STRATEGY_SYSTEM_AUDIO, POLL_RETRY_COUNT);
|
||||
}, HdmiConstants.POLL_ITERATION_IN_ORDER
|
||||
| HdmiConstants.POLL_STRATEGY_SYSTEM_AUDIO, POLL_RETRY_COUNT);
|
||||
}
|
||||
|
||||
private void checkHotplug(List<Integer> ackedAddress, boolean audioOnly) {
|
||||
|
||||
@@ -42,7 +42,7 @@ final class RequestArcInitiationAction extends RequestArcAction {
|
||||
sendCommand(command, new HdmiControlService.SendMessageCallback() {
|
||||
@Override
|
||||
public void onSendCompleted(int error) {
|
||||
if (error == HdmiControlService.SEND_RESULT_SUCCESS) {
|
||||
if (error == HdmiConstants.SEND_RESULT_SUCCESS) {
|
||||
mState = STATE_WATING_FOR_REQUEST_ARC_REQUEST_RESPONSE;
|
||||
addTimer(mState, TIMEOUT_MS);
|
||||
} else {
|
||||
|
||||
@@ -42,7 +42,7 @@ final class RequestArcTerminationAction extends RequestArcAction {
|
||||
sendCommand(command, new HdmiControlService.SendMessageCallback() {
|
||||
@Override
|
||||
public void onSendCompleted(int error) {
|
||||
if (error == HdmiControlService.SEND_RESULT_SUCCESS) {
|
||||
if (error == HdmiConstants.SEND_RESULT_SUCCESS) {
|
||||
mState = STATE_WATING_FOR_REQUEST_ARC_REQUEST_RESPONSE;
|
||||
addTimer(mState, TIMEOUT_MS);
|
||||
} else {
|
||||
|
||||
@@ -68,7 +68,7 @@ final class SetArcTransmissionStateAction extends FeatureAction {
|
||||
sendCommand(command, new HdmiControlService.SendMessageCallback() {
|
||||
@Override
|
||||
public void onSendCompleted(int error) {
|
||||
if (error == HdmiControlService.SEND_RESULT_SUCCESS) {
|
||||
if (error == HdmiConstants.SEND_RESULT_SUCCESS) {
|
||||
// Enable ARC status immediately after sending <Report Arc Initiated>.
|
||||
// If AVR responds with <Feature Abort>, disable ARC status again.
|
||||
// This is different from spec that says that turns ARC status to
|
||||
|
||||
@@ -67,7 +67,7 @@ abstract class SystemAudioAction extends FeatureAction {
|
||||
sendCommand(command, new HdmiControlService.SendMessageCallback() {
|
||||
@Override
|
||||
public void onSendCompleted(int error) {
|
||||
if (error == HdmiControlService.SEND_RESULT_SUCCESS) {
|
||||
if (error == HdmiConstants.SEND_RESULT_SUCCESS) {
|
||||
mState = STATE_WAIT_FOR_SET_SYSTEM_AUDIO_MODE;
|
||||
addTimer(mState, mTargetAudioStatus ? ON_TIMEOUT_MS : OFF_TIMEOUT_MS);
|
||||
} else {
|
||||
@@ -98,7 +98,7 @@ abstract class SystemAudioAction extends FeatureAction {
|
||||
sendCommand(command, new HdmiControlService.SendMessageCallback() {
|
||||
@Override
|
||||
public void onSendCompleted(int error) {
|
||||
if (error == HdmiControlService.SEND_RESULT_SUCCESS) {
|
||||
if (error == HdmiConstants.SEND_RESULT_SUCCESS) {
|
||||
mState = STATE_WAIT_FOR_REPORT_AUDIO_STATUS;
|
||||
addTimer(mState, TIMEOUT_MS);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user