[MOD][Guide][How to] Translatable 4-way reboot - outsource hard code to resources

Search This thread

daxgirl

Senior Member
Jun 30, 2012
4,047
9,169
Jerusalem
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...

Code:
<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...
Code:
        <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...
Code:
<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
Code:
        <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
Code:
const[COLOR="Blue"][I][B]-string v2, "Reboot Menu"[/B][/I][/COLOR]

To
Code:
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
Code:
invoke-virtual {v1, v2}, Landroid/app/AlertDialog$Builder;->setTitle([COLOR="Blue"]Ljava/lang/CharSequence;[/COLOR])Landroid/app/AlertDialog$Builder;

To
Code:
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:
Code:
sget-object v2, Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;->rebootOptions:[Ljava/lang/String;

Instead we put:
Code:
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:
Code:
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:
Code:
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!!!
 

Attachments

  • english_reboot.png
    english_reboot.png
    222.1 KB · Views: 3,940
  • italian_reboot.png
    italian_reboot.png
    225.1 KB · Views: 3,884
Last edited:

DaOldMan

Senior Member
  • Oct 6, 2010
    3,320
    5,616
    You are the best. All 4-way mods should be made this way :). Clean, non hard coded, the way android is supposed to be ! Loved your mod since you did it on our beloved S2. Thanks for an excellent guide.

    Thomas
     
    • Like
    Reactions: daxgirl

    daxgirl

    Senior Member
    Jun 30, 2012
    4,047
    9,169
    Jerusalem
    You are the best. All 4-way mods should be made this way :). Clean, non hard coded, the way android is supposed to be ! Loved your mod since you did it on our beloved S2. Thanks for an excellent guide.

    Thomas
    A student can only be as good as their mentor! Thank YOU! For everything! ???

    Inviato dal mio SM-G900F utilizzando Tapatalk
     
    • Like
    Reactions: DaOldMan

    Top Liked Posts

    • There are no posts matching your filters.
    • 33
      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...

      Code:
      <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...
      Code:
              <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...
      Code:
      <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
      Code:
              <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
      Code:
      const[COLOR="Blue"][I][B]-string v2, "Reboot Menu"[/B][/I][/COLOR]

      To
      Code:
      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
      Code:
      invoke-virtual {v1, v2}, Landroid/app/AlertDialog$Builder;->setTitle([COLOR="Blue"]Ljava/lang/CharSequence;[/COLOR])Landroid/app/AlertDialog$Builder;

      To
      Code:
      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:
      Code:
      sget-object v2, Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;->rebootOptions:[Ljava/lang/String;

      Instead we put:
      Code:
      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:
      Code:
      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:
      Code:
      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!!!
      5
      Hi @daxgirl ,
      thanks for your very useful guide!

      I've noticed some changes for S5 G900F Marshmallow.. I've followed this perfect guide by @Kamy for andvenced reboot menu.

      So advanced reboot menu is now in services.jar and not in android.policy.jar

      So for MM we need services.jar and not android.policy.jar .

      Obviously the GlobalActions$99.smali is now in smali/com/android/server/policy .

      And this old string:
      Code:
      sget-object v2, Lcom/android/[COLOR=red]internal[/COLOR]/policy/impl/GlobalActions$SinglePressAction;->reboot[COLOR=red]Options[/COLOR]:[Ljava/lang/String;

      Now is:
      Code:
      sget-object v2, Lcom/android/[COLOR=blue]server[/COLOR]/policy/GlobalActions$SinglePressAction;->reboot[COLOR=blue]String[/COLOR]:[Ljava/lang/String;
      (now there is NOT "/impl/" between policy and Global...)

      Anything else.

      Thank you again.
      I hope this info can help you and everyone :)
      d828adc6f586a36c005fdbaa8070c013.jpg
      4
      set style in Power menu 4way reboot

      Step1
      decompile framework-res.apk
      open >>
      values / public.xml

      search (this is ID style white ) >> <public type = "style" name = "Theme.DeviceDefault.Light"
      search (this is ID style black) >> <public type = "style" name = "Theme.DeviceDefault"

      mine are these but your could be different
      <public type="style" name="Theme.DeviceDefault.Light" id="0x0103012b" />
      <public type="style" name="Theme.DeviceDefault" id="0x01030128" />

      ---------------------------------------------------------

      Step 2
      decompile androidpolicy.jar
      com\android\ internal\policy\ impl
      open GlobalActions.smali
      search

      Landroid / view / ContextThemeWrapper;

      ID changes with the value found in the framework in Theme.DeviceDefault >> 0x01030128

      attention, the number may be different in Smali
      check the previous format
      if he has nine numbers have to remove the zero after
      0x
      and then change in 0x1030128


      Code:
      [COLOR="Red"]example:[/COLOR]
      new-instance v3, Landroid / view / ContextThemeWrapper;
      
           const v6, 0x103012b
      3
      In samsung Grand.. i cant find GlobalActions$99.smali

      Did you make the basic 4 way reboot mod first? Probably not and that's why you miss those smali files.

      Sent from my SM-N9005 using Tapatalk
      3
      Wubyyyy ? you have to eat fish is good for your memory☺☺☺☺☺
    Our Apps
    Get our official app!
    The best way to access XDA on your phone
    Nav Gestures
    Add swipe gestures to any Android
    One Handed Mode
    Eases uses one hand with your phone