FORUMS
Remove All Ads from XDA

[MOD][TUTORIAL]Longpress back to kill app[STOCK ROM][JB]

73 posts
Thanks Meter: 120
 
By MichaelGroth, Member on 31st December 2012, 01:54 PM
Post Reply Email Thread
Hello XDA'ers!

I am not new to these forums.. I am a frequent reader, but I am not much of a poster.
I was really missing the "long press back button to kill app" in the stock TW rom, so I just had to get this working for our GNote 10.1.
After alot of trial and error I finally got it working, and as promised in the Q&A forum, here comes my tutorial.

Big thank you to:
Mirko ddd for the $KillConcept script, and helping me understand the code and getting this working for the GNote 10.1. Link to Mirko ddd's original thread here: http://forum.xda-developers.com/show....php?t=1969499
tdunham for looking at my andoid.policy.jar and helping me solve my "annoying" toast message problem.

//*Standard disclaimer:
You are doing this at your own risk and understand that you are liable to any side effects that may come from performing this modification.
I am not responsible for anything that happens to your device.*//

**I recommend doing a backup before performing this modification**


What you need:
  • smali.zip - Attached at the bottom of this post -
  • flashable.zip - Attached at the bottom of this post -
  • PhoneWindowManager$KillConcept.smali - Attached at the bottom of this post -
  • 7zip - Download at 7-zip.org -
  • notepad++ - Download at notepad-plus-plus.org -

*Optional mod* (change text when app is killed) this will give you a toast message that makes more sence like "Application Killed.":
You will need APKTool or Virtuous Ten Studio for this.. -Download Virtuous Ten Studio at virtuous-ten-studio.com -


How to:

First we need to extract android.policy.jar from your device, this is located under system/framework, extract it to your sdcard and push it to your computer.

Now, unzip the supplied smali.zip file. You will now get a folder called "smali". Place your android.policy.jar file in this folder (remember to make a backup of your original android.policy.jar just in case).

Click on the 1.bat file (this will decompile your android.policy.jar), you will now get a folder called "classout", click on this folder and navigate to "classout\com\android\internal\policy\impl", now locate the file called "PhoneWindowManager.smali", and open this file using Notepad++.

Now we will need to locate this code:

Code:
    
new-instance v0, Lcom/android/internal/policy/impl/PhoneWindowManager$10;

invoke-direct {v0, p0}, Lcom/android/internal/policy/impl/PhoneWindowManager$10;-><init>(Lcom/android/internal/policy/impl/PhoneWindowManager;)V

iput-object v0, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mBackLongPress:Ljava/lang/Runnable;
Replace both subclasses $10 with $KillConcept so that the code will look like this:

Code:
    
new-instance v0, Lcom/android/internal/policy/impl/PhoneWindowManager$KillConcept;

invoke-direct {v0, p0}, Lcom/android/internal/policy/impl/PhoneWindowManager$KillConcept;-><init>(Lcom/android/internal/policy/impl/PhoneWindowManager;)V

iput-object v0, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mBackLongPress:Ljava/lang/Runnable;
Now locate this code:

Code:
 
    .line 6293
    :cond_905
    move-object/from16 v0, p0

    iget-boolean v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mIsMultiWindowUIEnabled:Z

    move/from16 v24, v0

    if-eqz v24, :cond_68

    move-object/from16 v0, p0

    iget v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mEnableMultiWindowUISetting:I

    move/from16 v24, v0

    if-eqz v24, :cond_68
Focus on bolded underlined conds, we need to switch them with cond_93c so we will have:

Code:
 
    .line 6293
    :cond_905
    move-object/from16 v0, p0

    iget-boolean v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mIsMultiWindowUIEnabled:Z

    move/from16 v24, v0

    if-eqz v24, :cond_93c

    move-object/from16 v0, p0

    iget v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mEnableMultiWindowUISetting:I

    move/from16 v24, v0

    if-eqz v24, :cond_93c

cond_93c may be different depending on your FW version and compiler, but we need to recall the cond that gives this:


Code:
 
    .line 6298
    :cond_93c
    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mHandler:Landroid/os/Handler;

    move-object/from16 v24, v0

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mBackLongPress:Ljava/lang/Runnable;

    move-object/from16 v25, v0

    invoke-static {}, Landroid/view/ViewConfiguration;->getGlobalActionKeyTimeout()J

    move-result-wide v26

    invoke-virtual/range {v24 .. v27}, Landroid/os/Handler;->postDelayed(Ljava/lang/Runnable;J)Z

    goto/16 :goto_68
Save the file.

Unzip and add the supplied PhoneWindowManager$KillConcept.smali to "classout\com\android\internal\policy\impl"

Now go back to your "smali" folder and click on 2.bat to recompile.
You will now get a file called classes.dex, open your android.policy.jar with 7zip and replace the old classes.dex with the new one.

Open the supplied flashable.zip with 7zip and place your modified android.policy.jar file in "system\framework\" inside the flashable.zip

Create a copy of "flashable.zip" and call it "backup.zip" and place your original unmodified android.policy.jar in this one (Just in case you did something wrong and you end up in a bootloop, you can always flash your backup.zip just remember to move it to your device together with the flashable.zip).

Flash the .zip in CWM.

Profit! You should now have the longpress back to kill app function enabled.


(Optional mod)
...Now if for some reason you get a "toast message" that makes no sence.. like "prevent app switches".
You need to edit the PhoneWindowManager$KillConcept.smali with notepad++

Locate this code (should be around line 234 somewhere):

Code:
    const v15, 0x104023d
Now, you have to extract framework-res.apk from your device.. this file is also located under system/framework.
Decompile framework-res.apk using APKTool or Virtuous Ten Studio
To find the correct value. Navigate to res/values/public.xml.
Search for: permlab_forceBack

Sould look something like this (this is what mine looks like):

Code:
<public type="string" name="permlab_forceBack" id="0x0104023d" />
You just need the last 7 digits (exclude the 0x0) and replace the last 7 of the code above in PhoneWindowManager$KillConcept.smali.

This will give you a "toast message" that makes a little more sence like "force app to close".
If you are fine with this.. just recompile and add the new framework-res.apk to the supplied flashable.zip under system/framework (Remember to make a backup.zip with your old framework-res.apk just in case anything goes wrong, you can always flash your backup.zip just remember to move it to your device together with the flashable.zip).

Flash the .zip in CWM. Profit!

(Second optional mod)
Now, if you are like me and want a more "stock look" to your toast message. You will also need to edit res/values/strings.xml
If you are running a different language rom you will need to find the values folder for your language. Example: If your language is "English - Great Britain" you will need to navigate to the folder res/values-en-rGB/strings.xml

Now search for the string: permlab_forceBack inside strings.xml and change the text from "force app to close" to "Application Killed." or what ever you prefer.

Recompile and add the new framework-res.apk to the supplied flashable.zip under system/framework (Remember to make a backup.zip with your old framework-res.apk just in case anything goes wrong, you can always flash your backup.zip just remember to move it to your device together with the flashable.zip).

Flash the .zip in CWM.

Done!
Attached Files
File Type: zip smali.zip - [Click for QR Code] (1,017.4 KB, 514 views)
File Type: zip flashable.zip - [Click for QR Code] (154.1 KB, 485 views)
File Type: zip PhoneWindowManager$KillConcept.smali.zip - [Click for QR Code] (2.0 KB, 485 views)
The Following 20 Users Say Thank You to MichaelGroth For This Useful Post: [ View ] Gift MichaelGroth Ad-Free
31st December 2012, 02:19 PM |#2  
Mirko ddd's Avatar
Inactive Recognized Developer
Flag Piazza Armerina
Thanks Meter: 4,863
 
Donate to Me
More
This should be in development. Nice one
The Following User Says Thank You to Mirko ddd For This Useful Post: [ View ] Gift Mirko ddd Ad-Free
31st December 2012, 02:56 PM |#3  
OP Member
Flag Oslo
Thanks Meter: 120
 
Donate to Me
More
Smile
Quote:
Originally Posted by Mirko ddd

This should be in development. Nice one

Thank you Mirko ddd.
As "New members (those with fewer than 10 posts) are not permitted to post to development-related forums." it ended up in here..
I had no other alternative unless I started spamming the forum to get my "10 posts".
Hoping a moderator will be kind enough to move it.
The Following User Says Thank You to MichaelGroth For This Useful Post: [ View ] Gift MichaelGroth Ad-Free
31st December 2012, 02:58 PM |#4  
Mirko ddd's Avatar
Inactive Recognized Developer
Flag Piazza Armerina
Thanks Meter: 4,863
 
Donate to Me
More
Quote:
Originally Posted by MichaelGroth

Thank you Mirko dd.
As "New members (those with fewer than 10 posts) are not permitted to post to development-related forums." it ended up in here..
I had no other alternative unless I started spamming the forum to get my "10 posts".
Hoping a moderator will be kind enough to move it.

I see. Report the op and ask for move, don t send pm to forum moderators.

Cheers
31st December 2012, 04:30 PM |#5  
OP Member
Flag Oslo
Thanks Meter: 120
 
Donate to Me
More
Smile
Quote:
Originally Posted by Mirko ddd

I see. Report the op and ask for move, don t send pm to forum moderators.

Cheers

Thnx.

Thread is moved now
The Following User Says Thank You to MichaelGroth For This Useful Post: [ View ] Gift MichaelGroth Ad-Free
31st December 2012, 10:20 PM |#6  
Jamison904's Avatar
Senior Member
Jacksonville, Florida
Thanks Meter: 15,189
 
Donate to Me
More
Awesome job man! I was having a heck of a time porting over "menu to kill" and modifying it to the back button. Just didn't have the time to work it through... thanks and definitely giving you credit when I implemente it.
3rd January 2013, 10:58 AM |#7  
OP Member
Flag Oslo
Thanks Meter: 120
 
Donate to Me
More
Smile
Quote:
Originally Posted by Jamison904

Awesome job man! I was having a heck of a time porting over "menu to kill" and modifying it to the back button. Just didn't have the time to work it through... thanks and definitely giving you credit when I implemente it.

Thnx, but Mirko ddd is the one who deserves the credit. I just made a few changes to his script and tutorial to make it work with our devices

Michael
4th January 2013, 03:25 PM |#8  
pimpmaneaton's Avatar
Recognized Contributor
Flag West Jordan UT
Thanks Meter: 5,327
 
Donate to Me
More
Man this is kicking my butt. I cannot get the android.policy to rebuild after making the changes. I am using linux and rename it to android.policy.apk and decompile and make changes but upon compile, it errors out. Dont have an issue when making the reboot mod this way. I dont really understand where to put this at in the .smali file.

.line 6298
:cond_93c
move-object/from16 v0, p0

iget-object v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mHandler:Landroid/os/Handler;

move-object/from16 v24, v0

move-object/from16 v0, p0

iget-object v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mBackLongPress:Ljava/lang/Runnable;

move-object/from16 v25, v0

invoke-static {}, Landroid/view/ViewConfiguration;->getGlobalActionKeyTimeout()J

move-result-wide v26

invoke-virtual/range {v24 .. v27}, Landroid/os/Handler;->postDelayed(Ljava/lang/Runnable;J)Z

goto/16 :goto_68

I dont really understand java very much at all. Any help would be greatly appreciated. Thanks for the work on getting this working for our device.
Attached Files
File Type: jar android.policy.jar - [Click for QR Code] (377.3 KB, 15 views)
5th January 2013, 03:52 AM |#9  
OP Member
Flag Oslo
Thanks Meter: 120
 
Donate to Me
More
Smile
Quote:
Originally Posted by pimpmaneaton

Man this is kicking my butt. I cannot get the android.policy to rebuild after making the changes. I am using linux and rename it to android.policy.apk and decompile and make changes but upon compile, it errors out. Dont have an issue when making the reboot mod this way. I dont really understand where to put this at in the .smali file.

.line 6298
:cond_93c
move-object/from16 v0, p0

iget-object v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mHandler:Landroid/os/Handler;

move-object/from16 v24, v0

move-object/from16 v0, p0

iget-object v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mBackLongPress:Ljava/lang/Runnable;

move-object/from16 v25, v0

invoke-static {}, Landroid/view/ViewConfiguration;->getGlobalActionKeyTimeout()J

move-result-wide v26

invoke-virtual/range {v24 .. v27}, Landroid/os/Handler;->postDelayed(Ljava/lang/Runnable;J)Z

goto/16 :goto_68

I dont really understand java very much at all. Any help would be greatly appreciated. Thanks for the work on getting this working for our device.

Hello pimpmaneaton.

As i said in my original post the cond_93c may be different depending on your FW version and compiler.
I did my mod on the 8010 JB ROM, I am not sure wich device/rom you are on, but the conds look different.

I looked at your android.policy.jar and this is what I found:

I found multiple conds that were close: cond_683, cond_9ae and cond_999, (I am not sure)but I went with the cond most similar to mine wich is cond_999 found at line: 17591

looks like this:

Code:
    .line 6430
    :cond_999
    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mHandler:Landroid/os/Handler;

    move-object/from16 v25, v0

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mBackLongPress:Ljava/lang/Runnable;

    move-object/from16 v26, v0

    invoke-static {}, Landroid/view/ViewConfiguration;->getGlobalActionKeyTimeout()J

    move-result-wide v27

    invoke-virtual/range {v25 .. v28}, Landroid/os/Handler;->postDelayed(Ljava/lang/Runnable;J)Z

    goto/16 :goto_68
Also, just in case... I think this is where you need to change your conds, found at line 17532 (Unless you already found this on your own):

Code:
    .line 6425
    :cond_962
    move-object/from16 v0, p0

    iget-boolean v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mIsMultiWindowUIEnabled:Z

    move/from16 v25, v0

    if-eqz v25, :cond_68

    move-object/from16 v0, p0

    iget v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mEnableMultiWindowUISetting:I

    move/from16 v25, v0

    if-eqz v25, :cond_68
Focus on bolded underlined conds, we need to switch them with the right cond.

The file will not recompile unless your conds match up, so I think that was our problem here.

I have attached your android.policy.jar with the modifications above and the $KillConcept already added, so flash that and see if it works (remember to make a flashable backup just in case!). If everything fails, check out the other conds I found and try those instead.
Sorry to advise you in to "trail and error" but eventually it will work, you just have to get the conds right.

Kind regards
Michael
Attached Files
File Type: jar android.policy.jar - [Click for QR Code] (364.9 KB, 29 views)
The Following User Says Thank You to MichaelGroth For This Useful Post: [ View ] Gift MichaelGroth Ad-Free
5th January 2013, 06:00 AM |#10  
pimpmaneaton's Avatar
Recognized Contributor
Flag West Jordan UT
Thanks Meter: 5,327
 
Donate to Me
More
Quote:
Originally Posted by MichaelGroth

Hello pimpmaneaton.

As i said in my original post the cond_93c may be different depending on your FW version and compiler.
I did my mod on the 8010 JB ROM, I am not sure wich device/rom you are on, but the conds look different.

I looked at your android.policy.jar and this is what I found:

I found multiple conds that were close: cond_683, cond_9ae and cond_999, (I am not sure)but I went with the cond most similar to mine wich is cond_999 found at line: 17591

looks like this:

Code:
    .line 6430
    :cond_999
    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mHandler:Landroid/os/Handler;

    move-object/from16 v25, v0

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mBackLongPress:Ljava/lang/Runnable;

    move-object/from16 v26, v0

    invoke-static {}, Landroid/view/ViewConfiguration;->getGlobalActionKeyTimeout()J

    move-result-wide v27

    invoke-virtual/range {v25 .. v28}, Landroid/os/Handler;->postDelayed(Ljava/lang/Runnable;J)Z

    goto/16 :goto_68
Also, just in case... I think this is where you need to change your conds, found at line 17532 (Unless you already found this on your own):

Code:
    .line 6425
    :cond_962
    move-object/from16 v0, p0

    iget-boolean v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mIsMultiWindowUIEnabled:Z

    move/from16 v25, v0

    if-eqz v25, :cond_68

    move-object/from16 v0, p0

    iget v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mEnableMultiWindowUISetting:I

    move/from16 v25, v0

    if-eqz v25, :cond_68
Focus on bolded underlined conds, we need to switch them with the right cond.

The file will not recompile unless your conds match up, so I think that was our problem here.

I have attached your android.policy.jar with the modifications above and the $KillConcept already added, so flash that and see if it works (remember to make a flashable backup just in case!). If everything fails, check out the other conds I found and try those instead.
Sorry to advise you in to "trail and error" but eventually it will work, you just have to get the conds right.

Kind regards
Michael

Awesome thank you for that. I will try when i get back in town. I really appreciate that.

Edit: okay i think i understand more now. I have not downloaded and tried and wont be able to till tomorrow. But i now see that the cond 68 should be changed to 999. I completely mid understood before and was actually trying to change to 93c. I don't really understand the code still but at least see the path i need to take to make the mod work. I'M DUMB!!!

Sent from my SCH-I535 using Tapatalk 2
17th March 2013, 01:31 PM |#11  
bykevin's Avatar
Junior Member
Thanks Meter: 2
 
More
Why I cannot find
CODE“.line 6293”

NO “if-eqz v24, :cond_68”

Click image for larger version

Name:	QQ?1.png
Views:	632
Size:	43.9 KB
ID:	1811786


Could you help me to check my "android.policy.jar" ?

N8000 ROM:
Revolution HD 4.4
android 4.12
Attached Files
File Type: jar android.policy.jar - [Click for QR Code] (375.2 KB, 4 views)
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes