Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,736,958 Members 52,337 Now Online
XDA Developers Android and Mobile Development Forum

[HOW TO][Gingerbread] Adding Reboot option to Power Menu

Tip us?
 
spear1403
Old
(Last edited by spear1403; 28th December 2011 at 04:21 PM.)
#1  
spear1403's Avatar
Senior Member - OP
Thanks Meter 238
Posts: 228
Join Date: Apr 2011
Exclamation [HOW TO][Gingerbread] Adding Reboot option to Power Menu

Here is a tutorial with screenshots on how to add the reboot option to the power menu for the Defy.

This is not my work .It is a rewrite of this thread modified for use on the Defy .

For this operation you will need :

1. APK Manager

2. smali/baksmali or use the one attached .

3. Notepad++

In this tutorial we are going to modify these files :framework-res.apk,frmework.jar ,android.policy.jar .
You require knowledge of decompiling/recompiling apk and jar files ,and some basic text editing (.xml and .smali)

For this example I'm using the 4.5.1-134-DFP-132 rom ,but this should work on any Gingerbread rom ???

Ok,let's start.

1. We need to add this line to your build.prop file or the whole thing will not work :

Code:
Select Code
ro.mot.deep.sleep.supported=true
Screenshot :



2. Next we need to add the resources to framework-res.apk .Decompile the framework-res.apk file.
In the project folder open "framework-res.apk\res\values\strings.xml" and add your string resources .

Code:
Select Code
<string name="reboot">Reboot</string>
Screenshot :



save and close

Now open "framework-res.apk\res\drawable-hdpi" and add an image that will be shown next to the reboot string in the power menu .
Name the image "ic_lock_reboot.png".

Screenshot :



Recompile the framework-res.apk .This will create an unsignedframework-res.apk file in the "place-apk-here-for-modding" folder.
Decompile the unsignedframework-res.apk file and open "unsignedframework-res.apk\res\values\public.xml"
Find your image and string id's and write them down .

Screenshot :





3. Next we need to modify Defy's shutdown method to accept 1 more option .
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 25

Code:
Select Code
.field public static mReboot:I
Screenshot :



Then at line 545 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
Then after this code on about line 555

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

.line 512
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
Screenshot :



Save and close

Compile framework

4. Now we are going to add the extra options to the power menu

Decompile android.policy

Open "com\android\internal\policy\impl\GlobalActions.sma li"

The first thing that we need to do is increase the array length by 1 so in method createDialog on line 628 change this :

Code:
Select Code
const/4 v0, 0x4

      new-array v0, v0, [Lcom/android/internal/policy/impl/GlobalActions$Action;
To this :

Code:
Select Code
const/4 v0, 0x5

      new-array v0, v0, [Lcom/android/internal/policy/impl/GlobalActions$Action;
Screenshot :



Now add the new menu items this is where the resource id's that we added to framework-res.apk com into play.
So on line 658 after "aput-object v1, v0, v12" add this code :

Code:
Select Code
const/4 v1, 0x4

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

      const v3, 0x108045c

      const v4, 0x10404fc

      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
Screenshot :



Make sure to change the resource id's to match what you added to to framework-res.apk .

Save and close .

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

Copy GlobalActions$5.smali and name it GlobalActions$10.smali open GlobalActions$10 and replace all instances of GlobalActions$5
with GlobalActions$10 then add this code to line 54 before
"invoke-static {v0, v1}, Lcom/android/internal/app/ShutdownThread;->shutdown(Landroid/content/Context;Z)V"

Code:
Select Code
const/4 p0, 0x1

      sput p0, Lcom/android/internal/app/ShutdownThread;->mReboot:I
Screenshot :



Save and close

Compile android.policy

Done.

Now you can test it on the phone.
Attached Files
File Type: 7z smali_baksmali.7z - [Click for QR Code] (1.63 MB, 784 views)
The Following 23 Users Say Thank You to spear1403 For This Useful Post: [ Click to Expand ]
 
diamond_lover
Old
#2  
diamond_lover's Avatar
Senior Member
Thanks Meter 107
Posts: 1,496
Join Date: Apr 2009
Location: Top Secret
Zomg XD not so fast Thanks dude ^_^
 
maxiordoqui
Old
#3  
Senior Member
Thanks Meter 50
Posts: 237
Join Date: Aug 2011
Hi, would you explain to me what should i have to start modifyng this? I used notepad+ to edit values and others... but it is not enough, i don't know development, but i'd like to know how to proceed and with wich tool should i do those changes. Thanks

---------- Post added at 09:08 PM ---------- Previous post was at 09:07 PM ----------

sorry for bothering .. !
 
spear1403
Old
(Last edited by spear1403; 28th December 2011 at 04:21 PM.)
#4  
spear1403's Avatar
Senior Member - OP
Thanks Meter 238
Posts: 228
Join Date: Apr 2011
The tools are listed above ,but here again with download locations :

1. APK Manager

2. smali/baksmali

3. Notepad++

This is what I use .Hope it helps .

Edit: edited first post
 
maxiordoqui
Old
#5  
Senior Member
Thanks Meter 50
Posts: 237
Join Date: Aug 2011
Thanks you very much!!
 
AgentSmith
Old
#6  
Senior Member
Thanks Meter 92
Posts: 542
Join Date: Feb 2006
Why not simply flash the nandroid that already has it built in? :S Saves a lot of time and hassle.
 
spear1403
Old
#7  
spear1403's Avatar
Senior Member - OP
Thanks Meter 238
Posts: 228
Join Date: Apr 2011
Of course it's easier ,but some of us here like to know how it is done .
Furthermore it's not just for this specific rom .I belive it can be applied to all gingerbread roms (didn't try it on all ,maybe the line numbers and resources don't match ,but the principle is the same ).

Guess the title is a bit confusing .Changing it.
The Following User Says Thank You to spear1403 For This Useful Post: [ Click to Expand ]
 
oscaredu
Old
#8  
Junior Member
Thanks Meter 0
Posts: 9
Join Date: Sep 2009
Hello spear1403.
I would like to add this option to defy my stock rom 2.2.
It may do? I have it root.
If you pass me the necessary files you would do?.
Thank you very much. Greetings from Argentina.

PD: Sorry for my bad english. :$

Oscar
 
spear1403
Old
#9  
spear1403's Avatar
Senior Member - OP
Thanks Meter 238
Posts: 228
Join Date: Apr 2011
I don't know if it works on Froyo roms ,but You can try it out .Be sure to make backups of your original files ,so if something goes wrong You can go back.
 
oscaredu
Old
#10  
Junior Member
Thanks Meter 0
Posts: 9
Join Date: Sep 2009
It works. Check out this link: http://forum.xda-developers.com/showthread.php?t=812341
But I'm half noob on these issues. Your tutorial is very well explained.
But there are things I do not know how we do.
For example:
As decompile and compile JAR files.
Or at what point using "Automated Smali"

PS: Could you upload the "Automated Smalian BakSmali" to any fileserver.

I appreciate your time and help.

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes