[Galaxy S II Original Android Development] StevenHarperUK:
More on the Car Dock

Hi Again,

I think I have found more useful information on why the car dock is not working.

When I look in the WiredAccessoryObserver.java in the main framework, I see the definitions of the Audio devices

private static final String uEventInfo[][] = { {"DEVPATH=/devices/virtual/switch/h2w",
"/sys/class/switch/h2w/state",
"/sys/class/switch/h2w/name"},
{"DEVPATH=[B]/devices/virtual/switch/usb_audio[/B]",
"[B]/sys/class/switch/usb_audio/state[/B]",
"[B]/sys/class/switch/usb_audio/name[/B]"},
{"DEVPATH=/devices/virtual/switch/hdmi",
"/sys/class/switch/hdmi/state",
"/sys/class/switch/hdmi/name"} };

and further down some code to deal with the state

private synchronized final void updateState(String name, int state)
{
if (name.equals("[B]usb_audio[/B]")) {
switchState = ((mHeadsetState & (BIT_HEADSET|BIT_HEADSET_NO_MIC|BIT_HDMI_AUDIO)) |
((state == 1) ? BIT_USB_HEADSET_ANLG :
((state == 2) ? BIT_USB_HEADSET_DGTL : 0)));
}

When I look here on my device - I can see that there is no usb_audio so this could be my problem.

shell@android:/sys/class/switch # ls -la
lrwxrwxrwx root root 2012-03-24 11:42 dock -> ../../devices/virtual/switch/dock
lrwxrwxrwx root root 2012-03-24 11:42 h2w -> ../../devices/virtual/switch/h2w
lrwxrwxrwx root root 2012-03-24 11:40 hdmi -> ../../devices/virtual/switch/hdmi
lrwxrwxrwx root root 2012-03-24 11:51 send_end -> ../../devices/virtual/switch/send_end

So what I tried is a hack, but I re-named all the references to usb_audio in the WiredAccessoryObserver to "dock"

After a install and reboot, now when I plug the dock in - the Audio that is playing stops coming out of the phones internal speaker - Progress!

However no-sound out of the usb headphones.

If I plug into the normal headphones jack I get sound, when I undock I get normal speaker sound too.

After looking at the logcat - it could be that my previous hacks are causing some badness - I am reverting them now to see if that gives me usb audio.

---------- Post added at 02:49 PM ---------- Previous post was at 02:01 PM ----------

Just leaving the hack to point at /sys/class/switch/dock (instead of /sys/class/switch/usb_audio) didn't work.

I think I am close to this being a dead-end for me as I lack the knowledge to track it further.

Here is a logcat of when I push play on the music player and get a nice ALSA write error.

Here is the logcat of when I plug the DOCK in .

It feels really close to working - the 2nd logcat linked here shows that the correct intent IS being fired now, and that the Yamaha CManager is getting the setDevices(devices=00001000h) with the device set as 1000. I do not know enough about audio (yet) and drivers to get any more done here.

V/AudioService( 2030): Broadcast Receiver: Got action = [B]android.intent.action.USB_DGTL_HEADSET_PLUG[/B]
V/AudioService( 2030): Broadcast Receiver: Got [B]ACTION_USB_DGTL_HEADSET_PLUG[/B], state = 1
[B]I/AudioPolicyManager( 1866): setDeviceConnectionState() device: 1000, state 1, address [/B]
I/AudioPolicyManager( 1866): getDeviceForStrategy() strategy 0, device 1000
I/AudioPolicyManager( 1866): getDeviceForStrategy() strategy 4, device 2
I/AudioPolicyManager( 1866): getDeviceForStrategy() strategy 1, device 1
I/AudioPolicyManager( 1866): getDeviceForStrategy() strategy 2, device 1002
I/AudioPolicyManager( 1866): getDeviceForStrategy() strategy 0, device 1000
I/AudioPolicyManager( 1866): getDeviceForStrategy() strategy 0, device 1000
I/AudioPolicyManager( 1866): getDeviceForStrategy() strategy 3, device 1000
I/AudioPolicyManager( 1866): getDeviceForStrategy() strategy 0, device 1000
I/AudioPolicyManager( 1866): getDeviceForStrategy() strategy 1, device 1
I/AudioPolicyManager( 1866): getDeviceForStrategy() strategy 2, device 1002
I/AudioPolicyManager( 1866): getDeviceForStrategy() strategy 0, device 1000
I/AudioPolicyManager( 1866): getDeviceForStrategy() strategy 3, device 1000
I/AudioPolicyManager( 1866): getDeviceForStrategy() strategy 4, device 2
D/AudioSystem( 1866): android::AudioSystem::isSeparatedStream(audio_stream_type_t) called!
D/AudioSystem( 1866): audio_stream_type_t: 0
D/AudioSystem( 1866): isSeparatedStream: false
D/AudioSystem( 1866): android::AudioSystem::isSeparatedStream(audio_stream_type_t) called!
D/AudioSystem( 1866): audio_stream_type_t: 1
D/AudioSystem( 1866): isSeparatedStream: false
D/AudioSystem( 1866): android::AudioSystem::isSeparatedStream(audio_stream_type_t) called!
D/AudioSystem( 1866): audio_stream_type_t: 2
D/AudioSystem( 1866): isSeparatedStream: false
D/AudioSystem( 1866): android::AudioSystem::isSeparatedStream(audio_stream_type_t) called!
D/AudioSystem( 1866): audio_stream_type_t: 3
D/AudioSystem( 1866): isSeparatedStream: false
D/AudioSystem( 1866): android::AudioSystem::isSeparatedStream(audio_stream_type_t) called!
D/AudioSystem( 1866): audio_stream_type_t: 4
D/AudioSystem( 1866): isSeparatedStream: false
D/AudioSystem( 1866): android::AudioSystem::isSeparatedStream(audio_stream_type_t) called!
D/AudioSystem( 1866): audio_stream_type_t: 5
D/AudioSystem( 1866): isSeparatedStream: false
D/AudioSystem( 1866): android::AudioSystem::isSeparatedStream(audio_stream_type_t) called!
D/AudioSystem( 1866): audio_stream_type_t: 6
D/AudioSystem( 1866): isSeparatedStream: false
D/AudioSystem( 1866): android::AudioSystem::isSeparatedStream(audio_stream_type_t) called!
D/AudioSystem( 1866): audio_stream_type_t: 7
D/AudioSystem( 1866): isSeparatedStream: false
D/AudioSystem( 1866): android::AudioSystem::isSeparatedStream(audio_stream_type_t) called!
D/AudioSystem( 1866): audio_stream_type_t: 8
D/AudioSystem( 1866): isSeparatedStream: false
D/AudioSystem( 1866): android::AudioSystem::isSeparatedStream(audio_stream_type_t) called!
D/AudioSystem( 1866): audio_stream_type_t: 9
D/AudioSystem( 1866): isSeparatedStream: false
D/AudioSystem( 1866): android::AudioSystem::isSeparatedStream(audio_stream_type_t) called!
D/AudioSystem( 1866): audio_stream_type_t: 10
D/AudioSystem( 1866): isSeparatedStream: false
D/AudioSystem( 1866): android::AudioSystem::isSeparatedStream(audio_stream_type_t) called!
D/AudioSystem( 1866): audio_stream_type_t: 11
D/AudioSystem( 1866): isSeparatedStream: false
D/AudioSystem( 1866): android::AudioSystem::isSeparatedStream(audio_stream_type_t) called!
D/AudioSystem( 1866): audio_stream_type_t: 12
D/AudioSystem( 1866): isSeparatedStream: false
D/AudioSystem( 1866): android::AudioSystem::isSeparatedStream(audio_stream_type_t) called!
D/AudioSystem( 1866): audio_stream_type_t: 13
D/AudioSystem( 1866): isSeparatedStream: false
D/AudioSystem( 1866): android::AudioSystem::isSeparatedStream(audio_stream_type_t) called!
D/AudioSystem( 1866): audio_stream_type_t: 14
D/AudioSystem( 1866): isSeparatedStream: false
[B]I/AudioHardwareYamaha( 1866): AudioHardware::setDevices(devices=00001000h, mask=00023FFFh)
V/yamaha::media::CManager( 1866): setDevices(devices=00001000h)[/B]