[Galaxy Note 10.1 Android Development] MichaelGroth:
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://xdaforums.com/showthread.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:

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:

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:

.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

[B][U]if-eqz v24, :cond_68[/U][/B]

move-object/from16 v0, p0

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

move/from16 v24, v0

[B][U]if-eqz v24, :cond_68[/U][/B]

Focus on

bolded underlined conds

, we need to switch them with cond_93c so we will have:

.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

[B][U]if-eqz v24, :cond_93c[/U][/B]

move-object/from16 v0, p0

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

move/from16 v24, v0

[B][U]if-eqz v24, :cond_93c[/U][/B]

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

.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):

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):

<public type="string" name="permlab_forceBack" id="0x0[B]104023d[/B]" />

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!