[HOWTO] Remap hardware button to ICS recent apps

Search This thread

Iloveyouandroid

Senior Member
Apr 10, 2012
57
20
NYC
Thanks evilisto, love this mod :)

Here is the smali version for 4.0.4 :

- Open com\android\internal\policy\impl\PhoneWindowManager.smali :
- Search for .line 1730 (there should be a call to showOrHideRecentAppsDialog 3 or 4 lines below)
(If you can't find it, search for method interceptKeyBeforeDispatching and for the call to showOrHideRecentAppsDialog within it)
- Now replace this

Code:
.line 1730
const/16 v26, 0x0

move-object/from16 v0, p0

move/from16 v1, v26

invoke-virtual {v0, v1}, Lcom/android/internal/policy/impl/PhoneWindowManager;->showOrHideRecentAppsDialog(I)V

.line 1732
:cond_1b5

By this

Code:
.line 1730
if-nez v14, :cond_1b5

:try_start_3d
move-object/from16 v0, p0
iget-object v1, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mStatusBarService:Lcom/android/internal/statusbar/IStatusBarService;
invoke-interface {v1}, Lcom/android/internal/statusbar/IStatusBarService;->toggleRecentApps()V
:try_end_41
.catch Landroid/os/RemoteException; {:try_start_3d .. :try_end_41} :catch_42

# No error, keep going
goto :cond_1b5

:catch_42
# Fetch exception
move-exception v0

# Throws exception
const-string v1, "WindowManager"
const-string v2, "RemoteException when showing recent apps"
invoke-static {v1, v2, v0}, Landroid/util/Slog;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

.line 1732
:cond_1b5

Smart!
 

zakiay

Member
May 8, 2010
36
0
Is there any way to have the menu button open the recent apps and not the search button? Im running CM9 on my xperia arc and want to remap the menu key to bring up recent apps. any possibility of this happening?
 

tylose

Senior Member
Nov 20, 2011
51
4
Is there any way to have the menu button open the recent apps and not the search button? Im running CM9 on my xperia arc and want to remap the menu key to bring up recent apps. any possibility of this happening?

You shouldn't. You will lose the ability to open the menu which may be vital for some applications. Since your phone has a physical menu button, even ICS optimized apps will not show you a menu button on the action bar.
 

muell_matto

Member
Oct 3, 2011
32
5
Münster
You shouldn't. You will lose the ability to open the menu which may be vital for some applications. Since your phone has a physical menu button, even ICS optimized apps will not show you a menu button on the action bar.


Hi!

If you enable the on screen buttons, ics optimized apps will show the "3 dots menu" somewhere in the app. eg the sms/mms app will show it on top, next tpo the phone symbol.

So in important apps you will see a menu....

btw the htc one x has the same keylayout and it works there

greetings matto
 

zakiay

Member
May 8, 2010
36
0
thats correct, ics should give you the 3 dots menu button somewhere on the screen, long pressing the home button and waiting is such a drag. So is there some way to enable in on the xperia arc or is it the same as the process on the first page?
 

BoyBawang2

Senior Member
Nov 25, 2008
637
22
If the app is not ICS optimized, the 3 dots should appear along with the recent apps when the key is tapped. That may be an extra step to access the menu but that will slowly change as developers update their apps. I wish the keys can pe MODDED that way.
 

Adi_Pat

Senior Member
Dec 19, 2011
1,210
3,566
Mumbai
Is there any way to get 'Recent Apps' on GB ?
Either in status bar or with the help of a softkey?
 

rkaede

Senior Member
can i implement this on the Galaxy S CM9 ?

since the google search menu is done using the long pressed of the menu.

Left soft key. i know this feature is accesible by the long pressed home button.

i figure easier to do it with soft key rather than hw key.

:D
 

Doopliss

Senior Member
May 13, 2011
90
66
Thanks for this guide, I've mapped the app switcher to the menu button on my Galaxy S2 with CM9. However, just editing the keylayout file(s) didn't actually make ICS optimised apps display the overflow menu button within their UI. To force them to do that I made a change in:
/frameworks/base/core/java/android/view/ViewConfiguration.java
From:
Code:
         if (!sHasPermanentMenuKeySet) {
             IWindowManager wm = Display.getWindowManager();
             try {
                 sHasPermanentMenuKey = wm.canStatusBarHide() && !wm.hasNavigationBar();
                 sHasPermanentMenuKeySet = true;
             } catch (RemoteException ex) {
                 sHasPermanentMenuKey = false;
             }
         }
To:
Code:
         if (!sHasPermanentMenuKeySet) {
             sHasPermanentMenuKey = false;
             sHasPermanentMenuKeySet = true;
         }

I would like to also make long-pressing the home button show the menu (for compatibility with non-ICS optimised apps), but I'm not sure how to do that.
 
Last edited:
  • Like
Reactions: reactorcooler

cloud596

Senior Member
Jan 7, 2011
207
43
Thanks for this guide, I've mapped the app switcher to the menu button on my Galaxy S2 with CM9. However, just editing the keylayout file(s) didn't actually make ICS optimised apps display the overflow menu button within their UI. To force them to do that I made a change in:
/frameworks/base/core/java/android/view/ViewConfiguration.java
From:
Code:
         if (!sHasPermanentMenuKeySet) {
             IWindowManager wm = Display.getWindowManager();
             try {
                 sHasPermanentMenuKey = wm.canStatusBarHide() && !wm.hasNavigationBar();
                 sHasPermanentMenuKeySet = true;
             } catch (RemoteException ex) {
                 sHasPermanentMenuKey = false;
             }
         }
To:
Code:
         if (!sHasPermanentMenuKeySet) {
             sHasPermanentMenuKey = false;
             sHasPermanentMenuKeySet = true;
         }

I would like to also make long-pressing the home button show the menu (for compatibility with non-ICS optimised apps), but I'm not sure how to do that.
would you like provide a guide for smali
 

dinos3

Senior Member
Dec 31, 2011
1,028
138
my noob question ; where is platform/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java file ? Any way to rebuild on win 7 with witch software ?
 
Last edited:

Renate

Recognized Contributor / Inactive Recognized Dev
There are basically three ways to modify a jar:

#1

Start with the modified Java source and build it.

#2a (for modifying parts of methods)

Adb pull the jar off your device, disassemble it using apktool d, modify the smali code by hand, assemble it using apktool b, adb push it on your device.

#2b (for replacing entire methods)

Write your patch in Java, add the package declaration, imports and stubs, do a normal build on it, disassemble it using apktool d, use the selected smali code from that to edit into the smali code for method #2a.

Be careful modifying smali code by hand, it's easy to screw up register allocation and brick your device.

(It would be helpful if people who post smali code here would also mention what method the smali code snippet modifies.)
 

gizzmoguy

Member
Jul 7, 2008
12
0
how to remap button on ics

am not looking to remap but simply to double tap my menu button to get to recent apps that way i don't loose no functionality
 

TheGoD

Senior Member
Oct 26, 2009
414
54
True that, is there a way to either remap the long press action or implement double taping. Id like to either use Home for multitasking and Home Long for home, or Menu for multitasking and Menu Long for menu or double taping a button for multitasking on my i9000.
 

daasguy

Senior Member
Nov 12, 2009
178
10
Needs update for Jelly Bean cm10

APP_SWITCH DOES NOT WORK

cypress-touchkey.kl

mxt224_ts_input.kl

IT ENDS UP GIVING RECENT APPS GINGERBREAD STYLE ON CM10 CRESPO SHANKS NIGHTLY

????
 

crkdslider

Senior Member
Jul 12, 2012
857
288
Scottsdale, AZ
www.delsolaviation.com
Is there any way to have the menu button open the recent apps and not the search button? Im running CM9 on my xperia arc and want to remap the menu key to bring up recent apps. any possibility of this happening?

You shouldn't. You will lose the ability to open the menu which may be vital for some applications. Since your phone has a physical menu button, even ICS optimized apps will not show you a menu button on the action bar.

I have done this on Paranoid Android for the Galaxy SII Epic 4G Touch.
My interest in this mod, however, is I would like the search button to open/close the menu. I have the menu button set to open recent apps, but is there a way I can do the aforementioned? How would I go about accessing the source code to make these changes if it is possible?

Thanks,

crkdslider
 

Top Liked Posts

  • There are no posts matching your filters.
  • 18

    this is simple howto about this mod.. : [MOD] Search key to ICS recent apps


    1) change source code related to APP_SWITCH keycode.

    platform/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

    from :
    Code:
            } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
                if (down && repeatCount == 0) {
                    showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS);
                }
                return -1;
            }


    to :
    Code:
            } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
                if (down && repeatCount == 0 && !keyguardOn) {
                try {
                    mStatusBarService.toggleRecentApps();
                } catch (RemoteException e) {
                    Slog.e(TAG, "RemoteException when showing recent apps", e);
                }
            }
                return -1;
            }


    2) edit your keylayout files..

    /system/usr/keylayout/

    for example, if you want to use search key to recent apps on nexus s...

    cypress-touchkey.kl
    Code:
    key 139    MENU           VIRTUAL
    key 102    HOME           VIRTUAL
    key 158    BACK           VIRTUAL
    key 217    APP_SWITCH     VIRTUAL

    and mxt224_ts_input.kl (it would be better to edit both files..)
    Code:
    key 158   BACK              WAKE
    key 139   MENU              WAKE
    key 217   APP_SWITCH        WAKE
    key 102   HOME              WAKE


    3) done :)

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

    - and if you cannot compile android.policy.jar for some reason, try with my files instead.
    you can find my files in these thread :
    [MOD] Search key to ICS recent apps
    [MOD] Add ICS 'Recent Apps' button to Status bar
    and be careful. you should use suitable version to your rom. so if your cm9 rom was built few weeks ago, do not try with latest version of my mod.
    10
    Thanks evilisto, love this mod :)

    Here is the smali version for 4.0.4 :

    - Open com\android\internal\policy\impl\PhoneWindowManager.smali :
    - Search for .line 1730 (there should be a call to showOrHideRecentAppsDialog 3 or 4 lines below)
    (If you can't find it, search for method interceptKeyBeforeDispatching and for the call to showOrHideRecentAppsDialog within it)
    - Now replace this

    Code:
    .line 1730
    const/16 v26, 0x0
    
    move-object/from16 v0, p0
    
    move/from16 v1, v26
    
    invoke-virtual {v0, v1}, Lcom/android/internal/policy/impl/PhoneWindowManager;->showOrHideRecentAppsDialog(I)V
    
    .line 1732
    :cond_1b5

    By this

    Code:
    .line 1730
    if-nez v14, :cond_1b5
    
    :try_start_3d
    move-object/from16 v0, p0
    iget-object v1, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mStatusBarService:Lcom/android/internal/statusbar/IStatusBarService;
    invoke-interface {v1}, Lcom/android/internal/statusbar/IStatusBarService;->toggleRecentApps()V
    :try_end_41
    .catch Landroid/os/RemoteException; {:try_start_3d .. :try_end_41} :catch_42
    
    # No error, keep going
    goto :cond_1b5
    
    :catch_42
    # Fetch exception
    move-exception v0
    
    # Throws exception
    const-string v1, "WindowManager"
    const-string v2, "RemoteException when showing recent apps"
    invoke-static {v1, v2, v0}, Landroid/util/Slog;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I
    
    .line 1732
    :cond_1b5
    1
    Hmm... I suppose...

    No pun intended... Just curious. Seemed a bit redundant but I suppose it's all in personal preference really. Just another option I suppose! :D

    I may actually be interested in this the more I think about it... I never use my search button. It would be nice to bind it to a some what useful function... lol...

    I'll be keeping my eye on this. Perhaps we could bundle a little update zip for this?
    1
    I am currently using a AOSP based ROM for the Nexus S and would greatly appreciate this mod! I found your thread on the Nexus S forum however my ROM isn't supported ...

    How would I go about changing the source code on my ROM? (Not too experienced with Android Development.)

    sorry but i can't make mod for your rom because he doesn't release his source code..
    and he was interested this mod too(link). so i think this mod or similar thing will be added to his rom later.
    1
    Thanks for this guide, I've mapped the app switcher to the menu button on my Galaxy S2 with CM9. However, just editing the keylayout file(s) didn't actually make ICS optimised apps display the overflow menu button within their UI. To force them to do that I made a change in:
    /frameworks/base/core/java/android/view/ViewConfiguration.java
    From:
    Code:
             if (!sHasPermanentMenuKeySet) {
                 IWindowManager wm = Display.getWindowManager();
                 try {
                     sHasPermanentMenuKey = wm.canStatusBarHide() && !wm.hasNavigationBar();
                     sHasPermanentMenuKeySet = true;
                 } catch (RemoteException ex) {
                     sHasPermanentMenuKey = false;
                 }
             }
    To:
    Code:
             if (!sHasPermanentMenuKeySet) {
                 sHasPermanentMenuKey = false;
                 sHasPermanentMenuKeySet = true;
             }

    I would like to also make long-pressing the home button show the menu (for compatibility with non-ICS optimised apps), but I'm not sure how to do that.