Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[GUIDE] Take Back Your Headset Controls!

OP IAmAN00bie

17th November 2012, 05:54 AM   |  #1  
IAmAN00bie's Avatar
OP Senior Member
Thanks Meter: 344
 
619 posts
Join Date:Joined: Dec 2010
More
REQUIREMENTS
  • ROOT ACCESS
  • SINGLE-BUTTON HEADSET
  • ANDROID 4.1+

PREFACE

TESTED ON THE NEXUS 4 RUNNING 4.2

If you often listen to music using a single-button headset (the kind that many Samsung devices tend to ship with), then you should know that Google lets you control the headset button. By default, you can:
  • Play/Pause (Single Press)
  • Skip track (Double Press)
  • Launch Voice Search (Single-click Long Press)

Pretty cool, right? So what's the deal, then?

The issue is you CANNOT customize how you want the system to respond to your button input.
  • What if you want to long press to increase volume?
  • What if you want to triple click to go to the previous track?
  • What if you want to double click and hold to decrease volume?
  • What if you want to launch an app besides Google Voice Search (I personally have bound utter! in place of Google's search!)?

Nope, too bad.

Well, there is a workaround for this.

How does it work?

In /system/usr/keylayout, two files called Generic.kl and hs_detect.kl reside where you can modify the keymapping of the HEADSETHOOK input to an alternate key that is normally found on a 3-button headset, specifically MEDIA_NEXT. Then, you can modify how the system responds to MEDIA_NEXT by using a headset control app.

TO FIX:

**NOTE: ITEMS SURROUNDED BY A BLUE BOX MEAN IT IS THE ORIGINAL VALUE WHILE ITEMS SURROUNDED BY A RED BOX MEANS IT IS THE NEW VALUE**

1) Install the Keytest App found here: https://github.com/chrisboyle/keytest/downloads

2) Once inside the app, press the headset button. On your screen, it should read as follows:

Code:
keyCode=KEYCODE_HEATSETHOOK
scanCode=226
as shown in the following picture: http://i.imgur.com/dogxm.png


3) Using a root-enabled file explorer app (I personally use Solid Explorer), go to /system/usr/keylayout and make a backup of Generic.kl and hs_detect.kl (copying them to your internal storage, for example /sdcard/headset).

4) You will modify these two files on two different lines. The folder should look like this: http://i.imgur.com/ShpCv.png


Generic.kl:
ORIGINAL: http://i.imgur.com/dzmPy.png AND http://i.imgur.com/bdRRz.png

NEW: http://i.imgur.com/ZddZT.png AND http://i.imgur.com/PPAZk.png

hs_detect.kl:
ORIGINAL: http://i.imgur.com/dVaXK.png

NEW: http://i.imgur.com/Deh9r.png NOTE: I MANUALLY ADDED THE KEY 163 LINE IN

Simple right? You are just flipping the two values essentially.

5) Save the changes. Reboot.

6) Open the Keytest app again. Press the headset button. On your screen, it should read as follows:

Code:
keyCode=KEYCODE_MEDIA_NEXT
scanCode=226
as shown in the following picture: http://i.imgur.com/2BSHM.png

7) Now all you need to do is use an app to configure the MEDIA_NEXT key to your liking.

MEDIA_NEXT is a key typically found on 3-button headsets, symbolized by the "Right" key. An app like Headset Button Controller or Headset Droid should do the trick. Both are paid apps, but there are trial versions available. If there are any free alternatives that can do the trick, let me know and I'll add it in! (I am NOT in any way affiliated with the app developers!)

LIMITATIONS
1)A ROM update will wipe/reset the files.

1a) How can you avoid this? Pretty simple, actually! Just keep a backup of Generic.kl and hs_detect.kl after you make the changes to them, and inject them into the zip file before you flash the ROM. You can also use the following script to do this which needs to be run as root, given that you have the two files backed up in /sdcard/headset

Code:
mount -o rw,remount /system

cp -f /sdcard/headset/* /system/usr/keylayout

chmod 644 /system/usr/keylayout/*

mount -o ro,remount /system

2) An actual or simulated "MEDIA_NEXT" input will now not be recognized as a MEDIA_NEXT. This will affect, for example, 3-button headsets or tasker tasks that simulate a MEDIA_NEXT input. Also: ROMs with the long-press to skip tracks will no longer skip track on holding volume-up, as this is no longer recognized as a MEDIA_NEXT input.

2a) How can you avoid this? You can instead use a different key to be replaced rather than MEDIA_NEXT, if you so desire. The work-up will be the exact same, only the values you swap will be different.


CREDITS
Last edited by IAmAN00bie; 17th December 2012 at 04:51 AM. Reason: updated for Nexus 4 and formatting
The Following 36 Users Say Thank You to IAmAN00bie For This Useful Post: [ View ]
17th November 2012, 06:19 AM   |  #2  
IAmAN00bie's Avatar
OP Senior Member
Thanks Meter: 344
 
619 posts
Join Date:Joined: Dec 2010
More
Please respond to this post if it worked for you! I don't have my Nexus 4 yet, but I am absolutely positive it works on it as well! It worked for my GNexus on 4.1 and 4.2, and it has worked across many other devices as well.
17th November 2012, 06:04 PM   |  #3  
IAmAN00bie's Avatar
OP Senior Member
Thanks Meter: 344
 
619 posts
Join Date:Joined: Dec 2010
More
Bump for visibility!

Sent from my Galaxy Nexus using Tapatalk 2
18th November 2012, 01:07 AM   |  #4  
brandall's Avatar
Senior Member
Flag Birmingham
Thanks Meter: 4,669
 
2,621 posts
Join Date:Joined: May 2008
Donate to Me
More
Thanks for this It'll help me hunting for why I can't get the headset working properly in utter! !
The Following User Says Thank You to brandall For This Useful Post: [ View ]
18th November 2012, 08:48 AM   |  #5  
Senior Member
Thanks Meter: 18
 
205 posts
Join Date:Joined: May 2011
Works PERFECT! THANKS!!!! (for nexus s)
Last edited by tssphysicsboi; 18th November 2012 at 10:59 AM.
18th November 2012, 10:19 AM   |  #6  
Senior Member
Thanks Meter: 214
 
608 posts
Join Date:Joined: Nov 2010
https://play.google.com/store/apps/d...headsetcontrol

I used to use this app. It offered the same functionality without having to tweak any files. I have not tested on n4 though.
18th November 2012, 11:03 AM   |  #7  
Senior Member
Thanks Meter: 18
 
205 posts
Join Date:Joined: May 2011
Quote:
Originally Posted by 1234568

https://play.google.com/store/apps/d...headsetcontrol

I used to use this app. It offered the same functionality without having to tweak any files. I have not tested on n4 though.

This tweak is meant for long press problem only opening google now. Even Jays says this

"Compatibility
- Click-and-hold actions will not work in Android 4.1+ as Google Now intercepts them."

so even if you use jays your long press should not work unless your rom has helped you change it!
The Following User Says Thank You to tssphysicsboi For This Useful Post: [ View ]
18th November 2012, 11:11 AM   |  #8  
Member
Flag Warsaw
Thanks Meter: 21
 
79 posts
Join Date:Joined: Feb 2012
More
Used this app back in the day before i got my MW600..

https://play.google.com/store/apps/d...id=tvk.headvol
18th November 2012, 08:12 PM   |  #9  
IAmAN00bie's Avatar
OP Senior Member
Thanks Meter: 344
 
619 posts
Join Date:Joined: Dec 2010
More
Quote:
Originally Posted by PMaksymiuk

Used this app back in the day before i got my MW600..

https://play.google.com/store/apps/d...id=tvk.headvol

Yes, Headset Droid is another option for users who don't want to use Headset Button Controller!
20th November 2012, 03:16 AM   |  #10  
IAmAN00bie's Avatar
OP Senior Member
Thanks Meter: 344
 
619 posts
Join Date:Joined: Dec 2010
More
I just received my Nexus 4 earlier today, and I saw that there were some changes done in the /system/usr/keylayout folder. I managed to fix the problem, and will update the OP with new pictures ASAP for those looking to fix the headset problem.

Post Reply Subscribe to Thread

Tags
control, fix, guide, headset, voicesearch
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes