Happening now! New Honor Phone Launch
FORUMS
Remove All Ads from XDA

[HOW-TO][MOD][MIUI 4] 3-way Reboot Options

1,392 posts
Thanks Meter: 958
 
By kong, Senior Member on 3rd June 2012, 10:07 AM
Post Reply Email Thread

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


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

Code:
MiuiGlobalActions$9.smali
MiuiGlobalActions$9$1.smali
MiuiGlobalActions$9$2.smali
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

Code:
.end annotation


# static fields
.field protected static rebootMode:I

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


# instance fields
.field private mIconResId:I
Then add another highlighted code after # direct methods and before .method protected constructor <init>(II)V

Code:
# direct methods
.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

.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:
Code:
grep -l reboot *.smali
If you're using Command Prompt, open it, go to the same directory and use the following command instead:
Code:
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.
Code:
MiuiGlobalActions$3.smali
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:
Code:
invoke-static {v0, v1, v2}, Lcom/android/internal/app/ShutdownThread;->reboot(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
The Following 13 Users Say Thank You to kong For This Useful Post: [ View ] Gift kong Ad-Free
 
 
3rd June 2012, 10:07 AM |#2  
kong's Avatar
OP Senior Member
Thanks Meter: 958
 
More
Reserved just in case
The Following 2 Users Say Thank You to kong For This Useful Post: [ View ] Gift kong Ad-Free
4th June 2012, 08:55 PM |#3  
Member
Thanks Meter: 3
 
More
Thanks you, kong :D
5th June 2012, 02:39 AM |#4  
toqpuk's Avatar
Member
Flag London
Thanks Meter: 6
 
More
kong
Thank any way/
Is it possible make zip file to install this menu through recovery? Be cause I do not have idea how to work with smali files, I think I am not alone how to operate with it/ =)
5th June 2012, 03:57 AM |#5  
kong's Avatar
OP Senior Member
Thanks Meter: 958
 
More
Quote:
Originally Posted by toqpuk

kong
Thank any way/
Is it possible make zip file to install this menu through recovery? Be cause I do not have idea how to work with smali files, I think I am not alone how to operate with it/ =)

It's possible to provide a flashable zip for a specific version of MIUI for a specific device, but not a generic one that can be used by all devices since android.policy.jar keeps changing in each MIUI releases.

That's why I wrote a "guide" so anyone who has those "prerequisites" can apply it to the appropriate android.policy.jar
The Following User Says Thank You to kong For This Useful Post: [ View ] Gift kong Ad-Free
7th June 2012, 09:29 PM |#6  
siulmagic's Avatar
Senior Member
Flag Bridgeport
Thanks Meter: 2,529
 
Donate to Me
More
I tried this on my miui v4 rom port, but it dint work, when ever i long press my power button miui reboots. here's my edited android.policy.jar.

http://www.mediafire.com/?lw7y57yk25drdy4
7th June 2012, 10:52 PM |#7  
broodplank1337's Avatar
Recognized Developer
Flag Nijmegen
Thanks Meter: 10,197
 
Donate to Me
More
If someone would like to add Quick Reboot to the menu:

Create a new file, for example: GlobalActions$12.smali:

Code:
.class Lcom/android/internal/policy/impl/GlobalActions$12;
.super Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;
.source "GlobalActions.java"

# annotations
.annotation system Ldalvik/annotation/EnclosingMethod;
    value = Lcom/android/internal/policy/impl/GlobalActions;->createDialog()Landroid/app/AlertDialog;
.end annotation


.annotation system Ldalvik/annotation/InnerClass;
    accessFlags = 0x0
    name = null
.end annotation


# instance fields
.field final synthetic this$0:Lcom/android/internal/policy/impl/GlobalActions;


# direct methods
.method constructor <init>(Lcom/android/internal/policy/impl/GlobalActions;II)V
    .registers 4
    .parameter
    .parameter "x0"
    .parameter "x1"

    .prologue
    .line 267
    iput-object p1, p0, Lcom/android/internal/policy/impl/GlobalActions$12;->this$0:Lcom/android/internal/policy/impl/GlobalActions;

    invoke-direct {p0, p2, p3}, Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;-><init>(II)V

    return-void
.end method


# virtual methods
.method public onPress()V
    .locals 6

    .prologue
    .line 142
    invoke-static {}, Ljava/lang/Runtime;->getRuntime()Ljava/lang/Runtime;

    move-result-object v3

    .line 143
    .local v3, localRuntime:Ljava/lang/Runtime;
    const/4 v4, 0x4

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

    .line 144
    .local v0, arrayOfString2:[Ljava/lang/String;
    const/4 v4, 0x0

    const-string v5, "pkill"

    aput-object v5, v0, v4

    .line 145
    const/4 v4, 0x1

    const-string v5, "-TERM"

    aput-object v5, v0, v4

    .line 146
    const/4 v4, 0x2

    const-string v5, "-f"

    aput-object v5, v0, v4

    .line 147
    const/4 v4, 0x3

    const-string v5, "system_server"

    aput-object v5, v0, v4

    .line 151
    :try_start_0
    invoke-virtual {v3, v0}, Ljava/lang/Runtime;->exec([Ljava/lang/String;)Ljava/lang/Process;
    :try_end_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v2

    .line 158
    :goto_0
    return-void

    .line 153
    :catch_0
    move-exception v1

    .line 156
    .local v1, e:Ljava/io/IOException;
    invoke-virtual {v1}, Ljava/io/IOException;->printStackTrace()V

    goto :goto_0
.end method

.method public showBeforeProvisioning()Z
    .locals 1

    .prologue
    .line 162
    const/4 v0, 0x1

    return v0
.end method

.method public showDuringKeyguard()Z
    .locals 1

    .prologue
    .line 167
    const/4 v0, 0x1

    return v0
.end method
called like this:

Code:
const/4 v1, 0x4

    new-instance v2, Lcom/android/internal/policy/impl/GlobalActions$12;

    const v3, 0x1080410

    const v4, 0x1040523

    invoke-direct {v2, p0, v3, v4}, Lcom/android/internal/policy/impl/GlobalActions$12;->(Lcom/android/internal/policy/impl/GlobalActions;II)V

    aput-object v2, v0, v1
It requires a new busybox installation to succeed
The Following 2 Users Say Thank You to broodplank1337 For This Useful Post: [ View ]
8th June 2012, 05:39 AM |#8  
kong's Avatar
OP Senior Member
Thanks Meter: 958
 
More
Quote:
Originally Posted by siulmagic

I tried this on my miui v4 rom port, but it dint work, when ever i long press my power button miui reboots. here's my edited android.policy.jar.

http://www.mediafire.com/?lw7y57yk25drdy4

I believe you forgot to modify this line in MiuiGlobalActions.smali

Code:
invoke-direct {v1, p0, v2, v3}, Lcom/android/internal/policy/impl/MiuiGlobalActions$3;-><init>(Lcom/android/internal/policy/impl/MiuiGlobalActions;II)V
17th June 2012, 06:19 PM |#9  
AldoSebastian's Avatar
Senior Member
Flag Denpasar - Yogyakarta
Thanks Meter: 394
 
More
Quote:
Originally Posted by kong

I believe you forgot to modify this line in MiuiGlobalActions.smali

Code:
invoke-direct {v1, p0, v2, v3}, Lcom/android/internal/policy/impl/MiuiGlobalActions$3;-><init>(Lcom/android/internal/policy/impl/MiuiGlobalActions;II)V

Thanks for the tutorial.... It's work great.... lucky me there is no file use $9.... so I just copy the file and edit some smali.... thanks sir

Sent from my GT-S5670 using Tapatalk 2
The Following User Says Thank You to AldoSebastian For This Useful Post: [ View ] Gift AldoSebastian Ad-Free
18th June 2012, 07:23 PM |#10  
kong's Avatar
OP Senior Member
Thanks Meter: 958
 
More
Quote:
Originally Posted by AldoSebastian

Thanks for the tutorial.... It's work great.... lucky me there is no file use $9.... so I just copy the file and edit some smali.... thanks sir

Thanks for confirming that it works
22nd June 2012, 07:01 PM |#11  
siulmagic's Avatar
Senior Member
Flag Bridgeport
Thanks Meter: 2,529
 
Donate to Me
More
can you guys check if this works on miui 2.6.22, i just tried it and the 3 way reboot menu does not come up, it just reboots the device. i dont think this is compatible anymore.[COLOR="Silver"]

---------- Post added at 02:01 PM ---------- Previous post was at 01:58 PM ----------
disregard i edited the wrong globalpressaction smali
Post Reply Subscribe to Thread

Tags
how-to, miui, mod
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes