• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!
  • Fill out your device list and let everyone know which phones you have!    Edit Your Device Inventory

[HOW TO] Extended Power Menu with no header (reboot / download / recovery)

Search This thread

sicopat

Senior Member
Oct 21, 2007
810
956
Samsung Galaxy S20
[HOW TO] Extended Power Menu (reboot / download / recovery) with no header


This HOW TO is rewritten from a French tutorial (HERE) itself rewritten from a XDA tutorial (HERE, and modified using this other one : HERE

Thanks to :
Okarin
untermensch
PaoloM70



warnings :
- This tutorial is for people who know what they will do, a mistake can fit your phone unusable so ...
- A modification of system files is always a delicate operation, pay attention and do not rush


Prerequisites :

First and foremost, you must master the decompilation / recompilation of APK and JAR using APK_Manager and smali/baksmali.


Mod the power menu :

Here is the way to add the options "Reboot", "Recovery" and "Download" to the Power menu (long press the power button)

For this part, we will work on 2 files:
framework res.apk
android.policy.jar
You can decompile the first with APK Manager, and the second with baksmali.


1/ framework-res.apk :

Extract it with APK_Manager (extracted in /project folder)

a/ Then, before going any further, you will have to find three new .PNG images to be displayed in the power menu, and name them :
"ic_lock_reboot.png" for reboot menu
"ic_lock_recovery.png" to enter recovery
"ic_lock_download.png" for download Mode

Place these 3 images in the : APK_Manager/project/framework-res.apk/res/drawable-hdpi
where you will find the other pictures already in the menu concerned.
It is easier for beginners to add customised icons (like for power off, silent or plane modes icons )after recompilation, using 7zip for example. .

b/ With NotePad + +, edit the file " res/values/strings.xml "
Go to the end of the file, and add before the last line "</resources>", the three lines:
Code:
    <string name="reboot_recovery">Recovery</string>
    <string name="reboot_download">Download</string>
    <string name="reboot">Reboot</string>

This should give you something like this:

captur24.png


c/ Save your file.

d/ Now you can recompile the file "framework-res.apk" with APK Manager.
Remember that this is an APK system and delete the "keep/resources.arsc", since we have modified an XML file.
You will have a your moded apk here : "place-apk-here-for-modding/unsignedframework-res.apk"

Warning: You should not have errors when you re-compil. don't forget to add 3 new icons;

e/ using APK-Manager, decompil "place-apk-here-for-modding/unsignedframework-res.apk".
*Go to res/values/public.xml and edit with Notepad ++
*public.xml is auto-generated from others modifications during APK_MANAGER re-compilation. 6 new lines have been added, with 6 new Hex numbers. You will need these numbers later ...
Look for :
Code:
    <public type="string" name="reboot" id="[B]0x01040488[/B]" />
    <public type="string" name="reboot_recovery" id="[B]0x01040489[/B]" />
    <public type="string" name="reboot_download" id="[B]0x0104048a[/B]" />
and for :
Code:
    <public type="drawable" name="ic_lock_reboot" id="[B]0x010803d2[/B]" />
    <public type="drawable" name="ic_lock_recovery" id="[B]0x010803d3[/B]" />
    <public type="drawable" name="ic_lock_download" id="[B]0x010803d4[/B]" />

f/ Now you just have to rename "place-apk-here-for-modding/unsignedframework-res.apk" to "framework-res.apk" and voila!

Edit : never sign a system File using APK_Manager.

Here is the first part ended.
A tip, try this file on your phone, if it restarts fine, then the mod is correct, otherwise you can start over ;)
It is important to test step by step, because it lets you know exactly from witch file comes the error.


2/ Now, we attack the second file "android.policy.jar".

Once decompiled with baksmal, edit the "out/com/android/internal/policy/impl/GlobalActions.smali."
Caution: Do not confuse it with the file "GlobalActions$Action.Smali"

a/ Find the line ".method private createDialog()Landroid/app/AlertDialog;"
then a few lines below, replace "const/4 v9, 0x4" with "const/4 v9, 0x7".
This line indicates the number of menu entries of extinction, we move from 4 to 7 (3 mor entries). You should have this after the changes made:

captur35.png


b/ Then find the line "
Code:
invoke-static {v0}, Lcom/google/android/collect/Lists;->newArrayList([Ljava/lang/Object;)Ljava/util/ArrayList;
" and insert just above:

Code:
    const/4 v1, 0x4

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

    const v3, 0x10803d2

    const v4, 0x1040488

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

    aput-object v2, v0, v1

    const/4 v1, 0x5

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

    const v3, 0x10803d3

    const v4, 0x1040489

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

    aput-object v2, v0, v1

    const/4 v1, 0x6

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

    const v3, 0x10803d4

    const v4, 0x104048a

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

    aput-object v2, v0, v1


You will notice in the code, the previous hex numbers generated. You have to modify the hex numbers quoted with the hex numbers you found in step 2 after decompilation of unsignedframework-res.apk

Warning in this code, the hex numbers have a 0 in less after the "0x" like : 0x1234567... and not 0x011234567 like in string.xml[/COLOR]...
Please not in the code you just added the GlobalActions$8, GlobalActions$9, GlobalActions$10 : you will add files .smali with same name later. If in your firmware GlobalActions$8 is already existing, then modify the "$X" to follow last used number

To help, here's what you should have:

captur40.png



3/ If you want to remove the header of the extended power menu, not having to scroll,

a/ search for ".method private prepareDialog()",
then look a few lines below, you should find "const v4, 0x104014a"
where This hexadecimal digit corresponds to the entry "<public type="string"name="global_actions" id="0x0104014a" /> in the "public.xml" file, which itself refers to the text of the menu in" string.xml " :

captur42.png



b/ find the corresponding hexadecimal number 0xXXXXX to the entry "<string name="config_tether_apndata" />" in the "string.xml" file. This entry has no text.
Now replace in "const v4, 0x104014a" with "const v4, 0xXXXXX," so it will not show anything in the power menu.

Save the file.

c/ Come on, we're almost there ...

Now copy the "out/com/android/internal/policy/impl/GlobalActions$4.Smali" to "out/com/android/internal/policy/impl/GlobalActions$8.Smali".
We choose #4 because it is one that contains the shutdown of the phone. We will rename it 8 because it's 8 in the next free issue ...
Remember this if ever in a future version of the files they are change.

d/ Now open the new file "out/com/android/internal/policy/impl/GlobalActions$8.Smali" and replace in, all occurrences of "\GlobalActions$4" with "\GlobalActions$8"

Then, Replace :
Code:
    const/4 v1, 0x1

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

With :
Code:
    const/4 v1, 0x1
	
    const-string v2, "now"
	
    invoke-static {v0, v2, v1}, Lcom/android/internal/app/ShutdownThread;->reboot(Landroid/content/Context;Ljava/lang/String;Z)V


e/ Save the file and copy it to "out/com/android/internal/policy/impl/GlobalActions$9.Smali"
Open it and replace in, all occurrences of "\GlobalActions$8" with "\GlobalActions$9
and
const-string v2, "now" with const-string v2, "recovery"

f/ Save the file and copy it to "out/com/android/internal/policy/impl/GlobalActions$10.Smali"
Open it and replace in, all occurrences of "\GlobalActions$9" with "\GlobalActions$10
and
const-string v2, "recovery" with const-string v2, "download"

Save the file and then ... compile it all!

The result, you will see that I also forgot to replace an icon:

sc20110722211413.png
 
Last edited:
S

sileshnair

Guest
Excellent. Now for a tutorial on how to get the mobile data toggle in the notification bar and we can all build custom roms.

Sent from my GT-I9100 using Tapatalk
 

D.O.C

Inactive Recognized Developer / Retired Senior Mod
Jun 24, 2006
3,141
4,002
42
Wow, u really went the whole 9 yards explaining this, thanks, as always grateful for ur sharing....
 

NitroOnTheRocks

Senior Member
Jun 19, 2008
142
31
Seems like you put a lot of time and effort in this post.
Very good and clear instructions on something I wanted to add to my custom rom for a long time. (without just adding some files)
Thank you very much.
 
Last edited:

_JKay_

Retired Recognized Developer
Aug 12, 2010
5,495
14,689
Nice guide. Two things when using apkmanager:

1) Never ever edit the public.xml
2) When Recompiling: Never sign system files. Copy their signature!

Sent from my GT-I9100 using XDA Premium App
 

Ghostbustersin

Senior Member
Dec 31, 2010
76
24
Nice guide. Two things when using apkmanager:

1) Never ever edit the public.xml
2) When Recompiling: Never sign system files. Copy their signature!

Sent from my GT-I9100 using XDA Premium App

If we don't edit Public.xml, how are going to achieve this? I keep getting errors while recompiling using apkmanager? They sometimes don't even extract the resources.arsc and throw a lot of errors.
I'm working on adding a few options in the settings apk and neither apkmanger nor apktool is letting me decompile settings apk. It always throws errors. I need to decompile to edit a few xml in values which i don't find if i unzip it with 7-zip or winrar! Editing smali files is not a prob for now!
Any solutions?
 

Ghostbustersin

Senior Member
Dec 31, 2010
76
24
@ sicopat
All three options call the Shutdown thread and present the "Your phone will shutdown" dialog. How do we change this?
And i also want to add the subtext in all three options in the main options, where are those located?
 

_JKay_

Retired Recognized Developer
Aug 12, 2010
5,495
14,689
If we don't edit Public.xml, how are going to achieve this? I keep getting errors while recompiling using apkmanager? They sometimes don't even extract the resources.arsc and throw a lot of errors.
I'm working on adding a few options in the settings apk and neither apkmanger nor apktool is letting me decompile settings apk. It always throws errors. I need to decompile to edit a few xml in values which i don't find if i unzip it with 7-zip or winrar! Editing smali files is not a prob for now!
Any solutions?

public.xml is auto-generated! Try add a string or a png and compile then decompile again. You will see that the new resources has been added to the public.xml

The ids MUST be unique and increased by one! Its all done in the apktool!
 

sicopat

Senior Member
Oct 21, 2007
810
956
Samsung Galaxy S20
No credit for the how to you copied this from?

what a shame

http://forum.xda-developers.com/showthread.php?t=811532

You are totaly right.
I didn't find lines to modify,
I just built a new How To, from a french one I found here : http://www.galaxys-team.fr/viewtopic.php?f=6&t=14562

I believe this french How To took its inspiration from this thread : http://forum.xda-developers.com/showthread.php?t=811532
I didn't found this thread myself, you found it for me.

I finished to write this thread at 1h30 AM and I am going just now correct this mistake ...
Sorry for this
 
Last edited:
  • Like
Reactions: designgears

sicopat

Senior Member
Oct 21, 2007
810
956
Samsung Galaxy S20
public.xml is auto-generated! Try add a string or a png and compile then decompile again. You will see that the new resources has been added to the public.xml

The ids MUST be unique and increased by one! Its all done in the apktool!

Ok but i never had errors using this How To and so, modifing public.xml.
But I will add your recommandation for people to try this How To, without modifing public.xml.
Thanks
 

sicopat

Senior Member
Oct 21, 2007
810
956
Samsung Galaxy S20
Why this statement? I'd rather say ONLY edit PNGs when decompiled!

Cause when using Apk manager, during re-compilation a keep folder is created and if you don't delete every files (and png) you modified in this keep folder, then after recompilation you will have olds .png from the keep folder and not your new png from your project folder.

It is easier to just push your new .png after recompilation.
I am just a noob who want to help a little with my short experience.
I am ready to learn and to optimise my how to :)

Sent from my GT-I9100 using XDA Premium App
 

_JKay_

Retired Recognized Developer
Aug 12, 2010
5,495
14,689
Cause when using Apk manager, during re-compilation a keep folder is created and if you don't delete every files (and png) you modified in this keep folder, then after recompilation you will have olds .png from the keep folder and not your new png from your project folder.

It is easier to just push your new .png after recompilation.
I am just a noob who want to help a little with my short experience.
I am ready to learn and to optimise my how to :)

Sent from my GT-I9100 using XDA Premium App

Its true you need to delete the files you modify from the keep folder. But you should never try and modify 9patch pngs if they are not decompiled!!
 

sicopat

Senior Member
Oct 21, 2007
810
956
Samsung Galaxy S20
Its true you need to delete the files you modify from the keep folder. But you should never try and modify 9patch pngs if they are not decompiled!!

Yes i agree with you.
But in this How to, you don't need to edit 9patch.png

For begginers i think it's easier to push the customised reboot, power off, download mode icons ... after recompilation.

Sent from my GT-I9100 using XDA Premium App
 

_JKay_

Retired Recognized Developer
Aug 12, 2010
5,495
14,689
Yes i agree with you.
But in this How to, you don't need to edit 9patch.png

For begginers i think it's easier to push the customised reboot, power off, download mode icons ... after recompilation.

Sent from my GT-I9100 using XDA Premium App

Ok...... But I think this could make beginners believe that this is always the case and how it should always be done. I rather teach them the right way :)
 

Top Liked Posts

  • There are no posts matching your filters.
  • 111
    [HOW TO] Extended Power Menu (reboot / download / recovery) with no header


    This HOW TO is rewritten from a French tutorial (HERE) itself rewritten from a XDA tutorial (HERE, and modified using this other one : HERE

    Thanks to :
    Okarin
    untermensch
    PaoloM70



    warnings :
    - This tutorial is for people who know what they will do, a mistake can fit your phone unusable so ...
    - A modification of system files is always a delicate operation, pay attention and do not rush


    Prerequisites :

    First and foremost, you must master the decompilation / recompilation of APK and JAR using APK_Manager and smali/baksmali.


    Mod the power menu :

    Here is the way to add the options "Reboot", "Recovery" and "Download" to the Power menu (long press the power button)

    For this part, we will work on 2 files:
    framework res.apk
    android.policy.jar
    You can decompile the first with APK Manager, and the second with baksmali.


    1/ framework-res.apk :

    Extract it with APK_Manager (extracted in /project folder)

    a/ Then, before going any further, you will have to find three new .PNG images to be displayed in the power menu, and name them :
    "ic_lock_reboot.png" for reboot menu
    "ic_lock_recovery.png" to enter recovery
    "ic_lock_download.png" for download Mode

    Place these 3 images in the : APK_Manager/project/framework-res.apk/res/drawable-hdpi
    where you will find the other pictures already in the menu concerned.
    It is easier for beginners to add customised icons (like for power off, silent or plane modes icons )after recompilation, using 7zip for example. .

    b/ With NotePad + +, edit the file " res/values/strings.xml "
    Go to the end of the file, and add before the last line "</resources>", the three lines:
    Code:
        <string name="reboot_recovery">Recovery</string>
        <string name="reboot_download">Download</string>
        <string name="reboot">Reboot</string>

    This should give you something like this:

    captur24.png


    c/ Save your file.

    d/ Now you can recompile the file "framework-res.apk" with APK Manager.
    Remember that this is an APK system and delete the "keep/resources.arsc", since we have modified an XML file.
    You will have a your moded apk here : "place-apk-here-for-modding/unsignedframework-res.apk"

    Warning: You should not have errors when you re-compil. don't forget to add 3 new icons;

    e/ using APK-Manager, decompil "place-apk-here-for-modding/unsignedframework-res.apk".
    *Go to res/values/public.xml and edit with Notepad ++
    *public.xml is auto-generated from others modifications during APK_MANAGER re-compilation. 6 new lines have been added, with 6 new Hex numbers. You will need these numbers later ...
    Look for :
    Code:
        <public type="string" name="reboot" id="[B]0x01040488[/B]" />
        <public type="string" name="reboot_recovery" id="[B]0x01040489[/B]" />
        <public type="string" name="reboot_download" id="[B]0x0104048a[/B]" />
    and for :
    Code:
        <public type="drawable" name="ic_lock_reboot" id="[B]0x010803d2[/B]" />
        <public type="drawable" name="ic_lock_recovery" id="[B]0x010803d3[/B]" />
        <public type="drawable" name="ic_lock_download" id="[B]0x010803d4[/B]" />

    f/ Now you just have to rename "place-apk-here-for-modding/unsignedframework-res.apk" to "framework-res.apk" and voila!

    Edit : never sign a system File using APK_Manager.

    Here is the first part ended.
    A tip, try this file on your phone, if it restarts fine, then the mod is correct, otherwise you can start over ;)
    It is important to test step by step, because it lets you know exactly from witch file comes the error.


    2/ Now, we attack the second file "android.policy.jar".

    Once decompiled with baksmal, edit the "out/com/android/internal/policy/impl/GlobalActions.smali."
    Caution: Do not confuse it with the file "GlobalActions$Action.Smali"

    a/ Find the line ".method private createDialog()Landroid/app/AlertDialog;"
    then a few lines below, replace "const/4 v9, 0x4" with "const/4 v9, 0x7".
    This line indicates the number of menu entries of extinction, we move from 4 to 7 (3 mor entries). You should have this after the changes made:

    captur35.png


    b/ Then find the line "
    Code:
    invoke-static {v0}, Lcom/google/android/collect/Lists;->newArrayList([Ljava/lang/Object;)Ljava/util/ArrayList;
    " and insert just above:

    Code:
        const/4 v1, 0x4
    
        new-instance v2, Lcom/android/internal/policy/impl/GlobalActions$8;
    
        const v3, 0x10803d2
    
        const v4, 0x1040488
    
        invoke-direct {v2, p0, v3, v4}, Lcom/android/internal/policy/impl/GlobalActions$8;-><init>(Lcom/android/internal/policy/impl/GlobalActions;II)V
    
        aput-object v2, v0, v1
    
        const/4 v1, 0x5
    
        new-instance v2, Lcom/android/internal/policy/impl/GlobalActions$9;
    
        const v3, 0x10803d3
    
        const v4, 0x1040489
    
        invoke-direct {v2, p0, v3, v4}, Lcom/android/internal/policy/impl/GlobalActions$9;-><init>(Lcom/android/internal/policy/impl/GlobalActions;II)V
    
        aput-object v2, v0, v1
    
        const/4 v1, 0x6
    
        new-instance v2, Lcom/android/internal/policy/impl/GlobalActions$10;
    
        const v3, 0x10803d4
    
        const v4, 0x104048a
    
        invoke-direct {v2, p0, v3, v4}, Lcom/android/internal/policy/impl/GlobalActions$10;-><init>(Lcom/android/internal/policy/impl/GlobalActions;II)V
    
        aput-object v2, v0, v1


    You will notice in the code, the previous hex numbers generated. You have to modify the hex numbers quoted with the hex numbers you found in step 2 after decompilation of unsignedframework-res.apk

    Warning in this code, the hex numbers have a 0 in less after the "0x" like : 0x1234567... and not 0x011234567 like in string.xml[/COLOR]...
    Please not in the code you just added the GlobalActions$8, GlobalActions$9, GlobalActions$10 : you will add files .smali with same name later. If in your firmware GlobalActions$8 is already existing, then modify the "$X" to follow last used number

    To help, here's what you should have:

    captur40.png



    3/ If you want to remove the header of the extended power menu, not having to scroll,

    a/ search for ".method private prepareDialog()",
    then look a few lines below, you should find "const v4, 0x104014a"
    where This hexadecimal digit corresponds to the entry "<public type="string"name="global_actions" id="0x0104014a" /> in the "public.xml" file, which itself refers to the text of the menu in" string.xml " :

    captur42.png



    b/ find the corresponding hexadecimal number 0xXXXXX to the entry "<string name="config_tether_apndata" />" in the "string.xml" file. This entry has no text.
    Now replace in "const v4, 0x104014a" with "const v4, 0xXXXXX," so it will not show anything in the power menu.

    Save the file.

    c/ Come on, we're almost there ...

    Now copy the "out/com/android/internal/policy/impl/GlobalActions$4.Smali" to "out/com/android/internal/policy/impl/GlobalActions$8.Smali".
    We choose #4 because it is one that contains the shutdown of the phone. We will rename it 8 because it's 8 in the next free issue ...
    Remember this if ever in a future version of the files they are change.

    d/ Now open the new file "out/com/android/internal/policy/impl/GlobalActions$8.Smali" and replace in, all occurrences of "\GlobalActions$4" with "\GlobalActions$8"

    Then, Replace :
    Code:
        const/4 v1, 0x1
    
        invoke-static {v0, v1}, Lcom/android/internal/app/ShutdownThread;->shutdown(Landroid/content/Context;Z)V

    With :
    Code:
        const/4 v1, 0x1
    	
        const-string v2, "now"
    	
        invoke-static {v0, v2, v1}, Lcom/android/internal/app/ShutdownThread;->reboot(Landroid/content/Context;Ljava/lang/String;Z)V


    e/ Save the file and copy it to "out/com/android/internal/policy/impl/GlobalActions$9.Smali"
    Open it and replace in, all occurrences of "\GlobalActions$8" with "\GlobalActions$9
    and
    const-string v2, "now" with const-string v2, "recovery"

    f/ Save the file and copy it to "out/com/android/internal/policy/impl/GlobalActions$10.Smali"
    Open it and replace in, all occurrences of "\GlobalActions$9" with "\GlobalActions$10
    and
    const-string v2, "recovery" with const-string v2, "download"

    Save the file and then ... compile it all!

    The result, you will see that I also forgot to replace an icon:

    sc20110722211413.png
    2
    Works on ics and jb

    Sent from my GT-I9100 using Tapatalk 2
    2
    yeah, i'll try that ..

    Did you already find it?

    If not:
    The opcodes are not the problem here. They've just changed some of the methods behind this ;)

    v9 isn't used anymore for this. It's v0 now (-> ICS_4.0.1_r1-Beta2-i9000.zip)

    So what you are searching for can be found at line 432

    Have fun... :D

    Code:
    Line     Code
    ________________
    
    427      invoke-direct/range {v0 .. v6}, Lcom/android/internal/policy/impl/GlobalActions$2;-><init>(Lcom/android/internal/policy/impl/GlobalActions;IIIII)V
    428
    429      iput-object v0, p0, Lcom/android/internal/policy/impl/GlobalActions;->mAirplaneModeOn:Lcom/android/internal/policy/impl/GlobalActions$ToggleAction;
    430
    431      .line 190
    432      const/4 v0, 0x3
    433
    434      new-array v0, v0, [Lcom/android/internal/policy/impl/GlobalActions$Action;
    1
    great tutorial.

    thanx, we all need help sometimes :D
    1
    No credit for the how to you copied this from?

    what a shame

    http://forum.xda-developers.com/showthread.php?t=811532