[Galaxy S 5 Android Development (Snapdragon)] daxgirl:
Hello guys!

This guide is a small addendum to the popular mod that's included in almost every tw rom today - 4 way reboot.

As you all know for now the 4 way reboot has an array of items that are hard coded into the smali. So... no matter what locale you're on, it will always be in english. You can of course translate it in the smali (let's say to italian), but then in all the locales it will be in italian.

I don't like hard coding. So I will share with you an easy and elegant way to bring this mod to the way android is intended to be. We will outsource the char sequence back where those items belong - to strings in resources. So when you switch to a different locale, your reboot menu will show in that locale's language. Provided you modified that locale like we will do now...

Preliminary requiremtns:

1. Basic knowledge in compiling and decompiling of apks

2. Text/xml editor

3. About 10 mins of your time

4. Working 4-way reboot for tw roms (use this guide for example)

5. A deodexed TW rom

So let's get cracking:

1. Decompile framework-res.apk for your build. Navigate to res/values/strings.xml

Scroll to the bottom and right before the line that says </resources> add a new line. We will add a new string.

(btw really no need to do that at the bottom of the screen - you can add anywhere).

I just like all the strings I am adding to be at the bottom - easier to find

2. So we do something like this...

<string name="reboot_title">Advanced reboot menu</string>

This will be the title of our reboot menu. You can choose any name for the string and have any content. Like "Bob's rom reboot menu"...

Save strings.xml

3. Navigate back to values folder and open arrays.xml

Scroll down and just like we did with strings.xml, we will add a new array of strings.

Like so...

<string-array name="restart_menu">
<item>Reboot Phone</item>
<item>Fast Boot</item>
<item>Download Mode</item>
<item>Recovery Mode</item>
</string-array>

You can choose any other name for your array or change the names of the items. BUT YOU CANNOT CHANGE THEIR ORDER!!!

Save arrays.xml

4. Now, we did all that so we can have it translatable to different locales. So lets do that. We will use Italian language as an example.

5. Navigate to res/values-it/strings.xml and copy the string you created in values/strings.xml to the end of the file.

Change the content of the string to the one in Italian. Like so...

<string name="reboot_title">Menu riavvio avanzato</string>

Note that the name of the string should remain THE SAME as in values/strings.xml

Save the italian strings.xml

6. Now we do the same to values-it/arrays.xml

<string-array name="restart_menu">
<item>Riavviare il dispositivo</item>
<item>Riavvio Rapido</item>
<item>Modalità Recovery</item>
<item>Modalità Download</item>
</string-array>

7. Save all your modified files and compile framework-res.apk

8. We're not done with it yet. Now decompile it and navigate to values/public.xml.

Open it in the text/xml editor and leave it open. We will use it in a little while.

9. Decompile (or backsmali) android.policy.jar

You should already have the 4 way reboot incorporated. (see requirements for the guide!!!)

Navigate to smali/com/android/internal/policy/impl/GlobalActions$99.smali

10. Search ro the following line:

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

Right underneath it you will see the following:

const-string v2, "Reboot Menu"

This initializes the string builder for our dialog. This will send the string "Reboot Menu" to the register v2.

This is the "Hard Coding" that we want to avoid. So we change it. Instead we will send an integer to the register v2.

And that integer will be the public id for the string we created in strings.xml.

So go to your open public.xml file and search for the public id that the compiler created for our new string.

The easiest way to search would be by the name of the string. In this case would be reboot_title

Now what I find is this <public type="string" name="reboot_title" id="0x01040b8a" />

Your number could be different from mine... You use yours...

Copy ONLY the public id (in my case 0x01040b8a) and go back to your GlobalActions$99.smali file

Change

const[COLOR="Blue"][I][B]-string v2, "Reboot Menu"[/B][/I][/COLOR]

To

const [COLOR="Red"]v2, 0x01040b8a[/COLOR]

11. Now that we "fed" the public id to our register, we need to make sure the methos is USING it.

So The next line we change

From

invoke-virtual {v1, v2}, Landroid/app/AlertDialog$Builder;->setTitle([COLOR="Blue"]Ljava/lang/CharSequence;[/COLOR])Landroid/app/AlertDialog$Builder;

To

invoke-virtual {v1, v2}, Landroid/app/AlertDialog$Builder;->setTitle([COLOR="Red"]I[/COLOR])Landroid/app/AlertDialog$Builder;

So basically we said: do not use the char sequence, use the resources and find by ID that we fed into the register.

12. Now we do the same for the items in our reboot options.

Go back to the public.xml and find the public id for the array of strings we created in arrays.xml.

Search by name. I gave it a name restart_menu.

So I find this:

<public type="array" name="restart_menu" id="0x0107005e" />

We copy the public id 0x0107005e (remember - you use YOURS) and we go back to the smali.

13. Find this line and delete it:

sget-object v2, Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;->rebootOptions:[Ljava/lang/String;

Instead we put:

const v2, 0x0107005e

14. Now about 9 lines later you will see this monstrosity:

invoke-virtual {v1, v2, v3, v4}, Landroid/app/AlertDialog$Builder;->setSingleChoiceItems([Ljava/lang/CharSequence;ILandroid/content/DialogInterface$OnClickListener;)Landroid/app/AlertDialog$Builder;

Basically it goes like this:

"We're gonna set the choice items for our reboot dialog.

We're gonna take them from the object called char sequence that we specified earlier

and assign it a function of doing something on click and use a function called Alert dialog builder"

Well, we don't want to use the char sequence. We want to use an integer we wrote into the v2 register.

So we change this:

invoke-virtual {v1, v2, v3, v4}, Landroid/app/AlertDialog$Builder;->setSingleChoiceItems([COLOR="Blue"][Ljava/lang/CharSequence;[/COLOR]ILandroid/content/DialogInterface$OnClickListener;)Landroid/app/AlertDialog$Builder;

To:

invoke-virtual {v1, v2, v3, v4}, Landroid/app/AlertDialog$Builder;->setSingleChoiceItems([COLOR="Red"]I[/COLOR]ILandroid/content/DialogInterface$OnClickListener;)Landroid/app/AlertDialog$Builder;

15. That's it. Save the edited smali and comlpile (or smali) android.policy.jar

MAKE BACKUP!!! Either nandroid or just have your working framework-res.apk and android.policy.jar in a flashable zip on your phone!!!!!!!​

16. Install both your modified framework-res.apk and your modified android.policy.jar into your device.

Flashing in recovery is recommended for framework jars.

If it reboots in the middle of you copying it into the system/framework you're in for alot of pain...

Well not actually pain but it will be either adb push, or rom reflash or backup framework files reflash in recovery.

Well, that's all!!! If you guys find it useful - use it and enjoy!

You can now translate your 4-way reboot to as many locales as you want.

Ask your users for help. Ask people from all around the world to translate those strings for you and put them in their locale in framework-res.

Most importantly - HAVE FUN!

No credit needed, no need to ask for permission to use it.

You can modify and redistribute and include in your rom - whatever!!! It's based on open source. It belongs to everyone!!!

As you can see - no flashable zips or ready made smali files are included. This is a "How-to" guide. Means - DO IT YOURSELF!!!

Cheers!!!