[Guide] Long press menu button to kill app

Search This thread

majdinj

Senior Member
Nov 25, 2006
980
3,442
AlAhsa
This mod will make you able to instantly kill app activity by long press on menu button

The original mod is done by maskerwsk, who modifies Mirko_ddd method

Needed tools:
1) Backsmali/Smali program from here
2) Notepad++ program from here
3) WinRAR or 7-zip archiver

The procedure:
- Backsmali android.policy.jar
- Navigate to classout/com/android/internal/policy/impl/ folder and open PhoneWindowManager.smali file
- Locate the following code by tracking "mMenuLongPress" and do the following changes:
before:
Code:
    .line 1674
    new-instance v0, Lcom/android/internal/policy/impl/PhoneWindowManager$[B][COLOR="Red"]9[/COLOR][/B];

    invoke-direct {v0, p0}, Lcom/android/internal/policy/impl/PhoneWindowManager$[B][COLOR="Red"]9[/COLOR][/B];-><init>(Lcom/android/internal/policy/impl/PhoneWindowManager;)V

    iput-object v0, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mMenuLongPress:Ljava/lang/Runnable;
after:
Code:
    .line 1674
    new-instance v0, Lcom/android/internal/policy/impl/PhoneWindowManager$[B][COLOR="Blue"]KillConcept[/COLOR][/B];

    invoke-direct {v0, p0}, Lcom/android/internal/policy/impl/PhoneWindowManager$[B][COLOR="Blue"]KillConcept[/COLOR][/B];-><init>(Lcom/android/internal/policy/impl/PhoneWindowManager;)V

    iput-object v0, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mMenuLongPress:Ljava/lang/Runnable;
N.B: $9 might be differ according to ROM, but track "mMenuLongPress" to locate the wanted code portion
- Save changes.
- Now add this new file (PhoneWindowManager$KillConcept.smali) to classout/com/android/internal/policy/impl/ folder. You can download it from here.
You should make sure that the id in PhoneWindowManager$KillConcept.smali is linked to "permlab_forceBack" id in framework-res.apk public.xml. See post #15 to know exactly how it is done.
- Now recompile (smali) the classout folder and open android.policy.jar by WinRAR or 7-zip and substitute classes.dex inside android.policy.jar with the new classes.dex file.. now push the modified android.policy.jar to your device and fix permissions to chmod 644.

Extra step:
To adjust timeout delay, backsmali framework.jar and navigate to classout/android/view/ folder and open ViewConfiguration.smali and search for this method and change RED text value:
Code:
.method public static getGlobalActionKeyTimeout()J
    .registers 2

    .prologue
    .line 669
    const-wide/16 v0, [B][COLOR="Red"]0x1f4[/COLOR][/B]

    return-wide v0
.end method
As you can see, this hex value means 500; i.e, 0.5 second.. So we will change it to which delay we want:
0x1f4 = 0.5 second (default value)
0x2ee = 0.75 second
0x3e8 = 1 second
0x4e2 = 1.25 second
0x5dc = 1.5 second
0x6d6 = 1.75 second
0x7d0 = 2 second
N.B: applying this change, will affect the timeout delay across OS!!

Now you can open any app and then long press the menu button to exit instantly.. :cool:
 
Last edited:

majdinj

Senior Member
Nov 25, 2006
980
3,442
AlAhsa
Last edited:

mikempower

Senior Member
Sep 4, 2007
341
14
for galaxy note i flashed a zip wich made all in one step.
where a can i find it for note II? (if it exists?)

Inviato dal mio GT-N7100 con Tapatalk 2
 

majdinj

Senior Member
Nov 25, 2006
980
3,442
AlAhsa
as I can check this? could you specify a bit more please
Yes..
1. decompile framework-res.apk
2. go to decompiled folder res/values folder and open public.xml file
3. search for permlab_forceBack. It will be something like this:
Code:
    <public type="string" name="permlab_forceBack" id="[B][COLOR="Blue"]0x01040245[/COLOR][/B]" />
As you see here our targeted id is 0x01040245
4. now open PhoneWindowManager$KillConcept.smali and locate this portion:
Code:
    .line 885
    move-object/from16 v0, p0

    iget-object v14, v0, Lcom/android/internal/policy/impl/PhoneWindowManager$KillConcept;->this$0:Lcom/android/internal/policy/impl/PhoneWindowManager;

    iget-object v14, v14, Lcom/android/internal/policy/impl/PhoneWindowManager;->mContext:Landroid/content/Context;

    const v15, [B][COLOR="Blue"]0x1040245[/COLOR][/B]

    const/16 v16, 0x0

    invoke-static/range {v14 .. v16}, Landroid/widget/Toast;->makeText(Landroid/content/Context;II)Landroid/widget/Toast;

    move-result-object v14

    invoke-virtual {v14}, Landroid/widget/Toast;->show()V
As you can see, I just match the id to be exactly the same like the one in public.xml of framework-res.apk (you should omit the first 0 digit; i.e, 0x01040245 will be 0x1040245)

..
 

Javho

Senior Member
Nov 26, 2012
325
20
Yes..
1. decompile framework-res.apk
2. go to decompiled folder res/values folder and open public.xml file
3. search for permlab_forceBack. It will be something like this:
Code:
    <public type="string" name="permlab_forceBack" id="[B][COLOR="Blue"]0x01040245[/COLOR][/B]" />
As you see here our targeted id is 0x01040245
4. now open PhoneWindowManager$KillConcept.smali and locate this portion:
Code:
    .line 885
    move-object/from16 v0, p0

    iget-object v14, v0, Lcom/android/internal/policy/impl/PhoneWindowManager$KillConcept;->this$0:Lcom/android/internal/policy/impl/PhoneWindowManager;

    iget-object v14, v14, Lcom/android/internal/policy/impl/PhoneWindowManager;->mContext:Landroid/content/Context;

    const v15, [B][COLOR="Blue"]0x1040245[/COLOR][/B]

    const/16 v16, 0x0

    invoke-static/range {v14 .. v16}, Landroid/widget/Toast;->makeText(Landroid/content/Context;II)Landroid/widget/Toast;

    move-result-object v14

    invoke-virtual {v14}, Landroid/widget/Toast;->show()V
As you can see, I just match the id to be exactly the same like the one in public.xml of framework-res.apk (you should omit the first 0 digit; i.e, 0x01040245 will be 0x1040245)

..

thanks for the reply: D, and the other is whether it is possible that instead of occupying occupy menu button back?
 

majdinj

Senior Member
Nov 25, 2006
980
3,442
AlAhsa
thanks for the reply: D, and the other is whether it is possible that instead of occupying occupy menu button back?

I don't know if I understand the question, but menu button will not be affected by the mod,, it will have another function that is long press to kill..
if you mean long press back button to kill, believe me this one is much easier to mod than back to kill since back button has multi-window function as well which you need to deal with during coding as well.

..
 
  • Like
Reactions: Davidson3680

Top Liked Posts

  • There are no posts matching your filters.
  • 19
    This mod will make you able to instantly kill app activity by long press on menu button

    The original mod is done by maskerwsk, who modifies Mirko_ddd method

    Needed tools:
    1) Backsmali/Smali program from here
    2) Notepad++ program from here
    3) WinRAR or 7-zip archiver

    The procedure:
    - Backsmali android.policy.jar
    - Navigate to classout/com/android/internal/policy/impl/ folder and open PhoneWindowManager.smali file
    - Locate the following code by tracking "mMenuLongPress" and do the following changes:
    before:
    Code:
        .line 1674
        new-instance v0, Lcom/android/internal/policy/impl/PhoneWindowManager$[B][COLOR="Red"]9[/COLOR][/B];
    
        invoke-direct {v0, p0}, Lcom/android/internal/policy/impl/PhoneWindowManager$[B][COLOR="Red"]9[/COLOR][/B];-><init>(Lcom/android/internal/policy/impl/PhoneWindowManager;)V
    
        iput-object v0, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mMenuLongPress:Ljava/lang/Runnable;
    after:
    Code:
        .line 1674
        new-instance v0, Lcom/android/internal/policy/impl/PhoneWindowManager$[B][COLOR="Blue"]KillConcept[/COLOR][/B];
    
        invoke-direct {v0, p0}, Lcom/android/internal/policy/impl/PhoneWindowManager$[B][COLOR="Blue"]KillConcept[/COLOR][/B];-><init>(Lcom/android/internal/policy/impl/PhoneWindowManager;)V
    
        iput-object v0, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mMenuLongPress:Ljava/lang/Runnable;
    N.B: $9 might be differ according to ROM, but track "mMenuLongPress" to locate the wanted code portion
    - Save changes.
    - Now add this new file (PhoneWindowManager$KillConcept.smali) to classout/com/android/internal/policy/impl/ folder. You can download it from here.
    You should make sure that the id in PhoneWindowManager$KillConcept.smali is linked to "permlab_forceBack" id in framework-res.apk public.xml. See post #15 to know exactly how it is done.
    - Now recompile (smali) the classout folder and open android.policy.jar by WinRAR or 7-zip and substitute classes.dex inside android.policy.jar with the new classes.dex file.. now push the modified android.policy.jar to your device and fix permissions to chmod 644.

    Extra step:
    To adjust timeout delay, backsmali framework.jar and navigate to classout/android/view/ folder and open ViewConfiguration.smali and search for this method and change RED text value:
    Code:
    .method public static getGlobalActionKeyTimeout()J
        .registers 2
    
        .prologue
        .line 669
        const-wide/16 v0, [B][COLOR="Red"]0x1f4[/COLOR][/B]
    
        return-wide v0
    .end method
    As you can see, this hex value means 500; i.e, 0.5 second.. So we will change it to which delay we want:
    0x1f4 = 0.5 second (default value)
    0x2ee = 0.75 second
    0x3e8 = 1 second
    0x4e2 = 1.25 second
    0x5dc = 1.5 second
    0x6d6 = 1.75 second
    0x7d0 = 2 second
    N.B: applying this change, will affect the timeout delay across OS!!

    Now you can open any app and then long press the menu button to exit instantly.. :cool:
    3
    Is it possible to control delay before an app gets killed?

    Sent from my GT-N7000 using Tapatalk HD

    No in the meantime,,, but may be in future, since it involves complicated coding and decompiling other system app..

    I have found a short way to do that,,, I will update OP soon after I come back home

    Edit:
    Added extra step
    2
    as I can check this? could you specify a bit more please
    Yes..
    1. decompile framework-res.apk
    2. go to decompiled folder res/values folder and open public.xml file
    3. search for permlab_forceBack. It will be something like this:
    Code:
        <public type="string" name="permlab_forceBack" id="[B][COLOR="Blue"]0x01040245[/COLOR][/B]" />
    As you see here our targeted id is 0x01040245
    4. now open PhoneWindowManager$KillConcept.smali and locate this portion:
    Code:
        .line 885
        move-object/from16 v0, p0
    
        iget-object v14, v0, Lcom/android/internal/policy/impl/PhoneWindowManager$KillConcept;->this$0:Lcom/android/internal/policy/impl/PhoneWindowManager;
    
        iget-object v14, v14, Lcom/android/internal/policy/impl/PhoneWindowManager;->mContext:Landroid/content/Context;
    
        const v15, [B][COLOR="Blue"]0x1040245[/COLOR][/B]
    
        const/16 v16, 0x0
    
        invoke-static/range {v14 .. v16}, Landroid/widget/Toast;->makeText(Landroid/content/Context;II)Landroid/widget/Toast;
    
        move-result-object v14
    
        invoke-virtual {v14}, Landroid/widget/Toast;->show()V
    As you can see, I just match the id to be exactly the same like the one in public.xml of framework-res.apk (you should omit the first 0 digit; i.e, 0x01040245 will be 0x1040245)

    ..
    2
    Is there a way to get this done using magic? I've got an amulet made out of cats teeth, a handful of lambs bones, some random bits of human hair (possibly some pubes too) 5 dried frogs and a small bag of exploding glitter (for the climactic bit)...

    Use the searching feature of xda to search for decompiling, compiling, baksmali and smali tutorials,,, There are many excellent tutorials that will make you have the first step..

    Example of excellent tutorials (must read thoroughly):
    >> [Guide] Decompile with Apk Tool [Easy Way]
    >> [TOOL/GUIDE GB/ICS/JB] Decompile/Recompile apk | jar | sign + Basic editing xml/smali
    >> [Share Latest Apktool 4.2.2/Guide/Tutorial/] How to Decompile/Compile/Sign Apk/Jar

    Some easy tools:
    >> [Windows][UTILITY][TOOL] APK Multi-Tool
    >> [Utility][Tool][Windows] Backsmali / Smali Manager

    No magic... It is only patience, willing of learning and a lot of practicing...!!
    1
    thanks for the reply: D, and the other is whether it is possible that instead of occupying occupy menu button back?

    I don't know if I understand the question, but menu button will not be affected by the mod,, it will have another function that is long press to kill..
    if you mean long press back button to kill, believe me this one is much easier to mod than back to kill since back button has multi-window function as well which you need to deal with during coding as well.

    ..