[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:
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.