# [Solved] Help requested adding Recovery/Download options to power menu



## Zerg The Bear (Aug 18, 2011)

***Solved - Look at post #4 for solution***

Hello. I'm trying to learn how to modify ROMs. Right now I am trying to add Recovery and Download options to the stock/deodexed FP1 that nitroglycerine posted:
http://eclipserom.co...loated-Versions

I found these instructions for the Galaxy S II, and under the hopes that the Charge would be set up in a similar fashion, was using them as a template (maybe not the best idea):
http://forum.xda-dev...d.php?t=1169443

I believe I have completed the first part of this tutorial without any issue. In addition to the image/string edits, I turned on the CRT off animation and added an accurate battery to show I was using the updated file. Both of those are working perfectly, and I haven't had any FCs, so I'm thinking this file is okay.

My problem seems to be with the edits I made to android.policy.jar. I will preface this part by stating this is the first time I have ever tried dealing with smali.

I extracted classes.dex with WinRAR and then used baksmali to get to the specific smali files mentioned in the thread. When I went to edit the first item in GlobalActions.smali, "const/4 v9 0x4", I only changed it to 0x6, as we already have a reboot option in the menu. I then added the references to the strings and images, updated the code provided with the correct IDs from public.xml and I also referenced GlobalActions$11 and $12 (as $1-$10 were already there). I created files for GlobalActions$11 and $12 from GlobalActions$4, updated them to reference their number, and replaced "GlobalActions restart" with "recovery" and "download". I didn't just copy the code from the tutorial thread.

Once done editing the files, I re-compiled with smali (both with and without the -Xmx512M option), re-opened the original android.policy.jar, then added the new classes.dex to the archive. Whenever I push this new file to my phone, everything starts fine, but when I long press the power button, the phone vibrates but the menu doesn't appear. This actually causes a restart of the launcher (both TW and GO Launcher EX). As soon as I push the original file back to the phone, everything returns to normal. Here is the error I get from logcat (full logcat available upon request):

```
<br />
[ 04-03 23:25:10.928  1916:0x79a E/AndroidRuntime ]<br />
*** FATAL EXCEPTION IN SYSTEM PROCESS: WindowManagerPolicy<br />
java.lang.ArrayIndexOutOfBoundsException<br />
at com.android.internal.policy.impl.GlobalActions.createDialog(GlobalActions.java:224)<br />
at com.android.internal.policy.impl.GlobalActions.showDialog(GlobalActions.java:113)<br />
at com.android.internal.policy.impl.PhoneWindowManager.showGlobalActionsDialog(PhoneWindowManager.java:585)<br />
at com.android.internal.policy.impl.PhoneWindowManager$2.run(PhoneWindowManager.java:572)<br />
at android.os.Handler.handleCallback(Handler.java:587)<br />
at android.os.Handler.dispatchMessage(Handler.java:92)<br />
at android.os.Looper.loop(Looper.java:130)<br />
at com.android.server.WindowManagerService$PolicyThread.run(WindowManagerService.java:624)<br />
```
Does anybody have any tips on what I might be doing wrong? Thanks in advance for your help.

Finally, I'm going to apologize for not having a GIT repository going. I realized as I was writing this that it would have been nice for anyone trying to help me out. I will work on getting it set up in case I need more help in the future.


----------



## imnuts (Jun 9, 2011)

Without seeing the smali files that you edited, I can't help to much, but, your problem will be in globalactions.smali somewhere just after a line labeled ".line 224". I would be willing to guess that the issue is related to creating the array and numbering the options in the list.


----------



## Zerg The Bear (Aug 18, 2011)

imnuts said:


> Without seeing the smali files that you edited, I can't help to much, but, your problem will be in globalactions.smali somewhere just after a line labeled ".line 224". I would be willing to guess that the issue is related to creating the array and numbering the options in the list.


Thanks a lot for the help. I had been looking at line 224 (which didn't make sense when I looked at it) as opposed to .line 224. One of the sources for the how-to thread is from the Vibrant, and that had slightly different instructions, including adjusting the array made at .line 224.

Now my phone shows the power menu again, but it still doesn't have the Recovery or Download options in it. The thread for the Vibrant also mentions editing framework.jar, so I'll be trying that next to see if it helps (since our phone is more like the Vibrant than the GSII.

Just for reference, here is my modified GlobalActions.smali:
http://dl.dropbox.co...tions_new.smali

...and the stock file:
http://dl.dropbox.co...ons_stock.smali


----------



## Zerg The Bear (Aug 18, 2011)

Okay, I think I have it figured out now. What I did might have been overkill, but all functions (including the original 4) are working as expected. I ended up doing things from both sets of instructions (GSII and Vibrant).

As mentioned above (per the Vibrant instructions), at .line 224, I changed

```
const/4 v0, 0x5
```
 to

```
const/4 v0, 0x7
```
and added my recovery and download entries in that section just before the line

```
invoke-static {v0}, Lcom/google/android/collect/Lists;->newArrayList([Ljava/lang/Object;)Ljava/util/ArrayList;
```
Also, I did what the GSII instructions mentioned and under

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

```
const/4 v9, 0x4
```
 to

```
const/4 v9, 0x6
```
 as well as added my new entries in the section below .line 268, and again before the line

```
invoke-static {v0}, Lcom/google/android/collect/Lists;->newArrayList([Ljava/lang/Object;)Ljava/util/ArrayList;<br />
```


----------



## RWNube (Sep 30, 2011)

Do you guys think it would be possible to add some long press options to the long-press power button if one uses the dialer code mod that disables the lockscreen?
Currently I used the dialer codes and my phone shuts off if I long-press the power button.


----------



## scarygood536 (Aug 11, 2011)

I think a screenshot button would be sweet







.. I was going to mess around and see if I could add it, but given my lack of knowledge due to my a.d.d in java class I'll have to wait. Where are these buttons even located in the rom? I didn't see them in the apps or framework apk


----------



## mthous01 (Dec 22, 2011)

Zerg The Bear said:


> Okay, I think I have it figured out now. What I did might have been overkill, but all functions (including the original 4) are working as expected. I ended up doing things from both sets of instructions (GSII and Vibrant).
> 
> As mentioned above (per the Vibrant instructions), at .line 224, I changed
> 
> ...


Any chance you might share what you've accomplished with the Android noobs of the world? I'm not sure I could figure out how to do this short of copying files into folders myself. I am using the same rom you are, as Tweaked and Eclipse are killing my phone speed.


----------



## mthous01 (Dec 22, 2011)

OK, I'm working my way thru this, but after extracting the framework, I cannot find the strings.xml file to edit to insert the lines for the menu. Any help here?


----------



## imnuts (Jun 9, 2011)

you have to decompile framework-res.apk to get the strings.xml file


----------



## cowsquad (Dec 19, 2011)

Great I'm gonna try this out

Sent from my Galaxy Nexus using Tapatalk 2


----------



## Zerg The Bear (Aug 18, 2011)

mthous01 said:


> Any chance you might share what you've accomplished with the Android noobs of the world? I'm not sure I could figure out how to do this short of copying files into folders myself. I am using the same rom you are, as Tweaked and Eclipse are killing my phone speed.


The link in the first post takes you to a pretty good tutorial of the whole process. Keep in mind that you don't have to add a Reboot option as we have it already. It tells you where to put the images and strings in framework-res.apk. Since I am not publishing these changes, I took the download and recovery icons from another ROM (can't remember which one).

Make sure you recompile and decompile after you add everything to framework-res.apk so that public.xml gets updated with addresses for the new items you added (2 strings and 2 images). Then decompile android-policy.jar (I used baksmali/smali, but APK Multitool seemed to work also). You will need to add two GlobalActions$xx.smali files as mentioned in the other thread and modify the GlobalActions.smali as noted above.

Upon reading this again, I'm not sure all of the additions to GlobalActions.smali listed above were necessary. I think I only needed to add what the GSII thread mentioned (the second set of additions in my "solution"). I have not tried to edit mine yet to test this theory, just wanted to let you know in case you don't want to add possibly unnecessary code.


----------

