[Xperia Arc Themes and Apps] BDFreak:
Happy New Year...

This is my first tutorial of 2014. Today I will teach

you how to add Reboot and Recovery option in Power Menu.

Make sure you have a basic knowledge on how to compile/decompile .apk/.jar files.

framework-res.apk

Decompile framework-res.apk

[*]Navigate to framework-res.apk\res\drawable-hdpi

[*]Extract all the files from PNG folder (Download From Attachment)

[*]Navigate to framework-res.apk\res\values

[*]Open strings.xml file in file editor

[*]Add these line at the end

<string name="reboot">Reboot</string>
<string name="reboot_progress">Rebooting…</string>
<string name="reboot_confirm">Your phone will reboot</string>
<string name="recovery">Recovery</string>
<string name="recovery_progress">Rebooting into recovery…</string>
<string name="recovery_confirm">Your phone will reboot into recovery</string>

[*]Save the file

[*]Recompile your framework-res.apk

[*]Decompile framework-res.apk which you have recompiled a moment ago

[*]Navigate to framework-res.apk\res\values

[*]Open public.xml file in file editor

framework.jar

Decompile framework.jar

[*]Navigate to framework.jar\smali\com\android\internal\app

[*]Open ShutdownThread.smali file in file editor

[*]Search for .field private static mReboot:Z and add the red line only

.field private static final TAG:Ljava/lang/String; = "ShutdownThread"

[COLOR="Red"].field public static mReboot:I[/COLOR]

.field private static mReboot:Z

[*]Search for .local v1, pd:Landroid/app/ProgressDialog; and add the red lines only

.line 184
.local v1, pd:Landroid/app/ProgressDialog;
[COLOR="Red"]sget v2, Lcom/android/internal/app/ShutdownThread;->mReboot:I

if-eq v2, v5, :cond_1

if-nez v2, :cond_2[/COLOR]

const v2, 0x104014a

[COLOR="Red"]goto :goto_1

:cond_1
const v2, name="reboot"

goto :goto_1

:cond_2
const v2, name="recovery"

:goto_1[/COLOR]
invoke-virtual {p0, v2}, Landroid/content/Context;->getText(I)Ljava/lang/CharSequence;

move-result-object v2

[*]Search for invoke-virtual {v1, v2}, Landroid/app/ProgressDialog;->setTitle(Ljava/lang/CharSequence;)V and add the red lines only

move-result-object v2

invoke-virtual {v1, v2}, Landroid/app/ProgressDialog;->setTitle(Ljava/lang/CharSequence;)V

.line 185
[COLOR="Red"]sget v2, Lcom/android/internal/app/ShutdownThread;->mReboot:I

if-eq v2, v5, :cond_3

if-nez v2, :cond_4[/COLOR]

const v2, 0x104014e

[COLOR="Red"]goto :goto_2

:cond_3
const v2, name="reboot_progress"

goto :goto_2

:cond_4
const v2, name="recovery_progress"

:goto_2[/COLOR]
invoke-virtual {p0, v2}, Landroid/content/Context;->getText(I)Ljava/lang/CharSequence;

move-result-object v2

[*]Search for .catch Ljava/lang/SecurityException; {:try_start_1 .. :try_end_1} :catch_0 and change the blue lines only

invoke-virtual {v2}, Landroid/os/PowerManager$WakeLock;->acquire()V
:try_end_1
.catch Ljava/lang/SecurityException; {:try_start_1 .. :try_end_1} :catch_0

.line 208
[COLOR="Blue"]:goto_3[/COLOR]
sget-object v2, Lcom/android/internal/app/ShutdownThread;->sInstance:Lcom/android/internal/app/ShutdownThread;

iput-object v6, v2, Lcom/android/internal/app/ShutdownThread;->mScreenWakeLock:Landroid/os/PowerManager$WakeLock;

.line 209
sget-object v2, Lcom/android/internal/app/ShutdownThread;->sInstance:Lcom/android/internal/app/ShutdownThread;

iget-object v2, v2, Lcom/android/internal/app/ShutdownThread;->mPowerManager:Landroid/os/PowerManager;

invoke-virtual {v2}, Landroid/os/PowerManager;->isScreenOn()Z

move-result v2

[COLOR="Blue"]if-eqz v2, :cond_5[/COLOR]

.line 211
:try_start_2

[*]Search for .catch Ljava/lang/SecurityException; {:try_start_2 .. :try_end_2} :catch_1 and change the blue lines only

:try_end_2
.catch Ljava/lang/SecurityException; {:try_start_2 .. :try_end_2} :catch_1

.line 222
[COLOR="Blue"]:cond_5
:goto_4[/COLOR]
sget-object v2, Lcom/android/internal/app/ShutdownThread;->sInstance:Lcom/android/internal/app/ShutdownThread;

new-instance v3, Lcom/android/internal/app/ShutdownThread$2;

[*]Search for .end local v0 #e:Ljava/lang/SecurityException; and change the blue lines only

iput-object v6, v2, Lcom/android/internal/app/ShutdownThread;->mCpuWakeLock:Landroid/os/PowerManager$WakeLock;

[COLOR="Blue"]goto :goto_3[/COLOR]

.line 215
.end local v0 #e:Ljava/lang/SecurityException;
:catch_1
move-exception v0

.line 216
.restart local v0 #e:Ljava/lang/SecurityException;
const-string v2, "ShutdownThread"

const-string v3, "No permission to acquire wake lock"

invoke-static {v2, v3, v0}, Landroid/util/Log;->w(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

.line 217
sget-object v2, Lcom/android/internal/app/ShutdownThread;->sInstance:Lcom/android/internal/app/ShutdownThread;

iput-object v6, v2, Lcom/android/internal/app/ShutdownThread;->mScreenWakeLock:Landroid/os/PowerManager$WakeLock;

[COLOR="Blue"]goto :goto_4[/COLOR]
.end method

.method public static reboot(Landroid/content/Context;Ljava/lang/String;Z)V

[*]Search for .method public static rebootOrShutdown(ZLjava/lang/String;)V and change the blue line only

.end method

.method public static rebootOrShutdown(ZLjava/lang/String;)V
.locals 5
.parameter "reboot"
.parameter "reason"

.prologue
.line 403
[COLOR="Blue"]if-eqz p0, :cond_3[/COLOR]

.line 404
const-string v2, "ShutdownThread"

[*]Search for invoke-static {p1}, Landroid/os/Power;->reboot(Ljava/lang/String;)V and add the red lines and change the blue lines only

:try_start_0
invoke-static {p1}, Landroid/os/Power;->reboot(Ljava/lang/String;)V
:try_end_0
[COLOR="Blue"].catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_1[/COLOR]

.line 428
:goto_0
const-string v2, "ShutdownThread"

const-string v3, "Performing low-level shutdown..."

invoke-static {v2, v3}, Landroid/util/Log;->i(Ljava/lang/String;Ljava/lang/String;)I

[COLOR="Red"]sget v1, Lcom/android/internal/app/ShutdownThread;->mReboot:I

const/4 v2, 0x1

if-eq v1, v2, :cond_0

const/4 v2, 0x2

if-eq v1, v2, :cond_1[/COLOR]

.line 429
invoke-static {}, Landroid/os/Power;->shutdown()V

.line 430
return-void

[COLOR="Red"]:cond_0
const-string/jumbo v4, "now"

invoke-static {v4}, Landroid/os/Power;->reboot(Ljava/lang/String;)V

return-void

:cond_1
:try_start_1
new-instance v1, Ljava/io/File;

const-string v4, "/cache/recovery/boot"

invoke-direct {v1, v4}, Ljava/io/File;-><init>(Ljava/lang/String;)V

.line 442
.restart local v1
invoke-virtual {v1}, Ljava/io/File;->exists()Z

move-result v4

if-nez v4, :cond_2

.line 443
invoke-virtual {v1}, Ljava/io/File;->createNewFile()Z
:try_end_1
.catch Ljava/io/IOException; {:try_start_1 .. :try_end_1} :catch_0

:catch_0
:cond_2
const-string/jumbo v4, "recovery"

invoke-static {v4}, Landroid/os/Power;->reboot(Ljava/lang/String;)V

return-void[/COLOR]

.line 407
[COLOR="Blue"]:catch_1[/COLOR]
move-exception v0

.line 408
.local v0, e:Ljava/lang/Exception;
const-string v2, "ShutdownThread"

[*]Search for .end local v0 #e:Ljava/lang/Exception; and change the blue lines only

.line 412
.end local v0 #e:Ljava/lang/Exception;
[COLOR="Blue"]:cond_3[/COLOR]
new-instance v1, Landroid/os/Vibrator;

invoke-direct {v1}, Landroid/os/Vibrator;-><init>()V

.line 414
.local v1, vibrator:Landroid/os/Vibrator;
const-wide/16 v2, 0x1f4

[COLOR="Blue"]:try_start_2[/COLOR]
invoke-virtual {v1, v2, v3}, Landroid/os/Vibrator;->vibrate(J)V
[COLOR="Blue"]:try_end_2
.catch Ljava/lang/Exception; {:try_start_2 .. :try_end_2} :catch_3[/COLOR]

.line 422
:goto_1
const-wide/16 v2, 0x1f4

[COLOR="Blue"]:try_start_3[/COLOR]
invoke-static {v2, v3}, Ljava/lang/Thread;->sleep(J)V
[COLOR="Blue"]:try_end_3
.catch Ljava/lang/InterruptedException; {:try_start_3 .. :try_end_3} :catch_2[/COLOR]

goto :goto_0

.line 423
[COLOR="Blue"]:catch_2[/COLOR]
move-exception v2

goto :goto_0

.line 415
[COLOR="Blue"]:catch_3[/COLOR]
move-exception v0

.line 417
.restart local v0 #e:Ljava/lang/Exception;

[*]Search for .local v1, longPressBehavior:I and change the blue lines only

.line 106
.local v1, longPressBehavior:I
const/4 v3, 0x2

[COLOR="Blue"]if-ne v1, v3, :cond_4[/COLOR]

const v2, 0x1040150

.line 110
.local v2, resourceId:I
:goto_1
const-string v3, "ShutdownThread"

new-instance v4, Ljava/lang/StringBuilder;

invoke-direct {v4}, Ljava/lang/StringBuilder;-><init>()V

const-string v5, "Notifying thread to start shutdown longPressBehavior="

invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

move-result-object v4

invoke-virtual {v4, v1}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

move-result-object v4

invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

move-result-object v4

invoke-static {v3, v4}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

.line 112
[COLOR="Blue"]if-eqz p1, :cond_7[/COLOR]

.line 113
new-instance v0, Lcom/android/internal/app/ShutdownThread$CloseDialogReceiver;

[*]Search for invoke-direct {v3, p0}, Landroid/app/AlertDialog$Builder;-><init>(Landroid/content/Context;)V and add the red lines only

new-instance v3, Landroid/app/AlertDialog$Builder;

invoke-direct {v3, p0}, Landroid/app/AlertDialog$Builder;-><init>(Landroid/content/Context;)V

[COLOR="Red"]const v5, 0x1

sget v4, Lcom/android/internal/app/ShutdownThread;->mReboot:I

if-eq v4, v5, :cond_2

if-nez v4, :cond_3[/COLOR]

const v4, 0x104014a

[COLOR="Red"]goto :goto_2

:cond_2
const v4, name="reboot"

goto :goto_2

:cond_3
const v4, name="recovery"

:goto_2[/COLOR]
invoke-virtual {v3, v4}, Landroid/app/AlertDialog$Builder;->setTitle(I)Landroid/app/AlertDialog$Builder;

move-result-object v3

[*]Search for invoke-virtual {v3}, Landroid/app/AlertDialog;->show()V and add the red lines and change the blue lines only

sget-object v3, Lcom/android/internal/app/ShutdownThread;->sConfirmDialog:Landroid/app/AlertDialog;

invoke-virtual {v3}, Landroid/app/AlertDialog;->show()V

[COLOR="Blue"]goto/16 :goto_0[/COLOR]

.line 102
.end local v0 #closer:Lcom/android/internal/app/ShutdownThread$CloseDialogReceiver;
.end local v1 #longPressBehavior:I
.end local v2 #resourceId:I
:catchall_0
move-exception v3

:try_start_1
monitor-exit v4
:try_end_1
.catchall {:try_start_1 .. :try_end_1} :catchall_0

throw v3

.line 106
.restart local v1 #longPressBehavior:I
[COLOR="Blue"]:cond_4[/COLOR]
[COLOR="Red"]const v3, 0x1

sget v2, Lcom/android/internal/app/ShutdownThread;->mReboot:I

if-eq v2, v3, :cond_5

if-nez v2, :cond_6[/COLOR]

const v2, 0x104014f

[COLOR="Blue"]goto/16 :goto_1[/COLOR]

[COLOR="Red"]:cond_5
const v2, name="reboot_confirm"

goto/16 :goto_1

:cond_6
const v2, name="recovery_confirm"

goto/16 :goto_1[/COLOR]

.line 132
.restart local v2 #resourceId:I
[COLOR="Blue"]:cond_7[/COLOR]
invoke-static {p0}, Lcom/android/internal/app/ShutdownThread;->beginShutdownSequence(Landroid/content/Context;)V

goto/16 :goto_0
.end method

[*]Now you have to find the names below

name="reboot"
name="recovery"
name="reboot_progress"
name="recovery_progress"
name="reboot_confirm"
name="recovery_confirm"

[*]You have to replace these name with hex ids from public.xml which is already opened in file editor

[*]For example search for name="reboot" in public.xml file

[*]In my case I have got

<public type="string" name="reboot" id="[COLOR="Blue"]0x01040548[/COLOR]" />

[*]The blue marked part is hex. Copy the hex and remove the 3rd digit. So 0x01040548 will be 0x1040548

[*]Now search for name="reboot" in ShutdownThread.smali file and replace name="reboot" with 0x1040548

[*]Do the same for other names too

[*]Save the file

[*]Recompile your framework.jar

android.policy.jar

Decompile android.policy.jar

[*]Navigate to android.policy.jar\smali\com\android\internal\policy\impl

[*]Extract all the files from SMALI folder (Download From Attachment)

[*]Open GlobalActions$2.smali file in file editor

[*]Search for invoke-static {v0}, Lcom/android/internal/policy/impl/GlobalActions;->access$100(Lcom/android/internal/policy/impl/GlobalActions;)Landroid/content/Context; and add the red lines only

#getter for: Lcom/android/internal/policy/impl/GlobalActions;->mContext:Landroid/content/Context;
invoke-static {v0}, Lcom/android/internal/policy/impl/GlobalActions;->access$100(Lcom/android/internal/policy/impl/GlobalActions;)Landroid/content/Context;

move-result-object v0

const/4 v1, 0x1

[COLOR="Red"]const/4 p0, 0x0

sput p0, Lcom/android/internal/app/ShutdownThread;->mReboot:I[/COLOR]

invoke-static {v0, v1}, Lcom/android/internal/app/ShutdownThread;->shutdown(Landroid/content/Context;Z)V

.line 171
return-void
.end method

[*]Save the file

[*]Open GlobalActions.smali file in file editor

[*]Search for .method private createDialog()Landroid/app/AlertDialog; and change the blue lines only

.end method

.method private createDialog()Landroid/app/AlertDialog;
[COLOR="Blue"].locals 12[/COLOR]

.prologue
const/4 v9, 0x1

[*]Search for invoke-direct {v1, p0, v2, v3}, Lcom/android/internal/policy/impl/GlobalActions$2;-><init>(Lcom/android/internal/policy/impl/GlobalActions;II)V and add the red lines only

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

invoke-virtual {v0, v1}, Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z

[COLOR="Red"]iget-object v0, p0, Lcom/android/internal/policy/impl/GlobalActions;->mContext:Landroid/content/Context;

invoke-virtual {v0}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

move-result-object v0

const-string v1, "reboot"

const-string v2, "string"

const-string v3, "android"

invoke-virtual {v0, v1, v2, v3}, Landroid/content/res/Resources;->getIdentifier(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I

move-result v10

if-nez v10, :cond_0

const-string v1, "reboot_system"

invoke-virtual {v0, v1, v2, v3}, Landroid/content/res/Resources;->getIdentifier(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I

move-result v10

if-eqz v10, :cond_1

:cond_0
const-string v1, "ic_lock_reboot"

const-string v2, "drawable"

invoke-virtual {v0, v1, v2, v3}, Landroid/content/res/Resources;->getIdentifier(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I

move-result v11

if-eqz v11, :cond_1

iget-object v0, p0, Lcom/android/internal/policy/impl/GlobalActions;->mItems:Ljava/util/ArrayList;

new-instance v1, Lcom/android/internal/policy/impl/GlobalActions$7;

invoke-direct {v1, p0, v11, v10}, Lcom/android/internal/policy/impl/GlobalActions$7;-><init>(Lcom/android/internal/policy/impl/GlobalActions;II)V

invoke-virtual {v0, v1}, Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z

:cond_1
iget-object v0, p0, Lcom/android/internal/policy/impl/GlobalActions;->mContext:Landroid/content/Context;

invoke-virtual {v0}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

move-result-object v0

const-string v1, "recovery"

const-string v2, "string"

const-string v3, "android"

invoke-virtual {v0, v1, v2, v3}, Landroid/content/res/Resources;->getIdentifier(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I

move-result v10

if-nez v10, :cond_2

const-string v1, "recovery_system"

invoke-virtual {v0, v1, v2, v3}, Landroid/content/res/Resources;->getIdentifier(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I

move-result v10

if-eqz v10, :cond_3

:cond_2
const-string v1, "ic_lock_recovery"

const-string v2, "drawable"

invoke-virtual {v0, v1, v2, v3}, Landroid/content/res/Resources;->getIdentifier(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I

move-result v11

if-eqz v11, :cond_3

iget-object v0, p0, Lcom/android/internal/policy/impl/GlobalActions;->mItems:Ljava/util/ArrayList;

new-instance v1, Lcom/android/internal/policy/impl/GlobalActions$8;

invoke-direct {v1, p0, v11, v10}, Lcom/android/internal/policy/impl/GlobalActions$8;-><init>(Lcom/android/internal/policy/impl/GlobalActions;II)V

invoke-virtual {v0, v1}, Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z[/COLOR]

.line 183
[COLOR="Red"]:cond_3[/COLOR]
iget-object v0, p0, Lcom/android/internal/policy/impl/GlobalActions;->mItems:Ljava/util/ArrayList;

iget-object v1, p0, Lcom/android/internal/policy/impl/GlobalActions;->mAirplaneModeOn:Lcom/android/internal/policy/impl/GlobalActions$ToggleAction;

[*]Save the file

[*]Recompile your android.policy.jar

Please Note :

Take backup before doing anything.

Use Notepad++ to edit files.

Please read the tutorial properly befor editing files.

If you found any mistake in this tutorial then please let me know.