Skip to content

Commit

Permalink
Add Dock USB Audio Support for Samsung Car / Desk Docks 1 of 2.
Browse files Browse the repository at this point in the history
Ported from CM10, original patch: http://review.cyanogenmod.com/20586

Also includes patches:
DockAudio: Always route audio back to normal on undock.
http://review.cyanogenmod.org/24830

Bugfix: Dock events can have state greater than 1
http://review.cyanogenmod.org/24995

------------------------------------------------------

Samsung docks have a non-sensing USB adio port.
Samsung get around this by having a separate Setting to route the Audio
The Changes made will only add the extra Observer if the Kernel supports the endpoint

  /sys/class/switch/dock/state

A new BroadcastReciever (SettingsChangedReceiver) is used to watch out for users changing the
Preference

The choice is made in the GalaxyS2Settings.apk (see 2 of 2)

  device/samsung/i9100/DeviceSettings/src/com/cyanogenmod/settings/device/DockFragmentActivity.java

After OnBootComplete and when the checkbox is changed, an Intent is triggered to this class.

When a Dock Event is caught if it is one the Samsung endpoint "dock" then if the users preference is
checked,
then the event is allowed to go on and route the audio.  If it is not checked then it is ignored.

Change-Id: I8e8f5001d5c651b07bb6af496bbf806732be21fa
  • Loading branch information
StevenHarperUK authored and bbelos committed Dec 13, 2012
1 parent 0e7cfa1 commit b38c33c
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions services/java/com/android/server/WiredAccessoryManager.java
Expand Up @@ -79,6 +79,8 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {

private int mSwitchValues;

private boolean dockAudioEnabled = false;

private final WiredAccessoryObserver mObserver;
private final InputManagerService mInputManager;

Expand All @@ -96,6 +98,12 @@ public WiredAccessoryManager(Context context, InputManagerService inputManager)

mObserver = new WiredAccessoryObserver();

File f = new File("/sys/class/switch/dock/state");
if (f!=null && f.exists()) {
// Listen out for changes to the Dock Audio Settings
context.registerReceiver(new SettingsChangedReceiver(),
new IntentFilter("com.cyanogenmod.settings.SamsungDock"), null, null);
}
context.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context ctx, Intent intent) {
Expand All @@ -105,6 +113,23 @@ public void onReceive(Context ctx, Intent intent) {
new IntentFilter(Intent.ACTION_BOOT_COMPLETED), null, null);
}

private final class SettingsChangedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
Slog.e(TAG, "Recieved a Settings Changed Action " + action);
if (action.equals("com.cyanogenmod.settings.SamsungDock")) {
String data = intent.getStringExtra("data");
Slog.e(TAG, "Recieved a Dock Audio change " + data);
if (data != null && data.equals("1")) {
dockAudioEnabled = true;
} else {
dockAudioEnabled = false;
}
}
}
}

private void bootCompleted() {
if (mUseDevInputEventForAudioJack) {
int switchValues = 0;
Expand Down Expand Up @@ -315,8 +340,10 @@ void init() {
}

// At any given time accessories could be inserted
// one on the board, one on the dock and one on HDMI:
// observe three UEVENTs
// one on the board, one on the dock, one on the
// samsung dock and one on HDMI:
// observe all UEVENTs that have valid switch supported
// by the Kernel
for (int i = 0; i < mUEventInfo.size(); ++i) {
UEventInfo uei = mUEventInfo.get(i);
startObserving("DEVPATH="+uei.getDevPath());
Expand Down Expand Up @@ -345,6 +372,14 @@ private List<UEventInfo> makeObservedUEventList() {
Slog.w(TAG, "This kernel does not have usb audio support");
}

// Monitor Samsung USB audio
uei = new UEventInfo("dock", BIT_USB_HEADSET_DGTL, BIT_USB_HEADSET_ANLG);
if (uei.checkSwitchExists()) {
retVal.add(uei);
} else {
Slog.w(TAG, "This kernel does not have samsung usb dock audio support");
}

// Monitor HDMI
//
// If the kernel has support for the "hdmi_audio" switch, use that. It will be
Expand Down Expand Up @@ -372,10 +407,20 @@ private List<UEventInfo> makeObservedUEventList() {
public void onUEvent(UEventObserver.UEvent event) {
if (LOG) Slog.v(TAG, "Headset UEVENT: " + event.toString());

int state = Integer.parseInt(event.get("SWITCH_STATE"));
try {
String devPath = event.get("DEVPATH");
String name = event.get("SWITCH_NAME");
int state = Integer.parseInt(event.get("SWITCH_STATE"));
if (name.equals("dock")) {
// Samsung USB Audio Jack is non-sensing - so must be enabled manually
// The choice is made in the GalaxyS2Settings.apk
// device/samsung/i9100/DeviceSettings/src/com/cyanogenmod/settings/device/DockFragmentActivity.java
// This sends an Intent to this class
if ((!dockAudioEnabled) && (state > 0)) {
Slog.e(TAG, "Ignoring dock event as Audio routing disabled " + event);
return;
}
}
synchronized (mLock) {
updateStateLocked(devPath, name, state);
}
Expand Down

0 comments on commit b38c33c

Please sign in to comment.