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

Search This thread

spear1403

Senior Member
Apr 2, 2011
233
242
Virovitica
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 :

screenshot17ul.jpg


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 :

screenshot16n.jpg


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 :

screenshot1wt.jpg


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 :

screenshot6ry.jpg


screenshot5uq.jpg


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 :

screenshot4km.jpg


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 :

screenshot9bw.jpg


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.smali"

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, 0x[COLOR="Red"]4[/COLOR]

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

To this :

Code:
const/4 v0, 0x[COLOR="Red"]5[/COLOR]

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

Screenshot :

screenshot10pd.jpg


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, [COLOR="Red"]0x108045c[/COLOR]

      const v4, [COLOR="Red"]0x10404fc[/COLOR]

      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 :

screenshot11ws.jpg


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 :

screenshot13t.jpg


Save and close

Compile android.policy

Done.

Now you can test it on the phone.
 

Attachments

  • smali_baksmali.7z
    1.6 MB · Views: 1,112
Last edited:

maxiordoqui

Senior Member
Aug 18, 2011
254
50
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

Senior Member
Apr 2, 2011
233
242
Virovitica
Of course it's easier :D,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.:rolleyes:
 
  • Like
Reactions: arunkekkar

oscaredu

Member
Sep 28, 2009
19
0
41
Tristan Suarez
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

Senior Member
Apr 2, 2011
233
242
Virovitica
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

Member
Sep 28, 2009
19
0
41
Tristan Suarez
It works. Check out this link: http://xdaforums.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.
 

spear1403

Senior Member
Apr 2, 2011
233
242
Virovitica
You dont need to decompile the JAR file .Extract the classes.dex file from the Jar and use smali to decompile it and baksmali to recompile it after editing. The automated smali/baksmali only has a decompile and recompile bat file so You dont have to use the command line.Anyways the link for the automated smali/baksmali is down .I'll attach it to the first post.
 
  • Like
Reactions: oscaredu

oscaredu

Member
Sep 28, 2009
19
0
41
Tristan Suarez
You're a genius!
Thank you very much. Then I tell how I was.

Greetings and thanks again.

---------- Post added at 07:36 PM ---------- Previous post was at 06:42 PM ----------

Traductor
I feel like a fool.
But I want to do this and understand it.
Explain to me step by step explained for a fool this:

"3. Next We Need to modify Defy's shutdown method to accept one more option.
Decompile framework and open "com \ android \ internal \ app \ ShutdownThread.smali"

What command should I run for decompiling the "FRAMEWORK.JAR" or should I use "FRAMEWORK.ODEX."

Greetings.
 
Last edited:

spear1403

Senior Member
Apr 2, 2011
233
242
Virovitica
If You have framework,jar and framework.odex that means Your rom isn't deodexed .This tutorial is for a deodexed rom .You have to deodex Your rom .
 

oscaredu

Member
Sep 28, 2009
19
0
41
Tristan Suarez
Thank you again. Please answer each question "dumb" I did
From what I see and tell me, would have to get a rom "deodexed" and flash my phone.
I do not want it is still under warranty.

Greetings.
 

navx2vad

Senior Member
Jul 15, 2008
158
36
i did all the listed steps & got three files, now wen using root explorer i paste them @ thr respective places with correct permissions i get a boot loop error..

appreciate your help.. what I'm doing wrong?
 

spear1403

Senior Member
Apr 2, 2011
233
242
Virovitica
There are dozens of things that can go wrong .Try putting the files one by one so that you see which file is causing the bootloop.
 

navx2vad

Senior Member
Jul 15, 2008
158
36
@spear1403

even putting files one by one.. din't help out! still get a boot loop on every try! phew..
any other way to add restart option to power menu? any zip or so to flash from recovery?
 

navx2vad

Senior Member
Jul 15, 2008
158
36
@spear ... it's 4.5.1-134_DFP-231

using walter79 's deodexed version!
 
Last edited:

Top Liked Posts

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

    screenshot17ul.jpg


    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 :

    screenshot16n.jpg


    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 :

    screenshot1wt.jpg


    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 :

    screenshot6ry.jpg


    screenshot5uq.jpg


    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 :

    screenshot4km.jpg


    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 :

    screenshot9bw.jpg


    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.smali"

    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, 0x[COLOR="Red"]4[/COLOR]
    
          new-array v0, v0, [Lcom/android/internal/policy/impl/GlobalActions$Action;

    To this :

    Code:
    const/4 v0, 0x[COLOR="Red"]5[/COLOR]
    
          new-array v0, v0, [Lcom/android/internal/policy/impl/GlobalActions$Action;

    Screenshot :

    screenshot10pd.jpg


    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, [COLOR="Red"]0x108045c[/COLOR]
    
          const v4, [COLOR="Red"]0x10404fc[/COLOR]
    
          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 :

    screenshot11ws.jpg


    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 :

    screenshot13t.jpg


    Save and close

    Compile android.policy

    Done.

    Now you can test it on the phone.
    2
    @spear ... it's 4.5.1-134_DFP-231

    Here you go. Flash via CWM.
    2
    I notice that you also added 1% battery steps to that nandroid. Could you explain how to do that? I've got a theme which has 1% steps for the battery icon (cooked at the UOT Kitchen), but the phone still only displays 10% steps.

    My phone has GB 2.3.4, build 4.5.1-134_DFP-82 as standard. I'm a bit wary about flashing a whole new build at this early stage but I'd be happy to flash an update just for 1% battery steps.

    Here is a How-To

    http://xdaforums.com/showpost.php?p=13784360&postcount=54
    2
    Can you send me just your file services.jar for compare with my file please? Thanks

    Here you go .From 4.5.1-134_DFP-132 rom
    1
    Of course it's easier :D,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.:rolleyes: