[HOWTO] Extended Power Menu (EPM): adding Recovery & Download

Search This thread

jeboo

Recognized Developer
Apr 2, 2010
815
4,059
2rdhm3t.png


This thread is a continuation of many previous ones, mainly the one by untermensch (http://forum.xda-developers.com/showthread.php?t=811532). I kept the mod going for ICS (http://forum.xda-developers.com/showpost.php?p=24218275&postcount=217), and figured 4.2.2 is deserving of a new thread.

The good news is the framework actually simplified the mod, requiring only two files to be updated. This tutorial is based on UCUAMDL.

1. framework-res.apk (this 1st part is unchanged from previous thread)

a) In strings.xml, add:
Code:
<string name="epm_recovery">Recovery</string>
<string name="epm_download">Download</string>

b) In public.xml, add (NOTE: these resource IDs will change in the future!!):
Code:
<public type="string" name="epm_recovery" id="0x010408e3" />
<public type="string" name="epm_download" id="0x010408e4" />
<public type="drawable" name="ic_lock_recovery" id="0x01080c9d" />
<public type="drawable" name="ic_lock_download" id="0x01080c9e" />

c) Lastly, add your two icons as ic_lock_recovery.png and ic_lock_download.png in drawable-hdpi.

Compile framework-res.apk, upload and reboot phone.
-----------------------------------------------------------------------------------------------
2. android.policy.jar

a) In GlobalActions.smali, add the following variables around line 150:
Code:
.field private mRecovery:Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;

.field private mDownload:Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;

b) Same file, find:

.line 566
new-instance v0, Lcom/android/internal/policy/impl/GlobalActions$5;

const v1, 0x108097f

const v2, 0x1040199

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

iput-object v0, p0, Lcom/android/internal/policy/impl/GlobalActions;->mRestart:Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;

Add this code directly below it (NOTE: this code references the resource IDs above, be sure to correct if they've changed):
Code:
new-instance v0, Lcom/android/internal/policy/impl/GlobalActions$18;

    const v1, [COLOR="Red"]0x1080c9d[/COLOR]

    const v2, [COLOR="red"]0x10408e3[/COLOR]

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

    iput-object v0, p0, Lcom/android/internal/policy/impl/GlobalActions;->mRecovery:Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;

    new-instance v0, Lcom/android/internal/policy/impl/GlobalActions$19;

    const v1, [COLOR="red"]0x1080c9e[/COLOR]

    const v2, [COLOR="red"]0x10408e4[/COLOR]

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

iput-object v0, p0, Lcom/android/internal/policy/impl/GlobalActions;->mDownload:Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;

c) About 10 lines below, you will see:

.line 659
const/4 v0, 0x6

Change it to:
Code:
const/16 v0, 0x8

d) About 20 lines below that, you will see:

const/4 v1, 0x5

iget-object v2, p0, Lcom/android/internal/policy/impl/GlobalActions;->mBugReport:Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;

aput-object v2, v0, v1

Add this code directly after:
Code:
const/4 v1, 0x6

	iget-object v2, p0, Lcom/android/internal/policy/impl/GlobalActions;->mRecovery:Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;

	aput-object v2, v0, v1

    const/4 v1, 0x7

    iget-object v2, p0, Lcom/android/internal/policy/impl/GlobalActions;->mDownload:Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;

aput-object v2, v0, v1

e) All that's left is to add the 2 smalis to handle when the menu items are selected. This is where the code is now simplified, as we don't need to mess with framework.jar anymore. In short, ShutDownThread.smali in framework has a reboot method that supports a parameter. So we simply call it with the appropriate param (either recovery or download).

Still in policy.jar, copy GlobalActions$5.smali as a template for GlobalActions$18.smali, change all the $5 to $18, and then we are going to replace the onPress method with this:
Code:
.method public onPress()V
    .registers 6

    .prologue
	iget-object v1, p0, Lcom/android/internal/policy/impl/GlobalActions[COLOR="Red"]$18[/COLOR];->this$0:Lcom/android/internal/policy/impl/GlobalActions;

    # getter for: Lcom/android/internal/policy/impl/GlobalActions;->mContext:Landroid/content/Context;
    invoke-static {v1}, Lcom/android/internal/policy/impl/GlobalActions;->access$000(Lcom/android/internal/policy/impl/GlobalActions;)Landroid/content/Context;
	
	move-result-object v1
	
	const-string v2, [COLOR="red"]"recovery"[/COLOR]
	
	const/4 v3, [COLOR="red"]0x1[/COLOR]   # CONFIRMATION FLAG
	
	invoke-static {v1, v2, v3}, Lcom/android/server/power/ShutdownThread;->reboot(Landroid/content/Context;Ljava/lang/String;Z)V
	
	return-void
.end method

Repeat this step for GlobalActions$19.smali but change "recovery" to "download", and $18 to $19, in the code fragment above. Also note, you can decide whether you want a confirmation dialog or not by setting v3 to 0x0 (no) or 0x1 (yes).

Compile android.policy.jar, upload and reboot! If all went well, you will see the EPM with your new options :fingers-crossed:

ADDENDUM:
If you're interested in adding Flashlight to the EPM, this is the onPress method:
Code:
.method public onPress()V
    .registers 6

    .prologue
    sget-boolean v0, Lcom/android/internal/policy/impl/GlobalActions$20;->mFlashlight:Z

    if-nez v0, :cond_6

    const/4 v2, 0x1

    goto :goto_7

    :cond_6
    const/4 v2, 0x0

    :goto_7
    sput-boolean v2, Lcom/android/internal/policy/impl/GlobalActions$20;->mFlashlight:Z

    invoke-static {v2}, Lcom/sec/android/hardware/SecHardwareInterface;->setTorchLight(I)V

    return-void
.end method
 
Last edited:

jeboo

Recognized Developer
Apr 2, 2010
815
4,059
I've updated the OP onPress() code to make the phone shut down gracefully (animation, etc). It seems rebootOrShutdown was a bit too low level. You can also decide if you want a confirmation box too. Thanks to shoman for pointing this out :)
 

AxAtAx

Senior Member
Mar 14, 2011
13,117
20,412
ViSiON,Texas
I have use this info 2 or 3 times now, great work, and works perfect...thanks.

---------- Post added at 09:53 AM ---------- Previous post was at 09:51 AM ----------

I rarely post .zips, and it would be unwise in this case. Mismatched resource IDs will lead to crash and/or possible bootloop.

lol, and trust me, this is exactly what happens, it will not boot. been there done that...:D

I wish there was one place with info like this for other mods....you know, like a all in one place...would be cool.
 
Last edited:

jeboo

Recognized Developer
Apr 2, 2010
815
4,059
I'll post the screenshot code later, it was not a trivial patch :p

Sent from my SAMSUNG-SGH-I337 using xda app-developers app
 

xdapowerapps

Senior Member
Jul 16, 2008
639
241
:eek: Gonna try with odex'd and see how things go..

Tapped from the Shear Galaxy Near You!

I posted this in a different thread but this one seems more active.

I am running JB 4.2.2 on a Tmobile Galaxy S4. Here is what I've done thus far:

1) Pulled /system/framework/framework-res.apk

2) Installed framework.

Code:
I: Framework installed to: C:\Users\Syed\apktool\framework\1.apk

3) Decompiled framework-res.apk

Code:
I: Loading resource table...
I: Loaded.
I: Decoding AndroidManifest.xml with resources...
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Done.
I: Copying assets and libs...

4) Added the two drawables in /res/drawable-hdpi

71yPWrK.png


5) Added the two strings in /res/values/strings.xml

Code:
<string name="download">Bootloader</string>
<string name="recovery">Recovery</string>

6) Compiled framework-res.apk

7) Deodexed android.policy.jar with "Universal Deodexer V4"

8) Made my GlobalActions smali changes.

9) Tried to odex android.policy.jar back but got stuck on how to do it. Used Auto Odexer Script by Alkhafaf. If I can get past this part, I'll be able to push both the updated framework-res.apk and the odex'ed android.policy.jar and see the results.

Were you able to succeed with your odex'ed files? Thanks.
 

jeboo

Recognized Developer
Apr 2, 2010
815
4,059
i have tried many guides for EPM and got same result my phone dont pass the first screen ie. Galaxy ace gts5830i
Any solution??

Sent from my GT-S5830i using Tapatalk 2

I'll post a new diff once 4.4 is out..There may be some subtle changes causing problems.
 

Alard_626

Member
Sep 24, 2009
41
6
Hello!
Thank you for your great mod!
I've followed all the instructions and got 2 extra strings in power menu, but there's one issue:
For some reason Recovery id named "Bootloader" and Download is named :Recovery" and also, when i press "Download"("Recovery on the screenshot) phone just reboots as normal, while, when i press "Recovery" ("Bootloader" on the screenshot), phone normally boots to recovery.
So, can anybody help me to correct this?
Thank you!
UPD. Fixed names, but phone still doesnt boot to download mode.
 
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 18
    2rdhm3t.png


    This thread is a continuation of many previous ones, mainly the one by untermensch (http://forum.xda-developers.com/showthread.php?t=811532). I kept the mod going for ICS (http://forum.xda-developers.com/showpost.php?p=24218275&postcount=217), and figured 4.2.2 is deserving of a new thread.

    The good news is the framework actually simplified the mod, requiring only two files to be updated. This tutorial is based on UCUAMDL.

    1. framework-res.apk (this 1st part is unchanged from previous thread)

    a) In strings.xml, add:
    Code:
    <string name="epm_recovery">Recovery</string>
    <string name="epm_download">Download</string>

    b) In public.xml, add (NOTE: these resource IDs will change in the future!!):
    Code:
    <public type="string" name="epm_recovery" id="0x010408e3" />
    <public type="string" name="epm_download" id="0x010408e4" />
    <public type="drawable" name="ic_lock_recovery" id="0x01080c9d" />
    <public type="drawable" name="ic_lock_download" id="0x01080c9e" />

    c) Lastly, add your two icons as ic_lock_recovery.png and ic_lock_download.png in drawable-hdpi.

    Compile framework-res.apk, upload and reboot phone.
    -----------------------------------------------------------------------------------------------
    2. android.policy.jar

    a) In GlobalActions.smali, add the following variables around line 150:
    Code:
    .field private mRecovery:Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;
    
    .field private mDownload:Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;

    b) Same file, find:

    .line 566
    new-instance v0, Lcom/android/internal/policy/impl/GlobalActions$5;

    const v1, 0x108097f

    const v2, 0x1040199

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

    iput-object v0, p0, Lcom/android/internal/policy/impl/GlobalActions;->mRestart:Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;

    Add this code directly below it (NOTE: this code references the resource IDs above, be sure to correct if they've changed):
    Code:
    new-instance v0, Lcom/android/internal/policy/impl/GlobalActions$18;
    
        const v1, [COLOR="Red"]0x1080c9d[/COLOR]
    
        const v2, [COLOR="red"]0x10408e3[/COLOR]
    
        invoke-direct {v0, p0, v1, v2}, Lcom/android/internal/policy/impl/GlobalActions$18;-><init>(Lcom/android/internal/policy/impl/GlobalActions;II)V
    
        iput-object v0, p0, Lcom/android/internal/policy/impl/GlobalActions;->mRecovery:Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;
    
        new-instance v0, Lcom/android/internal/policy/impl/GlobalActions$19;
    
        const v1, [COLOR="red"]0x1080c9e[/COLOR]
    
        const v2, [COLOR="red"]0x10408e4[/COLOR]
    
        invoke-direct {v0, p0, v1, v2}, Lcom/android/internal/policy/impl/GlobalActions$19;-><init>(Lcom/android/internal/policy/impl/GlobalActions;II)V
    
    iput-object v0, p0, Lcom/android/internal/policy/impl/GlobalActions;->mDownload:Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;

    c) About 10 lines below, you will see:

    .line 659
    const/4 v0, 0x6

    Change it to:
    Code:
    const/16 v0, 0x8

    d) About 20 lines below that, you will see:

    const/4 v1, 0x5

    iget-object v2, p0, Lcom/android/internal/policy/impl/GlobalActions;->mBugReport:Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;

    aput-object v2, v0, v1

    Add this code directly after:
    Code:
    const/4 v1, 0x6
    
    	iget-object v2, p0, Lcom/android/internal/policy/impl/GlobalActions;->mRecovery:Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;
    
    	aput-object v2, v0, v1
    
        const/4 v1, 0x7
    
        iget-object v2, p0, Lcom/android/internal/policy/impl/GlobalActions;->mDownload:Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;
    
    aput-object v2, v0, v1

    e) All that's left is to add the 2 smalis to handle when the menu items are selected. This is where the code is now simplified, as we don't need to mess with framework.jar anymore. In short, ShutDownThread.smali in framework has a reboot method that supports a parameter. So we simply call it with the appropriate param (either recovery or download).

    Still in policy.jar, copy GlobalActions$5.smali as a template for GlobalActions$18.smali, change all the $5 to $18, and then we are going to replace the onPress method with this:
    Code:
    .method public onPress()V
        .registers 6
    
        .prologue
    	iget-object v1, p0, Lcom/android/internal/policy/impl/GlobalActions[COLOR="Red"]$18[/COLOR];->this$0:Lcom/android/internal/policy/impl/GlobalActions;
    
        # getter for: Lcom/android/internal/policy/impl/GlobalActions;->mContext:Landroid/content/Context;
        invoke-static {v1}, Lcom/android/internal/policy/impl/GlobalActions;->access$000(Lcom/android/internal/policy/impl/GlobalActions;)Landroid/content/Context;
    	
    	move-result-object v1
    	
    	const-string v2, [COLOR="red"]"recovery"[/COLOR]
    	
    	const/4 v3, [COLOR="red"]0x1[/COLOR]   # CONFIRMATION FLAG
    	
    	invoke-static {v1, v2, v3}, Lcom/android/server/power/ShutdownThread;->reboot(Landroid/content/Context;Ljava/lang/String;Z)V
    	
    	return-void
    .end method

    Repeat this step for GlobalActions$19.smali but change "recovery" to "download", and $18 to $19, in the code fragment above. Also note, you can decide whether you want a confirmation dialog or not by setting v3 to 0x0 (no) or 0x1 (yes).

    Compile android.policy.jar, upload and reboot! If all went well, you will see the EPM with your new options :fingers-crossed:

    ADDENDUM:
    If you're interested in adding Flashlight to the EPM, this is the onPress method:
    Code:
    .method public onPress()V
        .registers 6
    
        .prologue
        sget-boolean v0, Lcom/android/internal/policy/impl/GlobalActions$20;->mFlashlight:Z
    
        if-nez v0, :cond_6
    
        const/4 v2, 0x1
    
        goto :goto_7
    
        :cond_6
        const/4 v2, 0x0
    
        :goto_7
        sput-boolean v2, Lcom/android/internal/policy/impl/GlobalActions$20;->mFlashlight:Z
    
        invoke-static {v2}, Lcom/sec/android/hardware/SecHardwareInterface;->setTorchLight(I)V
    
        return-void
    .end method
    4
    I've posted the changes needed for KK on my git:

    https://github.com/jeboo/ShoStock_KK

    Sent from my SAMSUNG-SGH-I337 using xda app-developers app
    3
    I've updated the OP onPress() code to make the phone shut down gracefully (animation, etc). It seems rebootOrShutdown was a bit too low level. You can also decide if you want a confirmation box too. Thanks to shoman for pointing this out :)
    2
    Good info. Looks like I have some work to do. Question, would these modifications require deodexed rom?

    Tapped from the Shear Galaxy Near You!
    2
    Good info. Looks like I have some work to do. Question, would these modifications require deodexed rom?

    Tapped from the Shear Galaxy Near You!

    I only work with deodexed files.
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone