[Micromax A110] jusma:
How to add Reboot and Reboot recovery to MMX A110 Power Menu

NOTE: PROGRAMMING KNOWLEDGE IS A MUST TO FOLLOW BELOW

Read entire steps once, before deciding whether you want to do this on your own. If you don't understand any of the terms used then GOOGLE or search here on XDA Forums. There is a high probability of 'Reboot Loop' or 'System Crash', so be warned.

Tools Required:

1) ADB to run commands on your phone from computer

2) Latest JAR files from Android SDK or downloaded from internet - APKTool.jar, Baksmali.jar, Smali.jar

3) Notepad++

4) 7zip (DOS or Windows, whichever is convenient)

Some of the actions below can also be done using APK-Multi-Tool and xUltimate

1) Take a CWM Backup of your phone

2) Pull /system/app and /system/framework folders from your phone into your computer

3) DEODEX both the above folders (Note, this will slow down phone until Re-DEXed or at least ZipAligned)

4) Use ADB to copy DEODEXed files back to the original folders

5) Don't forget to delete the .dex files and set 0644 permissions to all the files within

6) Better do 'Fix Permissions' from CWM, just in case, before rebooting

7) Reboot to check if above was done properly. Verify contacts and data of all System Apps

8) Take another CWM backup

9) Decompile /framework/framework-res.apk and /framework/android.policy.jar files using apktool or baksmali

For framework-res.apk

1) From \framework-res.apk\res\values folder...

A) Edit strings.xml file in Notepad++ and add two rows between < resources >< /resources >

I did...

<string name="global_action_reboot">Reboot</string>

<string name="global_action_reboot_recovery">Reboot recovery</string>

B) Edit public.xml file in Notepad++ and add two resource definitions (string) for the above menu. You can reuse, as I, drawable resources or add .png files to all the folders to have your own menu image.

My definitions were...

<public type="string" name="global_action_reboot" id="0x010404db" />

<public type="string" name="global_action_reboot_recovery" id="0x010404dc" />

but you will need to check for an unused id and add one... don't blindly copy-paste

2) Compile framework-res.apk with a different name

3) Open the original framework-res.apk and your newly compiled apk file in 7zip File Manager.

4) Drag and drop resources.arsc from the new apk file window into the original

5) Keep this modified file aside for later update

For android.policy.jar

1) Use baksmali to decompile JAR file

2) Review \android.policy\com\android\internal\policy\impl\GlobalActions.smali file from the decompiled folder

3) The code to add menus to the Power Menu lies with the following method (duh)...

.method private createDialog()Landroid/app/AlertDialog;

Use this webpage to understand what is happening...

http://pallergabor.uw.hu/androidblog/dalvik_opcodes.html

4) For me below is the code where the actual 'Power Off' menu item of the Power Menu is being added...

.line 204

iget-object v0, p0, Lcom/android/internal/policy/impl/GlobalActions;->mItems:Ljava/util/ArrayList;

new-instance v1, Lcom/android/internal/policy/impl/GlobalActions$2;

const v2, 0x1080030

const v3, 0x104012f

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

invoke-virtual {v0, v1}, Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z

5) Note how the resource id for menu text and menu icon is used, and how this class - Lcom/android/internal/policy/impl/GlobalActions$2 is assigned. This determines which sub-file determines behaviour.

6) The number next to GlobalActions$(X).smali [ (X) ] may be different for you. Open it.

7) Notice how the shutdown() method of com/android/internal/app/ShutdownThread class is called within the onPress() method of the above class.

This class resides in the framework.jar file

8) Decompile framework.jar and find the method for Reboot()

9) Once you have understood what really happens in the above method you can simply duplicate the above section of codes two more times... one for 'Reboot' and one for 'Reboot Recover', with the appropriate resource ids and new .smali files for handling the onPress() events of course

10) Hint: You will need to copy-paste the GlobalActions$2.smali as GlobalActions$7.smali & GlobalActions$8.smali (the number depends on sequence of already used numbers in your folder)

11) Call the Reboot() method instead of the shutdown() method with appropriate variable values

12) Hint: The following are reason codes that you need to use...

"now" - Normal Reboot

"recovery" - Reboot into CWM Recovery

"download" - Reboot into Bootloader

13) After all changes, compile using smali and merge the classes.dex file into the original .jar file

Finally...

1) Push your modified .apk and .jar files into the /system/framework folder

2) Set appropriate permissions and reboot

Test to make sure you have understood the above

Q. Answer the question, "do you have to re-compile framework.jar and update to phone /system/framework folder?"