• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

[HOWTO] Remap hardware button to ICS recent apps

Search This thread

evilisto

Senior Member
Nov 26, 2010
486
2,318

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.
 
Last edited:

etoy

Senior Member
Dec 21, 2009
1,814
862
dumb question, but what does originally the "APP_SWITCH" action do without the java change?
 

thejaredhuang

Senior Member
Jan 14, 2007
130
6
It brings up a recent apps window that looks like the original switcher from 1.5.

For OP, does this still mess up the other key functions that you said in your other thread?
 
Last edited:

evilisto

Senior Member
Nov 26, 2010
486
2,318
dumb question, but what does originally the "APP_SWITCH" action do without the java change?

that will bring old version app switcher.

For OP, does this still mess up the other key functions that you said in your other thread?

if you use proper version for your rom(currently stock, cm9 and aokp), key problems will not happen. but that will happen on other roms like peter alfonso's ics..
 

jerkysh

Senior Member
Feb 25, 2011
504
180
Chisinau
where the hell is this direction?
platform/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java , i would love to try this mod on my cappy, to see if it works :)
 

RaptorOne3

Senior Member
Dec 25, 2010
257
30
If you don't mind me asking, what is the significance of this?

Long pressing the "Home" capacitive key brings up the "Recent Apps" screen... Why change it?

Forgive my short sighted confusion, but I just don't understand why you want your search button to bring up the Recent Apps screen when the home button already does it...

:confused:
 

thejaredhuang

Senior Member
Jan 14, 2007
130
6
If you don't mind me asking, what is the significance of this?

Long pressing the "Home" capacitive key brings up the "Recent Apps" screen... Why change it?

Forgive my short sighted confusion, but I just don't understand why you want your search button to bring up the Recent Apps screen when the home button already does it...

:confused:

If you've ever used webOS you'll understand how frustrating it is to hold the Home button down for 2 seconds.

I would be bagging on Android for copying webOS but in the end its the same person who designed it.
 

RaptorOne3

Senior Member
Dec 25, 2010
257
30
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?
 
Last edited:
  • Like
Reactions: cwgannon

evilisto

Senior Member
Nov 26, 2010
486
2,318

AeroEchelon

Senior Member
Nov 24, 2011
367
59
Toronto, ON
www.twitter.com
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.)
 

evilisto

Senior Member
Nov 26, 2010
486
2,318
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.
 
  • Like
Reactions: AeroEchelon

endursa

Senior Member
Dec 26, 2008
955
311
Linz
Code:
else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
            if(showing != true){
                if (down && repeatCount == 0) {
                    try {
                    mStatusBarService.toggleRecentApps();
                } catch (RemoteException e) {
                    Slog.e(TAG, "RemoteException when showing recent apps", e);
                }
            }
                return -1;
           }
        }
could you please add a check if the device is on lockscreen, so pressing the search button while the device is locked wouldn't flash the recent apps screen :)

Code:
KeyguardManager kgMgr = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
boolean showing = kgMgr.inKeyguardRestrictedInputMode();
 
Last edited:
  • Like
Reactions: evilisto

evilisto

Senior Member
Nov 26, 2010
486
2,318
could you please add a check if the device is on lockscreen, so pressing the search button while the device is locked wouldn't flash the recent apps screen :)

thank you :) i didn't even know about that bug... :eek:..
i fixed that with this code and it seems like working well.

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;
        }
 

VolcanicSkunk

Senior Member
Apr 6, 2010
1,006
256
Ohio
Quick question for the OP:
I was going to request the developer of my rom to implement this into their build. Before I did though, I was wanting to make sure that if they put this code into their build it wouldn't change anything until the keylayout.kl file was changed.
 

evilisto

Senior Member
Nov 26, 2010
486
2,318
Quick question for the OP:
I was going to request the developer of my rom to implement this into their build. Before I did though, I was wanting to make sure that if they put this code into their build it wouldn't change anything until the keylayout.kl file was changed.

yes because this change APP_SWITCH related code only. and this is not related to long-press home key too. so if you don't use APP_SWITCH keycode, this code change doesn't do anything.
 
  • Like
Reactions: VolcanicSkunk

provolinoo

Senior Member
Nov 19, 2010
1,030
242
Milano
anyone is able to update the patch for latest cm9 builds using the how to? :D

current version messes some text up

thanks in advance
 

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.