[Android Software/Hacking General [Developers Only]] kong:
This is a mod that will add three options to the reboot menu of MIUI 4. It is based on the 4-way reboot mod for MIUI 2.x by roenano with my modifications. In summary, this is what you'll get after following the how-to:

​

- a deodexed MIUI 4 ROM

- basic knowledge of how to use smali/baksmali tools

- basic knowledge of how smali code works is a plus

- a good text editor e.g. Notepad++ or Sublime Text 2

- some "ROM modder" intuition and ability to adapt when things do not go exactly like what the how-to says :D

We're going to add and modify some smali files in android.policy.jar to redirect the original "Reboot" menu to a custom class that will display the reboot options and perform the action according to what the user has selected.

We'll have to extract the smali from android.policy.jar. I'm going to assume that you already know how to use smali/baksmali. The only suggestion is you should specify the output directory when using baksmali to prevent some confusion -- especially when you're doing many things in the same working directory. The command I normally use when decompiling classes.dex extracted from android.policy.jar is as follows:

baksmali -o android.policy classes.dex

All smali files will be put in android.policy directory. After you finished editing you can issue the following command to recompile it back to classes.dex:

smali -o classes.dex android.policy

Let's assume we're working in android.policy directory from now on.

We'll start with the easy part by adding some smali files (custom classes) to the package. You can download the files here. The zip contains essentially three files as follows:

[FONT="Courier New"]MiuiGlobalActions$9.smali[/FONT]
[FONT="Courier New"]MiuiGlobalActions$9$1.smali[/FONT]
[FONT="Courier New"]MiuiGlobalActions$9$2.smali[/FONT]

First, take a look in com/android/internal/policy/impl/ directory and see if there is already a file named MiuiGlobalActions$9.smali or not. If there is no such file then you're lucky, just copy over the three files into the mentioned directory.

But if the file already exists then we'll have to change our file names so it won't override what's already there. We can do it by renaming the three above files and change $9 to the next available number e.g. $10 (actually any unused number will work, just make sure you use the same number in all three files) Then open each renamed file and replace every occurrences of MiuiGlobalActions$9 with MiuiGlobalActions$10 (or the number you used). A simple "search/replace all" in the text editor should do the trick. After that, copy over the three files into the mentioned directory.

Next we'll have to edit two smali files in order to get it working.

com/android/internal/policy/impl/MiuiGlobalActions$SinglePressAction.smali

Add the highlighted code just after .end annotation and before # instance fields

.end annotation

[COLOR="Red"]# static fields
.field protected static rebootMode:I

.field protected static final rebootOptions:[Ljava/lang/String;[/COLOR]

# instance fields
.field private mIconResId:I

Then add another highlighted code after # direct methods and before .method protected constructor <init>(II)V

# direct methods
[COLOR="Red"].method static constructor <clinit>()V
.registers 3

const/4 v0, 0x3

new-array v0, v0, [Ljava/lang/String;

const/4 v1, 0x0

const-string v2, "Normal"

aput-object v2, v0, v1

const/4 v1, 0x1

const-string v2, "Recovery"

aput-object v2, v0, v1

const/4 v1, 0x2

const-string v2, "Bootloader"

aput-object v2, v0, v1

sput-object v0, Lcom/android/internal/policy/impl/MiuiGlobalActions$SinglePressAction;->rebootOptions:[Ljava/lang/String;

return-void
.end method[/COLOR]

.method protected constructor <init>(II)V
.registers 3
.parameter "iconResId"

Then save the file. The above modifications will populate the options array used by the three files we copied earlier. Next we'll redirect the original "Reboot" menu to our custom class, this can be done by editing:

com/android/internal/policy/impl/MiuiGlobalActions.smali

In order to know which line of code to change, we'll have to find which smali is being called when the user select the original "Reboot" menu.

If you're using Linux or Cygwin, open the terminal, go to com/android/internal/policy/impl/ directory and use the following command:

grep -l reboot *.smali

If you're using Command Prompt, open it, go to the same directory and use the following command instead:

findstr /M reboot *.smali

The output should be similar to the following. There will be a file named MiuiGlobalActions$#.smali where # is some number different from the files we added earlier. In my case this number is 3.

[B]MiuiGlobalActions$3.smali[/B]
MiuiGlobalActions$9$1.smali
MiuiGlobalActions$9$2.smali
MiuiGlobalActions$9.smali
MiuiGlobalActions$SinglePressAction.smali

To make sure it's the right file that handle the reboot command, open MiuiGlobalActions$3.smali and you'll see a line similar to this:

invoke-static {v0, v1, v2}, Lcom/android/internal/app/[B]ShutdownThread;->reboot[/B](Landroid/content/Context;Ljava/lang/String;Z)V

Once we know the file name, the modification is super easy. Just search and replace MiuiGlobalActions$3 with MiuiGlobalActions$9 in com/android/internal/policy/impl/MiuiGlobalActions.smali. Remember to change $9 to the number you used if you changed the three files' names. Note that there should be only two instances to be replaced. After you finish, save the file.

That's it. Now you'll have to recompile the smali code to classes.dex, put it back into android.policy.jar, push the jar onto the phone and reboot ;)