[Galaxy S 5 General] kaise123:
I realise that this subject already has multiple threads, but many of them do not include proper instructions, and are therefore hard to understand for users who are not familiar with Smali and other more complicated Android terminology.

This guide will help you to restore functionality similar to the Galaxy S4 and earlier models, by changing the new Recent Apps softkey back to menu, and restoring the long-press of the home button to the recent apps switcher. Unlike most other modifications that achieve this, the home button long press retains it's haptic feedback.

Before beginning, you need the following:

- Rooted Galaxy S5. Should work on all variants but I have personally tested on the G900I and G900F

- PC with Windows (Can obviously be done on Linux or OSX, but for this tutorial I will be using Windows)

- ADB Drivers for Samsung (HERE)

- Deodexed rom. I don't think this will work with an Odexed rom, as you won't be able to mod android.policy.jar

- ES File explorer, ADB or any file manager capable of editing files in root.

- ADB (Go HERE)

- JDK (Go HERE)

- Smali & Backsmali (Will be covered further down, Download from HERE)

- WinRar, 7zip or other program capable of unzipping JAR files

You do not need Xposed framework for this to work, making it compatible with Android 5+

I have tested this as working on the following devices & Android versions:

G900I: Android 5.0 (TW), Android 4.4.2 (TW)

G900F: Android 4.4.2 (TW)

Right, lets get started.

First, the easy part. For the ease of this guide I'll be using ES File Explorer to make changes, but if you are comfortable with ADB push/pull you can use that, or any other root file explorer.

Connect your phone to your computer, making sure USB debugging is enabled (Settings > Developer Options > USB Debugging)

Run ADB with your device connected (Navigate to the directory it's installed in in a command prompt window). If you don't have it, download this and install it.

Now, issue the following commands:

adb shell After a second you should see shell@klte:/ $

Now, type su and hit enter. You will likely have to grant superuser access on your device.

Now you can issue mount -o remount,rw /system to allow us to save the modifications we make back to the system partition.

Hit Control-C on the command prompt window to exit ADB, but leave the window open and the device connected.

Back on the phone, open ES File Explorer. If you haven't already you will need to go to Tools and enable 'Root Explorer' and grant superuser access.

Now, navigate to the root directory by tapping the directory you are in to bring up the history window, then tapping '/ Device'. Then go to system/usr/keylayout

Edit the file 'Generic.kl' by tapping it, opening as text (Use ES Note Editor), tapping the three dots in the top right and selecting 'Edit'

Scroll just past halfway to find the following section, And edit the line in red to MENU (It should originally be APP_SWITCH)

key 224 BRIGHTNESS_DOWN
key 225 BRIGHTNESS_UP
key 226 HEADSETHOOK

# samsung
key 252 USER

# samsung
[COLOR="Red"]key 254 MENU[/COLOR]

key 256 BUTTON_1
key 257 BUTTON_2
key 258 BUTTON_3
key 259 BUTTON_4

Save the file and repeat the above steps to edit the file 'gpio-keys.kl' changing the same thing at the bottom of the file (Changing APP_SWITCH to MENU).

Now for the more difficult part. Back on your PC, in the command prompt window type adb pull /system/framework/android.policy.jar you should now have a file called 'android.policy.jar' in your ADB directory. Copy it to a new folder somewhere on your computer.

In the folder with android.policy.jar, place smali-X.X.X.jar and baksmali-X.X.X.jar. Links to these files are at the top of the post.

Now, using WinRar or similar, extract the file 'classes.dex' from android.policy.jar and place it in the same folder as the jar itself.

Shift-rightclick in the folder holding smali, baksmali and classes.dex and select 'Open command window here'. This should open a new CMD window, in it type java -jar baksmali-2.0.5.jar -o out classes.dex (If you have a different version of baksmali, change the command accordingly)

You should now have a new folder called out. Navigate to \out\com\android\internal\policy\impl and then edit the file 'PhoneWindowManager.smali' with your favourite text editor. I recommend Notepad++ but you could get away with Notepad.

Now, there are a few different things that might need to be changed here. Online I have found many recommendations that say to change a line with if-ne v2, v5, :cond_6 however this did not work for me. If the first option does not work, try the second.

First, search for a section that looks like this:

iget v2, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mLongPressOnHomeBehavior:I

if-eqz v2, :cond_0

iput-boolean v5, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mHomeConsumed:Z

const/4 v2, 0x0

invoke-virtual {p0, v2, v4, v4}, Lcom/android/internal/policy/impl/PhoneWindowManager;->performHapticFeedbackLw(Landroid/view/WindowManagerPolicy$WindowState;IZ)Z

iget v2, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mLongPressOnHomeBehavior:I

[COLOR="red"]if-ne v2, v5, :cond_6[/COLOR]

invoke-direct {p0}, Lcom/android/internal/policy/impl/PhoneWindowManager;->toggleRecentApps()V

and remove the line that is highlighted in red. If you don't have this line, don't worry, neither did I. Instead, look for this:

iput-boolean v2, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mHomeConsumed:Z

const/4 v0, 0x0

invoke-virtual {p0, v0, v1, v1}, Lcom/android/internal/policy/impl/PhoneWindowManager;->performHapticFeedbackLw(Landroid/view/WindowManagerPolicy$WindowState;IZ)Z

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

[COLOR="red"]if-ne v0, v2, :cond_1d[/COLOR]

invoke-direct {p0}, Lcom/android/internal/policy/impl/PhoneWindowManager;->toggleRecentApps()V

goto :goto_a

And remove the red line. For me, it was on line #2547.

If you do not have either of these lines, PM me or reply with your PhoneWindowManager.smali along with what rom, version and variant of the S5 you have and I'll try to locate the correct line for you, then add it to the OP.

Now you need to recompile it and load it back on to your phone. To do this, save the PhoneWindowManager.smali if you haven't already. Now back out of the folders you are in until you are in the folder with out, Baksmali, smali, etc in it.

Rename the file 'classes.dex' to 'classes.dex.bak', this way we can restore from a backup if anything goes wrong.

Now open a command window again (Either use the one you had from before or open a new one with Shift-rightclick > Open new command window) and type java -jar smali-2.0.5.jar out -o classes.dex (If you have a different version of smali, change the command accordingly)

This should create a new classes.dex file, you can now open the android.policy.jar with WinRar again, and replace the classes.dex inside with the one that you just recompiled. Copy this android.policy.jar file back on to your phone, placing it on the root of the SD card like you would any other file. It is possible to use ADB push, however I had issues with it.

Back on the phone in ES File Explorer, go to your SD card where you just pasted the android.policy.jar and copy it. Then go to /system/framework and remove the existing android.policy.jar before pasting the new one.

Done! Reboot into recovery, wipe cache, boot your phone. It WILL take some time to boot back up, possibly upwards of 10-15min, and will say 'Android is upgrading' upon first boot. Don't take the battery out or force reboot the phone unless you are sure it's not working.

If anyone has any issues, let me know in a reply and I'll try to help. Likewise, if your phone no longer boots or you want to restore it to how it was before, I'll create an undo tutorial if required.

If I've missed anything or made some obvious typos, correct me :)

Credits:

In no way did I come up with all this without help, I spent a fair bit of time looking around to find all this information. If anyone thinks I've ripped off their work here, tell me and I'll give due credit.