Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,739,915 Members 41,916 Now Online
XDA Developers Android and Mobile Development Forum

[REF] How to add Reboot to power menu (updated 10/21/2010)

Tip us?
 
untermensch
Old
(Last edited by untermensch; 10th February 2011 at 11:15 PM.) Reason: correct "res\values\strings.xml" should be \values\strings.xml ditto for public.xml
#1  
untermensch's Avatar
Senior Member - OP
Thanks Meter 617
Posts: 480
Join Date: Apr 2009
Location: Portland
Default [REF] How to add Reboot to power menu (updated 10/21/2010)

this is the final method that will add reboot,recovery and download options
to the power menu updated 10/21/2010

================================================== ==========
Step 1.

the first thing we need to do is add string and image resources to framwork-res
for this example I am using a stock JI6 ROM your resource id's will be different
if on another ROM

use apk_manager to decompile framework-res

open "values\strings.xml" and add our string resources
Code:
Select Code
<string name="reboot_recovery">Recovery</string>
<string name="reboot_download">Download</string>
<string name="reboot">Reboot</string>
save and close

open "values\public.xml" and assign our strings resource id's

scroll until you get to the end of the "<public type="string"" id list
note the id of the last string, in this example it is "10403c2" sometimes
the id's are out of order so search for "10403c2 + 1" or "10403c3"
if the next id is unused then we can start assigning id's to the strings
we added.
Code:
Select Code
<public type="string" name="reboot_recovery" id="0x010403c3" />
<public type="string" name="reboot_download" id="0x010403c4" />
<public type="string" name="reboot" id="0x010403c5" />
now is a good time to add the image resources so add your icons to
"res\drawable-hdpi"
and assign id's to them the same way we did for the strings
in this example, using the example icons in the zip file I had
Code:
Select Code
<public type="drawable" name="reboot" id="0x010803aa" />
<public type="drawable" name="recovery" id="0x010803ab" />
<public type="drawable" name="download" id="0x010803ac" />
save and close

now framework-res has the resources needed for this mod use
apk_manager to compile.

================================================== ==========
Step 2.

next we need to modify Samsung's shutdown method to accept 3 more options
so decompile framework and open "com\android\internal\app\ShutdownThread.smali "

since we are going to pass an integer to ShutdownThread and then evaluate
that integer when the code runs we have to have a spot for the integer so
add this to line 37
Code:
Select Code
.field public static mReboot:I
then in method run at line 1463 add this code before "invoke-static {}, Landroid/os/Power;->shutdown()V"
Code:
Select Code
sget v1, Lcom/android/internal/app/ShutdownThread;->mReboot:I
	
const/4 v2, 0x1
	
if-eq v1, v2, :reboot
	
const/4 v2, 0x2
	
if-eq v1, v2, :rebootRecovery
	
const/4 v2, 0x3
	
if-eq v1, v2, :rebootDownload
then after this code on about line 1477
Code:
Select Code
.line 531
invoke-static {}, Landroid/os/Power;->shutdown()V

.line 532
return-void
add this code
Code:
Select Code
:reboot
	
const-string v4, "now"
	
invoke-static {v4}, Landroid/os/Power;->reboot(Ljava/lang/String;)V

return-void
	
:rebootRecovery
	
const-string v4, "recovery"
	
invoke-static {v4}, Landroid/os/Power;->reboot(Ljava/lang/String;)V

return-void
	
:rebootDownload
	
const-string v4, "download"
	
invoke-static {v4}, Landroid/os/Power;->reboot(Ljava/lang/String;)V

return-void
save and close

compile framework

================================================== ==========
Step 3.

now we are going to add the extra options to the power menu

decompile android.policy

open "com\android\internal\policy\impl\GlobalActions.sm ali"

the first thing that we need to do is increase the array length by 3
so in method createDialog on line 431 change this
Code:
Select Code
const/4 v0, 0x3

new-array v0, v0, [Lcom/android/internal/policy/impl/GlobalActions$Action;
to this
Code:
Select Code
const/4 v0, 0x6

new-array v0, v0, [Lcom/android/internal/policy/impl/GlobalActions$Action;
now add the new menu items this is where the resource id's that we added
to framework-res com into play so on line 457 after "aput-object v2, v0, v1"
add this code
Code:
Select Code
    const/4 v1, 0x3

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

    const v3, 0x10803aa # reboot icon resource id

    const v4, 0x10403c5 # reboot string resource id 

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

    aput-object v2, v0, v1

    const/4 v1, 0x4

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

    const v3, 0x10803ab # recovery icon resource id

    const v4, 0x10403c3 # recovery string resource id

    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, 0x10803ac # download icon resource id

    const v4, 0x10403c4 # download string resource id

    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
make sure to change the resource id's to match what you added to to framework-res

save and close

next add the code that runs when the menu item is pressed

copy GlobalActions$3.smali and name it GlobalActions$7.smali
open GlobalActions$7 and replace all instances of GlobalActions$3
with GlobalActions$7 then add this code to line 52 before
"invoke-static {v0, v1}, Lcom/android/internal/app/ShutdownThread;->shutdown(Landroid/content/Context;Z)V"
Code:
Select Code
const/4 v2, 0x1
	
sput v2, Lcom/android/internal/app/ShutdownThread;->mReboot:I
save and close

copy GlobalActions$3.smali and name it GlobalActions$8.smali
open GlobalActions$8 and replace all instances of GlobalActions$3
with GlobalActions$8 then add this code to line 52 before
"invoke-static {v0, v1}, Lcom/android/internal/app/ShutdownThread;->shutdown(Landroid/content/Context;Z)V"
Code:
Select Code
const/4 v2, 0x2
	
sput v2, Lcom/android/internal/app/ShutdownThread;->mReboot:I
save and close

copy GlobalActions$3.smali and name it GlobalActions$9.smali
open GlobalActions$9 and replace all instances of GlobalActions$3
with GlobalActions$9 then add this code to line 52 before
"invoke-static {v0, v1}, Lcom/android/internal/app/ShutdownThread;->shutdown(Landroid/content/Context;Z)V"
Code:
Select Code
const/4 v2, 0x3
	
sput v2, Lcom/android/internal/app/ShutdownThread;->mReboot:I
save and close

compile android.policy

done test on the phone.

flash the attached update.zip with the stock updater.
Attached Thumbnails
Click image for larger version

Name:	device.jpg
Views:	18065
Size:	28.0 KB
ID:	424006  
Attached Files
File Type: zip JI6_stock.zip - [Click for QR Code] (6.47 MB, 4424 views)
File Type: zip JI6_deodex.zip - [Click for QR Code] (6.41 MB, 4472 views)
File Type: zip powermenu_final.zip - [Click for QR Code] (22.8 KB, 8500 views)
The Following 68 Users Say Thank You to untermensch For This Useful Post: [ Click to Expand ]
 
BabyBoi.JN
Old
#2  
Member
Thanks Meter 2
Posts: 60
Join Date: Aug 2010
Location: San Diego
Anyway to get this in a flashable zip? I don't know how to decompile files
The Following User Says Thank You to BabyBoi.JN For This Useful Post: [ Click to Expand ]
 
moyofalaye
Old
#3  
Member
Thanks Meter 0
Posts: 90
Join Date: Jul 2006
Location: usa
Quote:
Originally Posted by BabyBoi.JN View Post
Anyway to get this in a flashable zip? I don't know how to decompile files
bump Bump bump please
 
blackerwater
Old
#4  
blackerwater's Avatar
Senior Member
Thanks Meter 52
Posts: 857
Join Date: Apr 2007
Location: Seattle

 
DONATE TO ME
Nice

Sent from my vibrant
-Vibrant-root-exthack-morphed-my own custom rom

-Nexus S Deodexed Memory Hack OG kernel custom.

-Lg Gslate Rooted

-Wifeys G2

and the retarded little cousin of the G2 mytouch slide running CM

Use drop box. Sign up now! Thanks

Sign up using this link and get a bonus:
https://www.dropbox.com/referrals/NTQyNzg2MTc5
 
b0ricuaguerrero
Old
#5  
b0ricuaguerrero's Avatar
Senior Member
Thanks Meter 161
Posts: 484
Join Date: Sep 2007
Location: brooklyn, N.Y

 
DONATE TO ME
Quote:
Originally Posted by BabyBoi.JN View Post
Anyway to get this in a flashable zip? I don't know how to decompile files
I second that. I miss that option
Phone & Statusran - Galaxy S2 Superuser
Rom - ______ Rom
Recovery- CWM
Clock Speed - 1.7ghz
Micro Sd -16gb Class 6
=================
Tablet- Galaxy Tab Super User
Rom - ♫ Overcome gingerbread ♫
Recovery- CWM 3
 
hyao
Old
#6  
Junior Member
Thanks Meter 0
Posts: 18
Join Date: Sep 2010
where is policy file
how to decompile
i use ubuntu
thx

Sent from my SGH-T959 using XDA App
 
adm1jtg
Old
#7  
Senior Member
Thanks Meter 93
Posts: 514
Join Date: Jul 2010
Location: Georgia
sounds like a great add-in if could be made flashable
 
daddysays
Old
#8  
daddysays's Avatar
Senior Member
Thanks Meter 10
Posts: 383
Join Date: Jul 2010
Location: Amesbury, MA
Quote:
Originally Posted by adm1jtg View Post
sounds like a great add-in if could be made flashable
Either that or a how to for dummies version

Sent from Vibrant Frankin Twiz Update3 JI2 modem.bin jac kernel with voodoo lagfix on XDA app with no fc's FINALLY!
SGS 4
 
BabyBoi.JN
Old
#9  
Member
Thanks Meter 2
Posts: 60
Join Date: Aug 2010
Location: San Diego
Quote:
Originally Posted by daddysays View Post
Either that or a how to for dummies version!
EXACTLY!!! That's what I need LOL
 
s0niqu3
Old
#10  
s0niqu3's Avatar
Senior Member
Thanks Meter 388
Posts: 716
Join Date: Feb 2005

 
DONATE TO ME
Quote:
Originally Posted by untermensch View Post
someone asked for this so here it is.

decompile android.policy

make a copy of GlobalActions$3.smali and name it to GlobalActions$7.smali open GlobalActions$7.smali

and replace all instances of GlobalActions$3 with GlobalActions$7

replace method onPress with this

Code:
Select Code
.method public onPress()V
    .registers 3

    const-string v0, "Reboot Now"

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

    return-void
.end method
save and close

now open GlobalActions.smali

and in method createDialog

the first thing that we need to do is increase the array length by 1 so find this
Code:
Select Code
const/4 v0, 0x3

new-array v0, v0, [Lcom/android/internal/policy/impl/GlobalActions$Action;
and change to
Code:
Select Code
const/4 v0, 0x4

new-array v0, v0, [Lcom/android/internal/policy/impl/GlobalActions$Action;
next we add the new menu item so on line 457 we add this next bit of code after "aput-object v2, v0, v1"
Code:
Select Code
const/4 v1, 0x3 # position in the menu array

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

const v3, 0x1080030  # power icon

const v4, 0x10402af  # reboot string

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

aput-object v2, v0, v1
framework-res already has a string for reboot so no modifications are needed to framework-res

save and close then compile android.policy
Hi,

Thanks so much for this, absolutely fantastic work like always!

For anyone that doesn't know how to decompile/compile apk files search for either APK Manager, or smali/baksmali tutorial/help/etc., it should help you out greatly.

And for those that want a flashable .zip, well, here you go, BUT, I'm lazy, so it requires some conditions:

1) You use a rom based on JI6 that's fully deodexed
2) you have previously flashed (or your custom rom included) the epic/puzzle lockscreen mod (also from untermensch)
3) You disable voodoo (if you use it) prior to flashing since this zip attempts to wipe your dalvik-cache


That said, zip should flash fine from clockwork, and all it does is replace your android.policy.jar with one pre-modded for lockscreen & reboot option support, and it wipes your dalvik-cache since that's the safest thing to do after applying any mod, period.

Cheers, =)
Attached Files
File Type: zip JI6_lockscreen_mod_REBOOT_menu_option.zip - [Click for QR Code] (144.8 KB, 1525 views)
~Jocelyn
@jocelyndev
fork me on github
Apparently posting personal signatures outside of this little block is too offensive for some.

The Following 3 Users Say Thank You to s0niqu3 For This Useful Post: [ Click to Expand ]
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes