Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

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

OP spear1403

22nd December 2011, 09:06 PM   |  #1  
spear1403's Avatar
OP Senior Member
Thanks Meter: 241
 
229 posts
Join Date:Joined: Apr 2011
More
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:
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:
<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:
.field public static mReboot:I
Screenshot :



Then at line 545 add this code before "invoke-static {}, Landroid/os/Power;->shutdown()V"

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:
: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:
const/4 v0, 0x4

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

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:
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:
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, 886 views)
Last edited by spear1403; 28th December 2011 at 05:21 PM.
The Following 24 Users Say Thank You to spear1403 For This Useful Post: [ View ]
23rd December 2011, 09:28 AM   |  #2  
diamond_lover's Avatar
Senior Member
Top Secret
Thanks Meter: 113
 
1,533 posts
Join Date:Joined: Apr 2009
Zomg XD not so fast Thanks dude ^_^
24th December 2011, 09:08 PM   |  #3  
Senior Member
Thanks Meter: 50
 
238 posts
Join Date:Joined: Aug 2011
More
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 .. !
25th December 2011, 09:18 AM   |  #4  
spear1403's Avatar
OP Senior Member
Thanks Meter: 241
 
229 posts
Join Date:Joined: Apr 2011
More
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
Last edited by spear1403; 28th December 2011 at 05:21 PM.
26th December 2011, 02:41 PM   |  #5  
Senior Member
Thanks Meter: 50
 
238 posts
Join Date:Joined: Aug 2011
More
Thanks you very much!!
26th December 2011, 03:22 PM   |  #6  
Senior Member
Thanks Meter: 103
 
594 posts
Join Date:Joined: Feb 2006
More
Why not simply flash the nandroid that already has it built in? :S Saves a lot of time and hassle.
26th December 2011, 04:07 PM   |  #7  
spear1403's Avatar
OP Senior Member
Thanks Meter: 241
 
229 posts
Join Date:Joined: Apr 2011
More
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: [ View ]
27th December 2011, 10:09 PM   |  #8  
Junior Member
Thanks Meter: 0
 
9 posts
Join Date:Joined: 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
28th December 2011, 03:16 PM   |  #9  
spear1403's Avatar
OP Senior Member
Thanks Meter: 241
 
229 posts
Join Date:Joined: Apr 2011
More
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.
28th December 2011, 03:45 PM   |  #10  
Junior Member
Thanks Meter: 0
 
9 posts
Join Date:Joined: 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.

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes