Introducing XDA:DevCon – A Conference For Developers By Developers
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
ksatta
Old
(Last edited by ksatta; 20th May 2011 at 03:29 PM.)
#1  
ksatta's Avatar
Senior Member - OP
Thanks Meter 77
Posts: 298
Join Date: Mar 2011
Location: Sieppijärvi
Default Trying to fix the bug with using headphones/line-out without mic [SOLVED]

The solution: http://forum.xda-developers.com/show...8&postcount=14

I'm trying to fix the bug that when using normal stereo headphones (without mic) or a 3.5mm jack -> 2xrca cable is used, the internal mic is disabled.

I've gotten so far that I have modified rpc_server_handset.c to set value of /sys/class/switch/h2w/state to 2 when headphones are inserted.

Now logcat shows:
Quote:
V/HeadsetObserver( 148): Intent.ACTION_HEADSET_PLUG: state: 1 name: ksatta headphones mic: 0
D/musicUtils( 829): wired_headset
E/AudioFlinger( 96): EQtype is 0, deviceType is 0
E/SRS_wowhd_binder( 96): startEqualizer EQtype is 0, deviceType is 0
E/SRS_wowhd_binder( 96): startEqualizer bSpeaker is 0
E/SRS_wowhd_binder( 96): equalizer1 EQtype = Default
Without the modifications logcat shows:
Quote:
V/HeadsetObserver( 149): Intent.ACTION_HEADSET_PLUG: state: 1 name: Headset mic: 1
D/musicUtils( 788): speaker
E/AudioFlinger( 96): EQtype is 0, deviceType is 2
E/SRS_wowhd_binder( 96): startEqualizer EQtype is 0, deviceType is 2
E/SRS_wowhd_binder( 96): startEqualizer bSpeaker is 1
E/SRS_wowhd_binder( 96): equalizer1 EQtype = Default
So the logs look like my mod is working correctly, however now I can't hear anything from the phone or headphones and also the internal mic is disabled. I've been trying to debug this further, but I can't find where the SRS_wowhd_binder, musicUtils and AudioFlinger logs are generated. Looks like huawei modified some other files than the kernel files, but they haven't released sources for those?

I've tried tags android-2.2.1_r2 and android-2.2.1_r1 from android.git.kernel.org, I found the line where "Intent.ACTION_HEADSET_PLUG: state:..." is logged from HeadsetObserver.java, but I haven't found the others.

Looking further into this..

Anyone have any ideas/suggestions?

edit: looks like Huawei has modified AudioService.class from framework.jar. AudioService handles ACTION_HEADSET_PLUG and and determines if a headset or headphone is connected. Next I think I'll try to decompile the classes and see what's been changed. Or then I'll just try to stick the git version of AudioService on the phone (I wonder what other consequences this'll have, AudioServer handles a bunch of other stuff too).

edit2: I decompiled the phone's AudioService class, it totally ignores the microphone=0 variable Jeez, I wonder why Huawei is cheaper than some others.. Oh well, it's possible to fix. Next step is to edit the decompiled AudioService class and see if that works. Progress

edit3: Actually looks the mic = 0 isn't ignored, the decompiled class just looks really funky. For example "while (true) { return; ...". Might be effects of the decompilation process. Investigating further. The problem might also be in the native libmedia.so

edit4: I found this: http://code.google.com/p/toggleheadset2/ It is used to set output and input to headset.
Might be easiest to fix using a similar way to set output to headphones/line-out and leave the internal mic on.. Looking into that now, I'll post here if I get it to work.
The Following User Says Thank You to ksatta For This Useful Post: [ Click to Expand ]
 
ryronz
Old
#2  
Senior Member
Thanks Meter 20
Posts: 145
Join Date: Feb 2011
Hey just a quick thing, I have absolutely no idea how easy or difficult it would be to do. But the phones seem to have a problem with headsets/headphones with the iPhone/Blackberry controls on them. It shorts and you can't hear much unless you're pressing the play/pause button.

AFAIK the ground/mic are switched round, but at least for the Samsung Galaxy S there is a kernal + rom out that fixes it so i'd imagine it was somewhat plausible with this phone too.

Don't necessarily need the buttons working (although they work with stock headphones, but meh) it'd just be nice to be able to using any type of headphones.
 
ksatta
Old
#3  
ksatta's Avatar
Senior Member - OP
Thanks Meter 77
Posts: 298
Join Date: Mar 2011
Location: Sieppijärvi
Quote:
Originally Posted by ryronz View Post
Hey just a quick thing, I have absolutely no idea how easy or difficult it would be to do. But the phones seem to have a problem with headsets/headphones with the iPhone/Blackberry controls on them. It shorts and you can't hear much unless you're pressing the play/pause button.

AFAIK the ground/mic are switched round, but at least for the Samsung Galaxy S there is a kernal + rom out that fixes it so i'd imagine it was somewhat plausible with this phone too.

Don't necessarily need the buttons working (although they work with stock headphones, but meh) it'd just be nice to be able to using any type of headphones.
I think this would have to be fixed from some other place in the kernel. I'm now trying to mod toggleheadset2 so that it sets the audio output to headphones and leaves the internal mic on. I think your suggestion could be accomplished probably by checking out what they changed in the Samsung Galaxy kernel and doing the same changes.
 
Piron
Old
#4  
Piron's Avatar
Member
Thanks Meter 3
Posts: 77
Join Date: Dec 2007
Location: Szczecin
in HTC devices do not have that problem. After connecting the headset microphone is working, one could see how it is set in the HTC. I have a headset phones that work with HTC and other companies. The X5 does not work and I get the impression that the reason is not software and the construction of the socket (While connecting).
XPERIA Z
 
ksatta
Old
#5  
ksatta's Avatar
Senior Member - OP
Thanks Meter 77
Posts: 298
Join Date: Mar 2011
Location: Sieppijärvi
Quote:
Originally Posted by Piron View Post
in HTC devices do not have that problem. After connecting the headset microphone is working, one could see how it is set in the HTC. I have a headset phones that work with HTC and other companies. The X5 does not work and I get the impression that the reason is not software and the construction of the socket (While connecting).
Yes, the Ideos X5 seems to detect headset connected even if it's headphones or line-out cable. You might be right that it's a hardware issue.

If I get my fix to work it'll just force the internal mic to stay on if headphones/headset is used. It's a workaround
 
ksatta
Old
#6  
ksatta's Avatar
Senior Member - OP
Thanks Meter 77
Posts: 298
Join Date: Mar 2011
Location: Sieppijärvi
OK. Some "progress"..

When headphones without mic are plugged in the Huawei sets DEVICE_OUT_WIRED_HEADSET to 1 and DEVICE_IN_MIC_ARRAY to 1

When I manually set only DEVICE_OUT_WIRED_HEADSET (even if headphones are not connected), the internal mic is disabled.

If I set both DEVICE_OUT_WIRED_HEADSET and DEVICE_IN_MIC_ARRAY to 0 after plugging the headphones, then the internal mic works, but the output goes to the earpiece..

Then I tried to set:
DEVICE_OUT_WIRED_HEADSET 0
DEVICE_IN_MIC_ARRAY 0
DEVICE_OUT_WIRED_HEADPHONE 1
Then the internal mic worked, but the output was routed to the phone's speaker (speakerphone mode)

I think the problem is in AudioSystem.cpp (part of libmedia.so), of which Huawei hasn't released the source.. Since they haven't modified AudioSystem.java (diffed that..).

There is something really different in there, maybe they have changed it so that always when _output_ is set to headset, input is set to "mic_array" or something... and setting output to headphones sets output to speaker etc etc..

I think I'll still try setting output to speaker (if headphone and speaker ids are switched).. Or then create my own native program which sets output to headphones..

Looks like the main routing is done in frameworks/base/libs/audioflinger/AudioPolicyManagerBase.cpp..

Oh well, I'll continue tomorrow
 
stockwell
Old
#7  
Recognized Developer
Thanks Meter 595
Posts: 375
Join Date: Mar 2007
Location: Brisbane

 
DONATE TO ME
Thanks for your efforts and for putting so much time into documenting the process.

I think if you can't find a simple solution the next step would be to try and get msm7k drivers with known source code working on our device, rather than spending time on guessing behaviours of a driver which we have no source for.

See the links below for the source for all of the msm7k drivers and a modified msm7x30 kernel from Kali. It might also be interesting to look at the Qualcomm sources to see how they have modified it (I think mostly it's just been changed to accommodate FM radio but there may be other changes).

https://github.com/Kali-/android_hardware_msm7k
https://github.com/Kali-/htc-kernel-msm7x30-exp

I will help with this when I can, but I am extremely busy at the moment with work and uni. Good luck!
 
ksatta
Old
#8  
ksatta's Avatar
Senior Member - OP
Thanks Meter 77
Posts: 298
Join Date: Mar 2011
Location: Sieppijärvi
Quote:
Originally Posted by stockwell View Post
Thanks for your efforts and for putting so much time into documenting the process.

I think if you can't find a simple solution the next step would be to try and get msm7k drivers with known source code working on our device, rather than spending time on guessing behaviours of a driver which we have no source for.

See the links below for the source for all of the msm7k drivers and a modified msm7x30 kernel from Kali. It might also be interesting to look at the Qualcomm sources to see how they have modified it (I think mostly it's just been changed to accommodate FM radio but there may be other changes).

https://github.com/Kali-/android_hardware_msm7k
https://github.com/Kali-/htc-kernel-msm7x30-exp

I will help with this when I can, but I am extremely busy at the moment with work and uni. Good luck!
Actually I was thinking the same thing, move on to something of which I have the full source code.

Thanks for the info, I'll look into that. Fixing this "little bug" turned out to be quite a time-consuming process, but I'm getting good experience on modifying android. Also if I one day get this fixed, it'll be awesome
 
ksatta
Old
(Last edited by ksatta; 19th May 2011 at 04:46 PM.)
#9  
ksatta's Avatar
Senior Member - OP
Thanks Meter 77
Posts: 298
Join Date: Mar 2011
Location: Sieppijärvi
Actually the source for the msm7x30 is in the huawei's kernel source from huaweidevice.com.

I think there are also some problems with the libaudio etc for which Huawei haven't released the source.

Thanks for pointing me in the right direction, I'll see if can modify the msm7x30 from huawei source so that the int. mic isn't disabled.

edit: Yeah, this looks like the place where the actual routing is done. Of course, it's the kernel driver for the sound.. Learning something new all the time
 
ksatta
Old
#10  
ksatta's Avatar
Senior Member - OP
Thanks Meter 77
Posts: 298
Join Date: Mar 2011
Location: Sieppijärvi
I managed to get some logs from msm7x30.c:
device handset_dual_mic_broadside_tx set 1
device handset_dual_mic_broadside_tx set 0

when plugging headphones in and taking them out..

Now I think I'm getting close. A good point to continue from tomorrow

 
Post Reply+
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Go to top of page...