Merge "Handle TODO in SystemAudioActionFromTv."

This commit is contained in:
Yuncheol Heo
2014-07-11 23:10:56 +00:00
committed by Android (Google) Code Review
8 changed files with 68 additions and 12 deletions

View File

@@ -18,11 +18,13 @@ package com.android.server.hdmi;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Pair;
import android.util.Slog;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.hdmi.HdmiControlService.DevicePollingCallback;
import java.util.ArrayList;
import java.util.List;
/**
@@ -59,6 +61,8 @@ abstract class FeatureAction {
// Timer that manages timeout events.
protected ActionTimer mActionTimer;
private ArrayList<Pair<FeatureAction, Runnable>> mOnFinishedCallbacks;
FeatureAction(HdmiCecLocalDevice source) {
mSource = source;
mService = mSource.getService();
@@ -220,8 +224,22 @@ abstract class FeatureAction {
* Finish up the action. Reset the state, and remove itself from the action queue.
*/
protected void finish() {
finish(true);
}
void finish(boolean removeSelf) {
clear();
removeAction(this);
if (removeSelf) {
removeAction(this);
}
if (mOnFinishedCallbacks != null) {
for (Pair<FeatureAction, Runnable> actionCallbackPair: mOnFinishedCallbacks) {
if (actionCallbackPair.first.mState != STATE_NONE) {
actionCallbackPair.second.run();
}
}
mOnFinishedCallbacks = null;
}
}
protected final HdmiCecLocalDevice localDevice() {
@@ -244,10 +262,17 @@ abstract class FeatureAction {
return mSource.getDeviceInfo().getPhysicalAddress();
}
protected void sendUserControlPressedAndReleased(int targetAddress, int uiCommand) {
protected final void sendUserControlPressedAndReleased(int targetAddress, int uiCommand) {
sendCommand(HdmiCecMessageBuilder.buildUserControlPressed(
getSourceAddress(), targetAddress, uiCommand));
sendCommand(HdmiCecMessageBuilder.buildUserControlReleased(
getSourceAddress(), targetAddress));
}
protected final void addOnFinishedCallback(FeatureAction action, Runnable runnable) {
if (mOnFinishedCallbacks == null) {
mOnFinishedCallbacks = new ArrayList<>();
}
mOnFinishedCallbacks.add(Pair.create(action, runnable));
}
}

View File

@@ -65,7 +65,7 @@ abstract class HdmiCecLocalDevice {
// Note that access to this collection should happen in service thread.
private final LinkedList<FeatureAction> mActions = new LinkedList<>();
private Handler mHandler = new Handler () {
private final Handler mHandler = new Handler () {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
@@ -482,6 +482,7 @@ abstract class HdmiCecLocalDevice {
@ServiceThreadOnly
void removeAction(final FeatureAction action) {
assertRunOnServiceThread();
action.finish(false);
mActions.remove(action);
checkIfPendingActionsCleared();
}
@@ -502,8 +503,8 @@ abstract class HdmiCecLocalDevice {
while (iter.hasNext()) {
FeatureAction action = iter.next();
if (action != exception && action.getClass().equals(clazz)) {
action.clear();
mActions.remove(action);
action.finish(false);
iter.remove();
}
}
checkIfPendingActionsCleared();
@@ -645,7 +646,7 @@ abstract class HdmiCecLocalDevice {
Iterator<FeatureAction> iter = mActions.iterator();
while (iter.hasNext()) {
FeatureAction action = iter.next();
action.finish();
action.finish(false);
iter.remove();
}
}

View File

@@ -537,10 +537,17 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
}
@ServiceThreadOnly
// Seq #32
void changeSystemAudioMode(boolean enabled, IHdmiControlCallback callback) {
assertRunOnServiceThread();
if (!mService.isControlEnabled() || hasAction(DeviceDiscoveryAction.class)) {
setSystemAudioMode(false, true);
invokeCallback(callback, HdmiControlManager.RESULT_INCORRECT_MODE);
return;
}
HdmiCecDeviceInfo avr = getAvrDeviceInfo();
if (avr == null) {
setSystemAudioMode(false, true);
invokeCallback(callback, HdmiControlManager.RESULT_TARGET_NOT_AVAILABLE);
return;
}

View File

@@ -219,7 +219,7 @@ final class HotplugDetectionAction extends FeatureAction {
return;
}
// Should ave only one Device Select Action
// Should have only one Device Select Action
DeviceSelectAction action = actions.get(0);
if (action.getTargetAddress() == address) {
removeAction(DeviceSelectAction.class);

View File

@@ -23,14 +23,20 @@ import android.hardware.hdmi.IHdmiControlCallback;
import android.os.RemoteException;
import android.util.Slog;
import java.util.List;
/**
* Base feature action class for SystemAudioActionFromTv and SystemAudioActionFromAvr.
*/
abstract class SystemAudioAction extends FeatureAction {
private static final String TAG = "SystemAudioAction";
// Transient state to differentiate with STATE_NONE where the on-finished callback
// will not be called.
private static final int STATE_CHECK_ROUTING_IN_PRGRESS = 1;
// State in which waits for <SetSystemAudioMode>.
private static final int STATE_WAIT_FOR_SET_SYSTEM_AUDIO_MODE = 1;
private static final int STATE_WAIT_FOR_SET_SYSTEM_AUDIO_MODE = 2;
private static final int MAX_SEND_RETRY_COUNT = 2;
@@ -65,7 +71,25 @@ abstract class SystemAudioAction extends FeatureAction {
mCallback = callback;
}
// Seq #27
protected void sendSystemAudioModeRequest() {
mState = STATE_CHECK_ROUTING_IN_PRGRESS;
List<RoutingControlAction> routingActions = getActions(RoutingControlAction.class);
if (!routingActions.isEmpty()) {
// Should have only one Routing Control Action
RoutingControlAction routingAction = routingActions.get(0);
routingAction.addOnFinishedCallback(this, new Runnable() {
@Override
public void run() {
sendSystemAudioModeRequestInternal();
}
});
return;
}
sendSystemAudioModeRequestInternal();
}
private void sendSystemAudioModeRequestInternal() {
int avrPhysicalAddress = tv().getAvrDeviceInfo().getPhysicalAddress();
HdmiCecMessage command = HdmiCecMessageBuilder.buildSystemAudioModeRequest(
getSourceAddress(),

View File

@@ -23,7 +23,7 @@ import android.hardware.hdmi.IHdmiControlCallback;
/**
* Feature action that handles System Audio initiated by AVR devices.
*/
// # Seq 33
// Seq #33
final class SystemAudioActionFromAvr extends SystemAudioAction {
/**
* Constructor

View File

@@ -24,6 +24,7 @@ import android.hardware.hdmi.IHdmiControlCallback;
* Feature action that handles System Audio initiated by TV devices.
*/
final class SystemAudioActionFromTv extends SystemAudioAction {
/**
* Constructor
*
@@ -41,9 +42,6 @@ final class SystemAudioActionFromTv extends SystemAudioAction {
@Override
boolean start() {
// TODO: Check HDMI-CEC is enabled.
// TODO: Move to the waiting state if currently a routing change is in progress.
removeSystemAudioActionInProgress();
sendSystemAudioModeRequest();
return true;

View File

@@ -21,6 +21,7 @@ import com.android.server.hdmi.HdmiControlService.SendMessageCallback;
/**
* Action to initiate system audio once AVR is detected on Device discovery action.
*/
// Seq #27
final class SystemAudioAutoInitiationAction extends FeatureAction {
private final int mAvrAddress;